Example #1
0
func GetLogger() *logpkg.Logger {
	if log != nil {
		return log
	}
	format := logpkg.MustStringFormatter(
		"%{time:15:04:05} [%{color}%{level:.4s}%{color:reset}] %{shortfile} %{color}▶%{color:reset} %{message}")
	backend := logpkg.NewLogBackend(os.Stdout, "", 2)
	backend1Leveled := logpkg.AddModuleLevel(backend)
	backend1Leveled.SetLevel(logpkg.DEBUG, "")
	backendFormatter := logpkg.NewBackendFormatter(backend, format)

	err_format := logpkg.MustStringFormatter("%{time:15:04:05} [%{level:.4s}] %{shortfile} : %{message}")
	err_writer, err := getLogFile("err")
	if err != nil {
		fmt.Println("get log file err, ", err)
	}
	err_backend := logpkg.NewLogBackend(err_writer, "", 0)
	// err_backend1Leveled := logpkg.AddModuleLevel(err_backend)
	// err_backend1Leveled.SetLevel(logpkg.ERROR, "")

	_ = err_format
	err_backendFormatter := logpkg.NewBackendFormatter(err_backend, err_format)

	logpkg.SetBackend(backendFormatter, err_backendFormatter)
	// logpkg.SetBackend(err_backendFormatter)

	log = logpkg.MustGetLogger("/")

	return log
}
Example #2
0
func init() {
	backend1 := logpkg.NewLogBackend(os.Stderr, "", 0)
	backend2 := logpkg.NewLogBackend(os.Stderr, "", 0)

	backend2Formatter := logpkg.NewBackendFormatter(backend2, format)

	backend1Leveled := logpkg.AddModuleLevel(backend1)
	backend1Leveled.SetLevel(logpkg.ERROR, "")

	logpkg.SetBackend(backend1Leveled, backend2Formatter)
}
Example #3
0
func main() {
	// For demo purposes, create two backend for os.Stderr.
	backend1 := logging.NewLogBackend(os.Stderr, "", 0)
	backend2 := logging.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)

	// Only errors and more severe messages should be sent to backend1
	backend1Leveled := logging.AddModuleLevel(backend1)
	backend1Leveled.SetLevel(logging.ERROR, "")

	// Set the backends to be used.
	logging.SetBackend(backend1Leveled, backend2Formatter)

	log.Debugf("debug %s", Password("secret"))
	log.Info("info")
	log.Notice("notice")
	log.Warning("warning")
	log.Error("err")
	log.Critical("crit")
}