-
Notifications
You must be signed in to change notification settings - Fork 10
2x Simplest logging
ccpaging edited this page Nov 14, 2019
·
2 revisions
nxlog4go is very simple to use without any configuring, setting. For example:
package main
import (
"time"
log "github.com/ccpaging/nxlog4go"
)
func main() {
log.Fine("This should be omitted as default.")
log.Debug("The time is now: %s", time.Now().Format("15:04:05 MST 2006/01/02"))
log.Info("The time is now: %s", time.Now().Format("15:04:05 MST 2006/01/02"))
log.Warn("The time is now: %s", time.Now().Format("15:04:05 MST 2006/01/02"))
log.Critical("The time is now: %s", time.Now().Format("15:04:05 MST 2006/01/02"))
}
import (
logger "github.com/ccpaging/nxlog4go"
}
- Standard logging
logger.Debug(format, args...)
logger.Info(format, args...)
logger.Warn(format, args...)
logger.Error(format, args...)
...
- With key, value...
logger.With(key, value...).Debug(format, args...)
logger.With(key, value...).Info(format, args...)
logger.With(key, value...).Warn(format, args...)
logger.With(key, value...).Error(format, args...)
...
- Compatible go std lib
logger.Print(v ...interface{})
logger.Println(v ...interface{})
logger.Printf(format string, v ...interface{})
...
- Creating
log := logger.NewLogger(key, value...)
- Getting package standard logger
log := logger.StdLogger()
- Setting
log.SetOutput(w io.Writer)
log.SetPrefix(prefix string)
log.SetLayout(layout Layout)
log.Set(key, val...)
log.SetOptions(key, val) error
- Setting filter level
log.Set("level", logger.INFO)
log.Debug("This should be not omitted now.")
The logging message which level is lower than INFO will be ignored.
- Creating and using Entry
std := logger.StdLogger()
elog := logger.NewEntry(std)
elog.Prefix = "prefix"
elog.Source = "foo"
- Entry logging
elog.Debug(message, key, value...)
elog.Info(message, key, value...)
elog.Warn(message, key, value...)
elog.Error(message, key, value...)
...
See also: