Documentation ¶
Overview ¶
Package rotoslog provides a slog.Handler implementation that writes to a rotating set of files. Log file names have the following structure: <prefix>(<suffix>|<timestamp>)<extension>. When creating a new handler the user can set various options:
- LogDir: directory where log files are created (default: "log")
- FilePrefix: file name <prefix> (default: "")
- CurrentFileSuffix: current file name <suffix> (default : "current")
- FileExt: file <extension> (default: ".log")
- DateTimeLayout: <timestamp> layout to be used in calls to time.Time.Format (default: "20060102150405")
- MaxFileSize: size threshold that triggers rotation (default: 32M)
- MaxRotatedFiles: number of rotated files to keep (default: 8)
- HandlerOptions: slog.HandlerOptions (default: zero value)
- LogHandlerBuilder: a function that can build a slog.Handler used for formatting log data (default: NewJSONHandler)
Index ¶
- Constants
- func CurrentFileSuffix(suffix string) optFun
- func DateTimeLayout(layout string) optFun
- func FileExt(ext string) optFun
- func FilePrefix(prefix string) optFun
- func HandlerOptions(opts slog.HandlerOptions) optFun
- func LogDir(dir string) optFun
- func LogHandlerBuilder(builder HandlerBuilder) optFun
- func MaxFileSize(size uint64) optFun
- func MaxRotatedFiles(n uint64) optFun
- func NewHandler(options ...optFun) (slog.Handler, error)
- func NewJSONHandler(w io.Writer, opts *slog.HandlerOptions) slog.Handler
- func NewTextHandler(w io.Writer, opts *slog.HandlerOptions) slog.Handler
- type HandlerBuilder
Constants ¶
const ( DEFAULT_FILE_DIR = "log" DEFAULT_FILE_NAME_PREFIX = "" DEFAULT_CURRENT_FILE_SUFFIX = "current" DEFAULT_FILE_EXTENSION = ".log" DEFAULT_CURRENT_FILE_NAME = DEFAULT_FILE_NAME_PREFIX + DEFAULT_CURRENT_FILE_SUFFIX + DEFAULT_FILE_EXTENSION DEFAULT_FILE_DATE_FORMAT = "20060102150405" DEFAULT_MAX_FILE_SIZE = 32 * 1024 * 1024 DEFAULT_MAX_ROTATED_FILES = 8 )
Variables ¶
This section is empty.
Functions ¶
func CurrentFileSuffix ¶ added in v0.2.0
func CurrentFileSuffix(suffix string) optFun
CurrentFileSuffix sets the current logging file suffix.
func DateTimeLayout ¶ added in v0.2.0
func DateTimeLayout(layout string) optFun
DateTimeLayout sets the timestamp layout used in rotated file names.
func FilePrefix ¶ added in v0.2.0
func FilePrefix(prefix string) optFun
FilePrefix sets the logging file prefix.
func HandlerOptions ¶ added in v0.2.0
func HandlerOptions(opts slog.HandlerOptions) optFun
HandlerOptions sets the slog.HandlerOptions for the handler.
func LogDir ¶ added in v0.2.0
func LogDir(dir string) optFun
LogDir sets the path to the logging directory
func LogHandlerBuilder ¶ added in v0.2.0
func LogHandlerBuilder(builder HandlerBuilder) optFun
LogHandlerBuilder sets the HandlerBuilder used for formatting.
func MaxFileSize ¶ added in v0.2.0
func MaxFileSize(size uint64) optFun
MaxFileSize sets the size threshold that triggers file rotation.
func MaxRotatedFiles ¶ added in v0.2.0
func MaxRotatedFiles(n uint64) optFun
MaxRotatedFiles sets the maximum number of rotated files. When this number is exceeded the oldest rotated fle is deleted.
func NewHandler ¶
NewHandler creates a new handler with the given options.
func NewJSONHandler ¶
NewJSONHandler is a HandlerBuilder that creates a slog.JSONHandler.
func NewTextHandler ¶
NewTestHandler is a HandlerBuilder that creates a slog.TextHandler.
Types ¶
type HandlerBuilder ¶
HandlerBuilder is a type representing functions used to create handlers to control formatting of logging data.