log

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: BSD-3-Clause Imports: 3 Imported by: 6

README

go-log

Opinionated Go package for doing minimal structured logging and prefixing of log messages with Emoji for easier filtering. It's possible this package will become irrelevant if and when Go slog package because part of "core". Until then it does what I need.

Documentation

Go Reference

Example

import (
	"log"

	aa_log "github.com/aaronland/go-log/v2"
)	

func main(){

	logger := log.Default()

	aa_log.SetMinLevelWithPrefix(aa_log.WARNING_PREFIX)

	// No output
	aa_log.Debug(logger, "This is a test")

	aa_log.UnsetMinLevel()

	// prints "💬 Hello, world"
	aa_log.Info(logger, "Hello, %w", "world")
	
	// prints "🪵 This is a second test"
	aa_log.Debug(logger, "This is a second test")

	// prints "🧯 This is an error"
	aa_log.Warning(logger, fmt.Errorf("This is an error"))

	// Emits errors using the default Go *log.Logger instance
	// prints "{YYYY}/{MM}/{DD} {HH}:{MM}:{SS} 🧯 This is a second error"
	aa_log.Warning(fmt.Errorf("This is a second error"))
}

Prefixes

Log level Prefix
debug 🪵
info 💬
warning 🧯
error 🔥
fatal 💥

Documentation

Index

Constants

View Source
const DEBUG_LEVEL int = 10

DEBUG_LEVEL is the numeric level associated with "debug" messages.

View Source
const DEBUG_PREFIX string = "🪵" // "🦜"

DEBUG_PREFIX is the string prefix to prepend "debug" messages with.

View Source
const ERROR_LEVEL int = 40

ERROR_LEVEL is the numeric level associated with "error" messages.

View Source
const ERROR_PREFIX string = "🔥"

ERROR_PREFIX is the string prefix to prepend "error" messages with.

View Source
const FATAL_LEVEL int = 50

FATAL_LEVEL is the numeric level associated with "fatal" messages.

View Source
const FATAL_PREFIX string = "💥"

FATAL_PREFIX is the string prefix to prepend "fatal" messages with.

View Source
const INFO_LEVEL int = 20

INFO_LEVEL is the numeric level associated with "info" messages.

View Source
const INFO_PREFIX string = "💬"

INFO_PREFIX is the string prefix to prepend "info" messages with.

View Source
const WARNING_LEVEL int = 30

WARNING_LEVEL is the numeric level associated with "warning" messages.

View Source
const WARNING_PREFIX string = "🧯"

WARNING_PREFIX is the string prefix to prepend "warning" messages with.

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

Emit a "debug" log message.

func Error

func Error(args ...interface{})

Emit an "error" log message.

func Fatal

func Fatal(args ...interface{})

Emit an "fatal" log message.

func Info

func Info(args ...interface{})

Emit a "info" log message.

func SetMinLevel

func SetMinLevel(l int) error

SetMinLevel assigns the minimum log level to 'l'. Log events with a lower level will not be emitted.

func SetMinLevelWithPrefix

func SetMinLevelWithPrefix(prefix string) error

SetMinLevelStringWithPrefix assigns the minimum log level associated with 'prefix'. Log events with a lower level will not be emitted.

func UnsetMinLevel

func UnsetMinLevel()

UnsetMinLevel resets the minimum level log level allowing all messages to be emitted.

func Warning

func Warning(args ...interface{})

Emit a "warning" log message.

Types

This section is empty.

Jump to

Keyboard shortcuts

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