Documentation
¶
Overview ¶
Package log implements logging package with runtime support for enabling and disabling log levels.
Example (Basic) ¶
package main
import (
"fmt"
"ngrd.no/log"
)
func main() {
logger, err := log.New(log.WithDisabledTimestamp())
if err != nil {
fmt.Printf("Error: %v\n", err)
}
logger.Infof("Hello")
logger.Warnf("This is a warning")
logger.Debugf("This is not logged by default")
}
Output: ngrd.no/log_test INFO Hello ngrd.no/log_test WARN This is a warning
Index ¶
- Constants
- Variables
- func LevelStringToType(level string) control.Level
- type Logger
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Fatal(args ...interface{})
- func (l *Logger) Fatalf(format string, args ...interface{})
- func (l *Logger) Fatalln(args ...interface{})
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) Log(level control.Level, msg string)
- func (l *Logger) Print(args ...interface{})
- func (l *Logger) Printf(format string, args ...interface{})
- func (l *Logger) Println(args ...interface{})
- func (l *Logger) Warnf(format string, args ...interface{})
- type Option
Examples ¶
Constants ¶
View Source
const ( FATAL control.Level = iota + 1 ERROR WARNING INFO DEBUG UNKNOWN = -1 )
Variables ¶
View Source
var ( ApplicationName string GlobalOptions []Option )
Functions ¶
func LevelStringToType ¶
Types ¶
type Option ¶
type Option func(l *Logger)
Option sets option when a new logger is created
func WithComponentName ¶
WithComponentName overrides the default component name for a Logger instance
func WithDisabledTimestamp ¶
func WithDisabledTimestamp() Option
WithDisabledTimestamp removes the timestamp from the log message
func WithLogControl ¶
func WithLogControl(c *control.LogControl) Option
WithLogControl overrides the default LogControl instance used
func WithTimeLayout ¶
WithTimeFormat sets how the logger should represent the time pf a log message using (t time.Time) Format(layout string).
func WithTimeUnixNano ¶
func WithTimeUnixNano() Option
WithTimeUnixNano represents the time of a log message as nanoseconds since unix epoch.
func WithWriter ¶
WithWriter sets a specific writer as the log message sink
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
logctl
command
|
|
|
Package control implements necessary functionality for runtime level toggling.
|
Package control implements necessary functionality for runtime level toggling. |
|
mmap
Package mmap implements functionality for keeping a files data in memory.
|
Package mmap implements functionality for keeping a files data in memory. |
Click to show internal directories.
Click to hide internal directories.