Skip to content

sfmunoz/logit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logit

logit: Simple Golang logging/slog library

Features

  • No dependencies
  • Fluent configuration (one line)
    • Simple and easy
    • Compact
  • Extra log levels
    • Usual: debug, info, warn, error
    • Added: trace, notice, fatal, panic
  • Color support
  • slog based so it requires Golang 1.21+
  • slog.Logger + slog.Handler compatible
  • Opinionated

TL;DR

Init module within an empty folder:

$ go mod init example.com/demo

$ cat go.mod 
module example.com/demo

go 1.24.5

Download/install logit:

$ go get -u github.com/sfmunoz/logit

Create main.go file:

package main

import "github.com/sfmunoz/logit"

var log = logit.Logit().
	WithLevel(logit.LevelNotice).
	With("app", "my-app")

func main() {
	log.Trace("trace-msg")
	log.Debug("debug-msg")
	log.Info("info-msg")
	log.Notice("notice-msg")
	log.Warn("warn-msg")
	log.Error("error-msg")
}

Run it using go run main.go:

20250714_151107.png

Detailed configuration:

package main

import (
	"os"

	"github.com/sfmunoz/logit"
)

var log = logit.Logit().
	With("app", "my-app").
	WithWriter(os.Stderr).
	WithTpl(logit.TplTime, logit.TplUptime, logit.TplLevel, logit.TplSource, logit.TplMessage, logit.TplAttrs).
	WithLevel(logit.LevelDebug).
	WithTimeFormat("2006-01-02T15:04:05.000Z07:00").
	WithColor(true)

func main() {
	log.Info("hello world")
}

Run it too with go run main.go:

20250725_094637.png

References

$ go doc slog
(...)
For a guide to writing a custom handler, see https://golang.org/s/slog-handler-guide
(...)

There are 4 versions of the indenthandler example in the README.md:

https://github.com/golang/example/tree/master/slog-handler-guide

Google: 'golang slog'

slog related videos:

Others

Google: 'golang slog color'

Google: 'golang log packages'

zap & zerolog:

About

Simple Golang logging/slog library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages