logit

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2025 License: MIT Imports: 2 Imported by: 0

README

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
(...)

[!TIP] So the must reading guide is the following one:
https://golang.org/s/slog-handler-guidehttps://github.com/golang/example/blob/master/slog-handler-guide/README.md

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:

Documentation

Overview

Package logit implements a simple yet powerful logging/slog library

Usage

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:

$ go run main.go
2025-07-14T15:10:26.591Z 0d00h00m00.000s [N] notice-msg app=my-app
2025-07-14T15:10:26.591Z 0d00h00m00.000s [W] warn-msg app=my-app
2025-07-14T15:10:26.591Z 0d00h00m00.000s [E] error-msg app=my-app

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:

$ go run main.go
2025-07-25T09:44:45.734Z 0d00h00m00.000s [I] <demo/main.go:18> hello world app=my-app

Index

Constants

View Source
const (
	LevelTrace  = common.LevelTrace
	LevelDebug  = common.LevelDebug
	LevelInfo   = common.LevelInfo
	LevelNotice = common.LevelNotice
	LevelWarn   = common.LevelWarn
	LevelError  = common.LevelError
	LevelFatal  = common.LevelFatal

	SymbolNone        = common.SymbolNone
	SymbolUnicodeUp   = common.SymbolUnicodeUp
	SymbolUnicodeDown = common.SymbolUnicodeDown

	TplTime    = common.TplTime
	TplUptime  = common.TplUptime
	TplLevel   = common.TplLevel
	TplSource  = common.TplSource
	TplMessage = common.TplMessage
	TplAttrs   = common.TplAttrs

	UptimeAdhoc = common.UptimeAdhoc
	UptimeStd   = common.UptimeStd

	AttrsStd     = common.AttrsStd
	AttrsBuiltin = common.AttrsBuiltin
)

Variables

This section is empty.

Functions

func Logit

func Logit() *logit

Types

This section is empty.

Directories

Path Synopsis
cmd
logit-demo command
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL