go-logger alternatives and similar packages
Based on the "Logging" category.
Alternatively, view go-logger alternatives based on common mentions on social networks and blogs.
-
spew
Implements a deep pretty printer for Go data structures to aid in debugging -
tail
A Go package striving to emulate the features of the BSD tail program. -
seelog
logging functionality with flexible dispatching, filtering, and formatting. -
logutils
Utilities for slightly better logging in Go (Golang) extending the standard logger. -
Onelog
Dead simple, super fast, zero allocation and modular logger for Golang -
loggo
A logging library for Go. Doesn't use the built in go log standard library, but instead offers a replacement. -
httpretty
Pretty-prints your regular HTTP requests on your terminal for debugging (similar to http.DumpRequest). -
rollingwriter
RollingWriter is an auto-rotate io.Writer implementation with multi policies to provide log file rotation. -
ozzo-log
High performance logging supporting log severity, categorization, and filtering. Can send filtered log messages to various targets (e.g. console, network, mail). -
sqldb-logger
A logger for Go SQL database driver without modify existing *sql.DB stdlib usage. -
xlog
A structured logger for net/context aware HTTP handlers with flexible dispatching. -
logur
An opinionated logger interface and collection of logging best practices with adapters and integrations for well-known libraries (logrus, go-kit log, zap, zerolog, etc). -
gologger
Simple easy to use log lib for go, logs in Colored Cosole, Simple Console, File or Elasticsearch. -
logex
An golang log lib, supports tracking and level, wrap by standard log lib -
stdlog
Stdlog is an object-oriented library providing leveled logging. It is very useful for cron jobs. -
mlog
A simple logging module for go, with 5 levels, an optional rotating logfile feature and stdout/stderr output. -
go-cronowriter
A simple writer that rotate log files automatically based on current date and time, like cronolog. -
distillog
distilled levelled logging (think of it as stdlib + log levels). -
slf
The Structured Logging Facade (SLF) for Go (like SLF4J but structured and for Go) -
journald
Go implementation of systemd Journal's native API for logging. -
Kiwi Logs&Context
Structured logger & context keeper for Go language -
slog
The reference implementation of the Structured Logging Facade (SLF) for Go -
gomol
Gomol is a library for structured, multiple-output logging for Go with extensible logging outputs -
logmatic
Colorized logger for Golang with dynamic log level configuration. -
go-rethinklogger
Automatically persists all the logs of your Go application inside RethinkDB. -
kemba
A tiny debug logging tool inspired by debug, great for CLI tools and applications. -
MrZ's go-logger
Easy to use, extendable and super fast logging package for Go -
gone/log
Fast, extendable, full-featured, std-lib source compatible log library.
Scout APM - Leading-edge performance monitoring starting at $39/month
Do you think we are missing an alternative of go-logger or a related project?
Popular Comparisons
README
go-logger
A simple go logger for easy logging in your programs. Allows setting custom format for messages.
Preview
[[Example Output](examples/example.png)](examples/example.go)
Install
go get github.com/apsdehal/go-logger
Use go get -u
to update the package.
Example
Example [program](examples/example.go) demonstrates how to use the logger. See below for formatting instructions.
package main
import (
"github.com/apsdehal/go-logger"
"os"
)
func main () {
// Get the instance for logger class, "test" is the module name, 1 is used to
// state if we want coloring
// Third option is optional and is instance of type io.Writer, defaults to os.Stderr
log, err := logger.New("test", 1, os.Stdout)
if err != nil {
panic(err) // Check for error
}
// Critically log critical
log.Critical("This is Critical!")
log.CriticalF("%+v", err)
// You can also use fmt compliant naming scheme such as log.Criticalf, log.Panicf etc
// with small 'f'
// Debug
// Since default logging level is Info this won't print anything
log.Debug("This is Debug!")
log.DebugF("Here are some numbers: %d %d %f", 10, -3, 3.14)
// Give the Warning
log.Warning("This is Warning!")
log.WarningF("This is Warning!")
// Show the error
log.Error("This is Error!")
log.ErrorF("This is Error!")
// Notice
log.Notice("This is Notice!")
log.NoticeF("%s %s", "This", "is Notice!")
// Show the info
log.Info("This is Info!")
log.InfoF("This is %s!", "Info")
log.StackAsError("Message before printing stack");
// Show warning with format
log.SetFormat("[%{module}] [%{level}] %{message}")
log.Warning("This is Warning!") // output: "[test] [WARNING] This is Warning!"
// Also you can set your format as default format for all new loggers
logger.SetDefaultFormat("%{message}")
log2, _ := logger.New("pkg", 1, os.Stdout)
log2.Error("This is Error!") // output: "This is Error!"
// Use log levels to set your log priority
log2.SetLogLevel(DebugLevel)
// This will be printed
log2.Debug("This is debug!")
log2.SetLogLevel(WarningLevel)
// This won't be printed
log2.Info("This is an error!")
}
Formatting
By default all log messages have format that you can see above (on pic). But you can override the default format and set format that you want.
You can do it for Logger instance (after creating logger) ...
log, _ := logger.New("pkgname", 1)
log.SetFormat(format)
... or for package
logger.SetDefaultFormat(format)
If you do it for package, all existing loggers will print log messages with format that these used already. But all newest loggers (which will be created after changing format for package) will use your specified format.
But anyway after this, you can still set format of message for specific Logger instance.
Format of log message must contains verbs that represent some info about current log entry. Ofc, format can contain not only verbs but also something else (for example text, digits, symbols, etc)
Format verbs:
You can use the following verbs:
%{id} - means number of current log message
%{module} - means module name (that you passed to func New())
%{time} - means current time in format "2006-01-02 15:04:05"
%{time:format} - means current time in format that you want
(supports all formats supported by go package "time")
%{level} - means level name (upper case) of log message ("ERROR", "DEBUG", etc)
%{lvl} - means first 3 letters of level name (upper case) of log message ("ERR", "DEB", etc)
%{file} - means name of file in what you wanna write log
%{filename} - means the same as %{file}
%{line} - means line number of file in what you wanna write log
%{message} - means your log message
Non-existent verbs (like %{nonex-verb}
or %{}
) will be replaced by an empty string.
Invalid verbs (like %{inv-verb
) will be treated as plain text.
Tests
Run:
go test logger
to run test on logger.go test -bench=.
for benchmarks.
Thanks
Thanks goes to all go-loggers out there which I used as reference.
Contributors
Following contributors have made major contributions to go-logger:
License
The BSD 3-Clause license, the same as the Go language.
*Note that all licence references and agreements mentioned in the go-logger README section above
are relevant to that project's source code only.