示例#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
}
示例#2
0
package logging

import (
	logpkg "github.com/ckeyer/go-log"
	"os"
)

var (
	log    = logpkg.MustGetLogger("example")
	format = logpkg.MustStringFormatter(
		"%{time:15:04:05} [%{color}%{level:.4s}%{color:reset}] %{shortfile} %{color}▶%{color:reset} %{message}")
)

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)
}

func GetLogger() *logpkg.Logger {
	return log
}
示例#3
0
文件: example.go 项目: ckeyer/goblog
package main

import (
	"os"

	logging "github.com/ckeyer/go-log"
)

var log = logging.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(
	`%{color}%{time:15:04:05.000} %{shortfunc} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`,
)

// Password is just an example type implementing the Redactor interface. Any
// time this is logged, the Redacted() function will be called.
type Password string

func (p Password) Redacted() interface{} {
	return logging.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)

	// For messages written to backend2 we want to add some additional