Documentation ¶
Index ¶
- Constants
- func AddOutput(writers ...io.Writer)
- func BuildDefaultLogger(actions ...func(logConfiguration *LogConfiguration))
- func Child(name string) *golog.Logger
- func CreateEncoderConfig(configuration *LogConfiguration) (config zapcore.EncoderConfig)
- func Debug(v ...interface{})
- func Debugf(format string, args ...interface{})
- func Error(v ...interface{})
- func Errorf(format string, args ...interface{})
- func Fatal(v ...interface{})
- func Fatalf(format string, args ...interface{})
- func Handle(handler golog.Handler)
- func Hijack(hijacker func(ctx *pio.Ctx))
- func Info(v ...interface{})
- func Infof(format string, args ...interface{})
- func Install(logger golog.ExternalLogger)
- func InstallStd(logger golog.StdLogger)
- func Logf(level golog.Level, format string, args ...interface{})
- func NewLine(newLineChar string)
- func NewLog(configuration *LogConfiguration, sinkOpts ...func()) *zap.Logger
- func Print(v ...interface{})
- func Println(v ...interface{})
- func RegistWriterSink(name string, sinks ...ILoggerSink) error
- func Reset()
- func Scan(r io.Reader) (cancel func())
- func SetLevel(levelName string)
- func SetOutput(w io.Writer)
- func SetPrefix(s string) *golog.Logger
- func SetTimeFormat(s string)
- func Warn(v ...interface{})
- func Warnf(format string, args ...interface{})
- func WithField(fields ...zap.Field)
- func WithSinks(name string, sinks ...ILoggerSink)
- type ILoggerSink
- type LogConfiguration
Constants ¶
const ( DebugLevel = "debug" InfoLevel = "info" WarnLevel = "warn" ErrorLevel = "error" FatalLevel = "fatal" Disable = "disable" )
Available level names are: "disable" "fatal" "error" "warn" "info" "debug"
const ( SinkName_Console = "console" SinkName_File = "file" )
Variables ¶
This section is empty.
Functions ¶
func AddOutput ¶
AddOutput adds one or more `io.Writer` to the golog.Logger's Printer.
If one of the "writers" is not a terminal-based (i.e File) then colors will be disabled for all outputs.
func BuildDefaultLogger ¶
func BuildDefaultLogger(actions ...func(logConfiguration *LogConfiguration))
构建默认的logger
func Child ¶
Child (creates if not exists and) returns a new child Logger based on the default package-level logger instance.
Can be used to separate logs by category.
func CreateEncoderConfig ¶
func CreateEncoderConfig(configuration *LogConfiguration) (config zapcore.EncoderConfig)
func Debugf ¶
func Debugf(format string, args ...interface{})
Debugf will print when logger's Level is debug.
func Error ¶
func Error(v ...interface{})
Error will print only when logger's Level is error, warn, info or debug.
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf will print only when logger's Level is error, warn, info or debug.
func Fatal ¶
func Fatal(v ...interface{})
Fatal `os.Exit(1)` exit no matter the level of the logger. If the logger's level is fatal, error, warn, info or debug then it will print the log message too.
func Fatalf ¶
func Fatalf(format string, args ...interface{})
Fatalf will `os.Exit(1)` no matter the level of the logger. If the logger's level is fatal, error, warn, info or debug then it will print the log message too.
func Handle ¶
Handle adds a log handler to the default logger.
Handlers can be used to intercept the message between a log value and the actual print operation, it's called when one of the print functions called. If it's return value is true then it means that the specific handler handled the log by itself therefore no need to proceed with the default behavior of printing the log to the specified logger's output.
It stops on the handler which returns true firstly. The `Log` value holds the level of the print operation as well.
func Hijack ¶
Hijack adds a hijacker to the low-level logger's Printer. If you need to implement such as a low-level hijacker manually, then you have to make use of the pio library.
func Infof ¶
func Infof(format string, args ...interface{})
Infof will print when logger's Level is info or debug.
func Install ¶
func Install(logger golog.ExternalLogger)
Install receives an external logger and automatically adapts its print functions.
Install adds a golog handler to support third-party integrations, it can be used only once per `golog#Logger` instance.
For example, if you want to print using a logrus logger you can do the following: `golog.Install(logrus.StandardLogger())`
Look `golog#Handle` for more.
func InstallStd ¶
InstallStd receives a standard logger and automatically adapts its print functions.
Install adds a golog handler to support third-party integrations, it can be used only once per `golog#Logger` instance.
Example Code:
import "log" myLogger := log.New(os.Stdout, "", 0) InstallStd(myLogger)
Look `golog#Handle` for more.
func Logf ¶
Logf prints a leveled log message to the output. This method can be used to use custom log levels if needed. It adds a new line in the end.
func NewLine ¶
func NewLine(newLineChar string)
NewLine can override the default package-level line breaker, "\n". It should be called (in-sync) before the print or leveled functions.
See `github.com/kataras/pio#NewLine` and `Logger#NewLine` too.
func Println ¶
func Println(v ...interface{})
Println prints a log message without levels and colors. It adds a new line at the end.
func RegistWriterSink ¶
func RegistWriterSink(name string, sinks ...ILoggerSink) error
注册一个日志sink name: sink的名称 level:sink处理的level
func Scan ¶
Scan scans everything from "r" and prints its new contents to the logger's Printer's Output, forever or until the returning "cancel" is fired, once.
func SetLevel ¶
func SetLevel(levelName string)
SetLevel alternatively you can use the exported `golog.Level` field, i.e `golog.Level = golog.ErrorLevel`
func SetPrefix ¶
SetPrefix sets a prefix for the default package-level Logger.
The prefix is the first space-separated word that is being presented to the output. It's written even before the log level text.
Returns itself.
func SetTimeFormat ¶
func SetTimeFormat(s string)
SetTimeFormat sets time format for logs, if "s" is empty then time representation will be off.
func Warnf ¶
func Warnf(format string, args ...interface{})
Warnf will print when logger's Level is warn, info or debug.
func WithSinks ¶
func WithSinks(name string, sinks ...ILoggerSink)
Types ¶
type ILoggerSink ¶
日志写入sink
func NewLoggerSink ¶
func NewLoggerSink(createFunc func() zapcore.Core) ILoggerSink
创建一个新的ILoggerSink实例
type LogConfiguration ¶
type LogConfiguration struct { //日志级别 Level string `mapstructure:"level" json:"level" yaml:"level"` // 日志前缀 Prefix string `mapstructure:"prefix" json:"prefix" yaml:"prefix"` // 格式,json,console Format string `mapstructure:"format" json:"format" yaml:"format"` // 输出在的文件夹 Directory string `mapstructure:"directory" json:"directory" yaml:"directory"` // 编码级 EncodeLevel string `mapstructure:"encode-level" json:"encode-level" yaml:"encode-level"` // 栈名 StacktraceKey string `mapstructure:"stacktrace-key" json:"stacktrace-key" yaml:"stacktrace-key"` // 日志留存时间, 天 MaxAge int64 `mapstructure:"max-age" json:"max-age" yaml:"max-age"` // 单个文件大小,单位为 bytes MaxSize int64 `mapstructure:"max-size" json:"max-size" yaml:"max-size"` // 是否显示行号 ShowLine bool `mapstructure:"show-line" json:"show-line" yaml:"show-line"` //是否输出到控制台 ToConsole bool `mapstructure:"to-console" json:"to-console" yaml:"to-console"` }
var ( DefaultLogConfiguration *LogConfiguration = &LogConfiguration{} Logger *zap.Logger )
日志配置