Pull to refresh

gookit/slog — release v0.5.2, Lightweight, configurable, extensible logging library

Level of difficultyMedium

gookit/slog ? Lightweight, configurable, extensible logging library written in Go.
Support multi level, multi outputs and built-in multi file logger, buffers, clean, rotate-file handling.

Github https://github.com/gookit/slog

v0.5.2 changelog

Full changeloghttps://github.com/gookit/slog/compare/v0.5.1...v0.5.2



New feature usage

Custom log file permissions

The log file permission flag created by configuring the FilePerm setting of hander.Config.

h1 := handler.MustFileHandler("/tmp/error.log",
  handler.WithFilePerm(0644), // <- sets log file permissions


Split files using ModeCreate mode

about RotateMode:

  • ModeRename By default, every time rename handles rotation.

  • ModeCreate Create files only by split time

Setting RotateMode=ModeCreate allows log files to be created only by split time.

h1 := handler.MustRotateFile(
  rotatefile.EveryHour, // split by hour
  handler.WithRotateMode(rotatefile.ModeCreate), // set RotateMode=ModeCreate


Configure the logfile as /tmp/error.log in the above example. When set to ModeCreate mode, the file will not actually be created,
Instead, it will be created according to the actual split time:


Tips: The ModeCreate mode can be applied to command-line tool applications. Because they exit after each execution, ModeRename may not be able to split files on time.

And using ModeRename mode will have the following effect:

/tmp/error.log # <- Logs are always written to this file

More usage

More usage please see README

You can’t comment this publication because its author is not yet a full member of the community. You will be able to contact the author only after he or she has been invited by someone in the community. Until then, author’s username will be hidden by an alias.