Skip to content

zuern/zlog

Repository files navigation

zlog

Package zlog provides a minimal setup for log/slog with sensible defaults.

Quick start

package main

import (
	"flag"
	"log/slog"

	"zuern.dev/zlog"
)

func main() {
	level := zlog.RegisterLevelFlag(flag.CommandLine)
	flag.Parse()

	zlog.Init(level)
	slog.Info("service started", slog.String("version", "1.2.3"))
}

Output format

The handler format is selected in this order:

  1. LOG_FORMAT=json or LOG_FORMAT=text if set.
  2. Otherwise, text format when stderr is a TTY and JSON when it is not.

Attribution

The pretty text handler in prettylog is derived from dusted-go/logging's handlers/prettylog and is licensed under Apache 2.0. See https://github.com/dusted-go/logging/tree/main/handlers/prettylog.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages