Help us shape the future of Go! Take the 2026 Go Developer Survey

eslog

package module
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 6 Imported by: 5

README

image:https://github.com/steffakasid/eslog/actions/workflows/go-test.yml/badge.svg[Go Test]
image:https://github.com/steffakasid/eslog/actions/workflows/codeql-analysis.yml/badge.svg[CodeQL]
image:https://img.shields.io/badge/License-Apache%202.0-blue.svg[Apache-2.0]

= eslog

Lightweight, structured logger for Go projects. It basically adds some functions to slog which I found missing (e.g. log*f functions and a logFatal function known from standard log package.). Slog is wrapped inside eslog so you can do everything which is possible with slog.

NOTE: This project is intended to not have any dependencies.

== Install

[source,bash]
----
go get github.com/steffakasid/eslog@latest
----

== Quick start

[source,go]
----
include::./examples/main.go[]
----

== Configuration

* log.level: debug|info|warn|error
* log.format: json|text
* output (optional): file path or stdout/stderr

== Contributing

PRs welcome. Please follow gofmt and golangci-lint rules.

== License

Apache v2

Documentation

Index

Constants

View Source
const LevelFatal = slog.Level(12)
View Source
const LevelPrint = slog.Level(16)

LevelPrint is a sentinel level used by Print/Printf/Println to indicate that the level attribute should be omitted from output. It is higher than default thresholds so it won't be filtered.

Variables

View Source
var Logger *eSlogLogger

Logger is the default logger which extends slog.

Functions

func Debug

func Debug(msg string, args ...any)

Debugf logs at [LevelDebug]. Multiple args are joined with " ".

func DebugLn

func DebugLn(msg string, args ...any)

func Debugf

func Debugf(format string, args ...any)

Debugf logs at [LevelDebug]. The function uses fmt.Sprintf with given format and args and log it.

func Error

func Error(args ...any)

Error logs at [LevelError]. Multiple args are joined with " ".

func ErrorLn

func ErrorLn(msg string, args ...any)

ErrorLn logs at [LevelError] and appends a newline.

func Errorf

func Errorf(format string, args ...any)

Errorf logs at [LevelError]. The function uses fmt.Sprintf with given format and args and log it.

func Fatal

func Fatal(args ...any)

Fatal logs at LevelFatal. Multiple args are joined with " ".

func FatalLn

func FatalLn(msg string, args ...any)

FatalLn logs at LevelFatal and appends a newline, then exits.

func Fatalf

func Fatalf(format string, args ...any)

Fatalf logs at LevelFatal. The function uses fmt.Sprintf with given format and args and log it. Also it calls os.Exit(1).

func Field

func Field(key string, value any) slog.Attr

func Info

func Info(args ...any)

Infof logs at [LevelInfo]. Multiple args are joined with " ".

func InfoLn

func InfoLn(msg string, args ...any)

InfoLn logs at [LevelInfo] and appends a newline.

func Infof

func Infof(format string, args ...any)

Infof logs at [LevelInfo]. The function uses fmt.Sprintf with given format and args and log it.

func LogIfError

func LogIfError(err error, loggerFunc func(args ...any), args ...any)

LogIfError check the given error. If error is nil nothing is logged. If error is not nil the loggerFunc is used to log the args. The error is not automatically added to args except args are empty.

func LogIfErrorf

func LogIfErrorf(err error, loggerFuncf func(format string, args ...any), format string, args ...any)

LogIfErrorf checks the given error. If error is nil nothing is logged. If error is not nil the loggerFuncf is used with the given format to print the given args. The error is not automatically added to args except args are empty.

func New

func New(cfg *Config) *eSlogLogger

func ParseText

func ParseText(text string) (slog.Level, error)

func Print

func Print(args ...any)

Print logs a simple, unstructured message to the configured Logger. The message is produced by fmt.Sprint over args and sent via context.Background. No level, timestamp, or attributes are set on the record; the Handler may supply defaults. Prefer structured or leveled logging APIs for richer context or severity control.

func Printf

func Printf(format string, args ...any)

Printf formats and logs a message using the package's default Logger.

It applies fmt.Sprintf to the provided format and arguments, then submits the resulting text to the Logger's Handler with a background context. This helper emits only the message and does not set a level or attach attributes; prefer structured, leveled logging APIs when additional context is required.

func Println

func Println(args ...any)

Println logs a line by formatting args with fmt.Sprintln (space‑separated, with a trailing newline) and sending the resulting message to the configured Logger’s Handler using context.Background(). It is a convenience wrapper similar to fmt.Println and does not set an explicit log level or add attributes.

func Warn

func Warn(args ...any)

Warn logs at [LevelWarn]. Multiple args are joined with " ".

func WarnLn

func WarnLn(msg string, args ...any)

WarnLn logs at [LevelWarn] and appends a newline.

func Warnf

func Warnf(format string, args ...any)

Fatalf logs at [LevelWarn]. The function uses fmt.Sprintf with given format and args and log it.

Types

type Config

type Config struct {
	Level  slog.Level // Log level: debug, info, warn, error, fatal
	Format Format     // Log format: TextFormat or JSONFormat
	// contains filtered or unexported fields
}

type Format

type Format int

Format represents the log format type.

const (
	TextFormat Format = iota
	JSONFormat
)

func ParseFormat

func ParseFormat(format string) (Format, error)

ParseFormat converts a string to Format. It returns an error if the format string is invalid.

func (Format) String

func (f Format) String() string

String returns the string representation of Format.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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