You've already forked go_logger
Changing up the flow of the logging system, starting to move the tests
into their own directory for organization.
This commit is contained in:
@@ -2,14 +2,16 @@ package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"mimirtech.net/gitea/GoUtilities/logger"
|
||||
)
|
||||
|
||||
var log = logging.MustGetLogger("example")
|
||||
var log = logger.MustGetLogger("example")
|
||||
|
||||
// Example format string. Everything except the message has a custom color
|
||||
// which is dependent on the log level. Many fields have a custom output
|
||||
// formatting too, eg. the time returns the hour down to the milli second.
|
||||
var format = logging.MustStringFormatter(
|
||||
var format = logger.MustStringFormatter(
|
||||
`%{color}%{time:15:04:05.000} %{shortfunc} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`,
|
||||
)
|
||||
|
||||
@@ -18,25 +20,25 @@ var format = logging.MustStringFormatter(
|
||||
type Password string
|
||||
|
||||
func (p Password) Redacted() interface{} {
|
||||
return logging.Redact(string(p))
|
||||
return logger.Redact(string(p))
|
||||
}
|
||||
|
||||
func main() {
|
||||
// For demo purposes, create two backend for os.Stderr.
|
||||
backend1 := logging.NewLogBackend(os.Stderr, "", 0)
|
||||
backend2 := logging.NewLogBackend(os.Stderr, "", 0)
|
||||
backend1 := logger.NewLogBackend(os.Stderr, "", 0)
|
||||
backend2 := logger.NewLogBackend(os.Stderr, "", 0)
|
||||
|
||||
// For messages written to backend2 we want to add some additional
|
||||
// information to the output, including the used log level and the name of
|
||||
// the function.
|
||||
backend2Formatter := logging.NewBackendFormatter(backend2, format)
|
||||
backend2Formatter := logger.NewBackendFormatter(backend2, format)
|
||||
|
||||
// Only errors and more severe messages should be sent to backend1
|
||||
backend1Leveled := logging.AddModuleLevel(backend1)
|
||||
backend1Leveled.SetLevel(logging.ERROR, "")
|
||||
backend1Leveled := logger.AddModuleLevel(backend1)
|
||||
backend1Leveled.SetLevel(logger.ERROR, "")
|
||||
|
||||
// Set the backends to be used.
|
||||
logging.SetBackend(backend1Leveled, backend2Formatter)
|
||||
logger.SetBackend(backend1Leveled, backend2Formatter)
|
||||
|
||||
log.Debugf("debug %s", Password("secret"))
|
||||
log.Info("info")
|
||||
|
||||
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Reference in New Issue
Block a user