logit

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 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:

$ go run main.go

Detailed configuration:

package main

import (
	"log/slog"
	"os"

	"github.com/sfmunoz/logit"
)

var log = logit.Logit().
	With("app", "my-app").
	WithWriter(os.Stderr).
	WithSource(true).
	WithLevel(slog.LevelDebug).
	WithTimeFormat("2006-01-02T15:04:05.000Z07:00").
	WithTime(true).
	WithUptime(true).
	WithColor(true)

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

References

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

The guide to read is this one:

https://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

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
)

Variables

This section is empty.

Functions

func Logit

func Logit() *logit

Types

This section is empty.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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