Library / SDK
gookit/slog avatar
gookit/slog

slog is a batteries-included Go logger with file rotation built in

📑 Lightweight, configurable, extensible logging library written in Go. Support multi level, multi outputs and built-in multi file logger, buffers, clean, rotate-file handling.一个易于使用的,轻量级、可配置、可扩展的日志库。支持多个级别,输出到多文件;内置文件日志处理、自动切割、清理、压缩等增强功能

556 stars33 forksGoMIT

At a glance

What is it?
gookit/slog is a Go logging library with eight levels, pluggable formatters and handlers, built-in console, file, rotating file, syslog and email handlers, and a standalone rotatefile subpackage you can drop into other loggers. It suits an application or CLI tool that wants file rotation and coloured console output without adding dependencies, and it predates the standard library slog.
Who is it for?
Adopt slog when you are building an application or CLI tool and want a logger that already handles coloured console output, file rotation, cleanup and compression without a third party dependency. Do not adopt it as a library dependency in a service you publish, because the standard library slog is the better fit there and the README says so.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 8 days ago.
What is it written in?
Mainly Go, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on October 22, 2026, and from our analysis. They are not legal advice.

Editorial analysis

Eight levels, with the severity running the other way

slog supports the common level set of trace, debug, info, notice, warn, error, fatal and panic, and it is directly usable without any configuration. The quick start is four calls:

go
package main

import (
	"github.com/gookit/slog"
)

func main() {
	slog.Info("info log message")
	slog.Warn("warning log message")
	slog.Infof("info log %s", "message")
	slog.Debugf("debug %s", "message")
}

The output format is a bracketed line carrying the timestamp, the application name, the level, the source file and line, and the message. The one convention worth internalising is in the comparison table, which notes that slog's levels run Panic, Fatal, Error, Warn, Notice, Info, Debug and Trace with a higher value meaning less severe, while the standard library runs the other way with Debug at minus four and Error at eight. If you are porting code between the two, that inversion is the thing that silently reverses your filter. The library also offers a sugared style with printf variants and WithField, closer to logrus and zap than to the standard library.

Handlers and formatters are the extension points

The design is a handler and a formatter model, and the feature list makes the boundaries clear. Any extension of Handler and Formatter is supported, and multiple Handler instances can be added at the same time so that logs go to different places from one call. The formatter decides what a record looks like, with built-in json and text formatters and support for a custom message formatter. The handler decides where the record goes and how it is built, with a built-in handler.Config and handler.Builder that can build the handler you want quickly. The built-in handlers are the practical part. Console outputs to the console with colour support. Writer writes to any io.Writer you specify. File writes to a specified file and can optionally buffer writes. Simple writes directly to a file with no buffering. And rotate_file writes to a specified file, supports splitting by time and size, and has buffered writing enabled by default. The handler/ directory holds the built-in implementations, and the API style is the logrus and zap-sugar shape, with Infof and WithField as the familiar calls.

File logging, rotation and cleanup are the reason to use it

The file side of the library is where it differs from a plain logger. Buffering can be enabled for log writing, so writes are batched rather than issued per record. Log files can be split by time and by size, and there is configuration to compress log files with gzip, which is what keeps a long-running service from filling a disk with plain text. Old log files are cleaned by the BackupNum and BackupTime settings, so retention is a count and a duration rather than something you write yourself. The rotatefile subpackage is the part that makes the library reusable outside slog. It is a standalone tool library with file splitting, cleaning and compressing of backups, and rotatefile.Writer can be wrapped and used with other logging libraries such as log, glog and zap. rotatefile.FilesClear is an independent cleaning tool that can be used in other places, and the README notes it works for other program log cleaning tasks such as PHP. The interop point is spelled out too, since rotatefile.Writer is a plain io.Writer you can use with the standard library slog as well.

How it compares with the standard library

The README has a section comparing gookit/slog with the standard log/slog added in Go 1.21, and it is unusually candid about the relationship. The library predates the standard one and aims at a different sweet spot, and the guide is a quick one for choosing. Use the standard log/slog when you want a zero-dependency, high-performance structured logger and will bring your own sinks, which is the case for libraries and services. Use gookit/slog when you want a batteries-included logger for applications and CLI tools, with built-in file rotation, coloured and templated console output, multiple handlers for file, syslog, email, buffered and multi, processors, and Fatal and Panic behaviour. The table sets out the differences row by row. Distribution is third party against the standard library with zero dependencies. File rotation is built in against not included, where you bring a third party writer. Console output is coloured and template based against fixed logfmt text or JSON. Performance is any-based args with more allocations against typed Attr and Value values with near zero allocation through LogAttrs. And context handling goes through WithContext and the Ctx methods against the context-first design with WithGroup, Group and LogValuer.

Configuring colour and output style

The console handler is coloured by default, and the README shows the configuration path for changing it, which goes through the logger's Configure function and reaches into the formatter to toggle EnableColor. That is a slightly awkward shape for a user who only wants to turn colour off in a CI log, but it does show that the formatter is where the presentation decisions live. The same section explains that you can also create your own logger and append a ConsoleHandler to it, through NewConsoleHandler with a level set and NewWithHandlers, which is the route to take when you want one logger writing to the console and another writing to a file. The formatter is also where a templated output style is set, and the documented console template is of the form [{{datetime}}] [{{level}}] and so on, which is the piece that lets you rearrange the fields of a line without replacing the handler.

Dependencies, structure and the build

The go.mod targets Go 1.19 and the dependency list is short and tells you what the library leans on. gookit/color at 1.6.3 is the colour output, gookit/goutil at 0.8.3 is the general utility package, gookit/gsr is the structured record type used by the formatters, gookit/rotatefile at 0.3.0 is the rotation engine, and valyala/bytebufferpool is the buffer pool behind the buffered writers. The repository layout is flat and readable, with logger.go and logger_write.go for the core, sugared.go for the printf and field style API, handler.go, formatter.go with formatter_text.go and formatter_json.go for the two built-in formats, processor.go for the log processors, record.go for the record type, and the handler/, rotatefile/, internal/, bufwrite/ and docs/ directories. There is a separate _example/ directory, a Makefile with a testdata build target and a version stamped from the latest tag plus the commit, and benchmark files at the root, with the README pointing to a benchmark section. The release history shows v0.7.1 in June 2026 after v0.7.0 two days earlier, with v0.6.0 in August 2025, and the last push was on 2026-10-15. The licence is MIT.

Editorial conclusion

Adopt slog when you are building an application or CLI tool and want a logger that already handles coloured console output, file rotation, cleanup and compression without a third party dependency. Do not adopt it as a library dependency in a service you publish, because the standard library slog is the better fit there and the README says so. Verify first which level semantics suit your code, since slog's higher value means less severe while the standard library's lower value means less severe, and that the rotatefile writer you use is configured with a retention policy you have actually thought about.

Frequently asked questions

Should I use gookit/slog or the standard library log/slog?

The README's guide says use the standard log/slog when you want a zero-dependency, high-performance structured logger and will bring your own sinks, which suits libraries and services. Use gookit/slog when you want a batteries-included logger for applications and CLI tools, with built-in file rotation, coloured and templated console output, multiple handlers, processors and Fatal and Panic behaviour.

Which log levels does gookit/slog support?

Trace, debug, info, notice, warn, error, fatal and panic. The comparison table notes that in slog a higher value means less severe, while in the standard library a lower value means less severe, so filters have to be inverted when moving between the two.

What handlers does gookit/slog ship with?

Console, which writes to the console with colour output, writer for a specified io.Writer, file for a specified file with optional buffering, simple which writes directly to a file without buffering, and rotate_file which writes to a file with splitting by time and size and buffered writing enabled by default. Syslog, email, buffered and multi handlers are also listed as built-in.

Can I use the gookit rotatefile writer with another logger?

Yes. The rotatefile subpackage is a standalone tool library with file splitting, cleaning and compressing of backups, and rotatefile.Writer can be wrapped and used with other logging libraries such as log, glog and zap. Because it is a plain io.Writer you can also use it with the standard library log/slog.

Official sources

  1. gookit/slog on GitHub
  2. License: MIT
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/gookit-slog.svg)](https://hysenlabs.com/projects/gookit-slog)

Was this useful?