Documentation ¶
Overview ¶
Package logs 日志.
多级日志,文件滚动,不同级别日志可以分别使用不同文件。
Example ¶
package main import ( "os" "github.com/xuender/kit/logs" ) func main() { // logs.SetLogFile("/var/tmp", "test.log") logs.SetLog(os.Stdout) logs.SetLevel(logs.Info) logs.I.SetFlags(0) logs.T.Println("trace") logs.D.Printf("debug: %d", 1) logs.I.Println("info") }
Output: [I] info
Index ¶
- Variables
- func Close() error
- func CloseFile(file *os.File) error
- func Expired(path, name string, reserved int) error
- func File(path, name string) (io.Writer, error)
- func GetLevelName() string
- func Log(values ...any)
- func Rotating(path, file string, yield func(string, string) error) func()
- func SetDebug(writer io.Writer)
- func SetDebugFile(path, file string) error
- func SetError(writer io.Writer)
- func SetErrorFile(path, file string) error
- func SetInfo(writer io.Writer)
- func SetInfoFile(path, file string) error
- func SetLevel(level Level)
- func SetLog(writer io.Writer)
- func SetLogFile(path, file string) error
- func SetTrace(writer io.Writer)
- func SetTraceFile(path, file string) error
- func SetWarn(writer io.Writer)
- func SetWarnFile(path, file string) error
- type Level
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // T 跟踪. T = _loggers[Trace].newLog("[T] ") // D 调试. D = _loggers[Debug].newLog("[D] ") // I 消息. I = _loggers[Info].newLog("[I] ") // W 警告. W = _loggers[Warn].newLog("[W] ") // E 错误. E = _loggers[Error].newLog("[E] ") // RetentionDays 日志保留天数,0为永久. RetentionDays = base.Seven )
nolint: gochecknoglobals, varnamelen
Functions ¶
func File ¶ added in v1.0.3
File 生成软连接文件.
Example ¶
package main import ( "github.com/samber/lo" "github.com/xuender/kit/logs" ) func main() { writer := lo.Must1(logs.File("/tmp/log", "link.log")) defer logs.Close() lo.Must1(writer.Write([]byte("xxx"))) }
Output:
func Log ¶ added in v1.0.3
func Log(values ...any)
Log 输出日志.
Example ¶
package main import ( "os" "github.com/xuender/kit/logs" ) func main() { logs.SetLog(os.Stdout) logs.I.SetFlags(0) logs.E.SetFlags(0) logs.Log(nil) logs.Log(1) logs.Log(2, os.ErrClosed) }
Output: [I] 1 [E] 2 file already closed
Types ¶
Click to show internal directories.
Click to hide internal directories.