Simple logger for Go with no dependencies
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
IamTheFij 548575b4a7 Add Fatal and Panic 1 month ago
.gitignore Move from dockron 1 month ago
.pre-commit-config.yaml Remove docker pre-commit hooks 1 month ago
LICENSE Initial commit 1 month ago
Makefile Move from dockron 1 month ago
README.md Add Fatal and Panic 1 month ago
add-docs-to-readme.sh Move from dockron 1 month ago
go.mod Move from dockron 1 month ago
slog.go Add Fatal and Panic 1 month ago

README.md

slog

A simple logger for Go with no dependencies

I know there are many go loggers out there that offer various logging features such as file rotation, granular verbosity settings, colored and JSON output, etc.

Slog is not one of them.

Slog lets you hide or show debug logs as well as provides a simpler way to log messages with Warning and Error prefixes for consistency.

Also provided are a few simple methods for handling returned error variables, logging them out and optionally panicing or fatally exiting.

Documentation

package slog // import "git.iamthefij.com/iamthefij/slog"

Package slog is a super simple logger that allows a few convenience methods
for handling debug vs warning/error logs. It also adds a few conveniences
for handling errors.

VARIABLES

var (
    // DebugLevel indicates if we should log at the debug level
    DebugLevel = true

    // LoggerInfo is the slog Info logger
    LoggerInfo = log.New(os.Stderr, "INFO    ", defaultFlags)
    // LoggerWarning is the slog Warning logger
    LoggerWarning = log.New(os.Stderr, "WARNING ", defaultFlags)
    // LoggerError is the slog Error logger
    LoggerError = log.New(os.Stderr, "ERROR   ", defaultFlags)
    // LoggerDebug is the slog Debug logger
    LoggerDebug = log.New(os.Stderr, "DEBUG   ", defaultFlags)
)

FUNCTIONS

func Debug(format string, v ...interface{})
    Debug will log with a DEBUG prefix if DebugLevel is se

func Error(format string, v ...interface{})
    Error will log with a ERROR prefix

func Fatal(format string, v ...interface{})
    Fatal will log with a ERROR prefix followed by exit(1)

func FatalOnErr(err error, format string, v ...interface{})
    FatalOnErr if error provided, will log out details of an error and exi

func Info(format string, v ...interface{})
    Info formats logs with an INFO prefix

func Log(format string, v ...interface{})
    Log formats logs directly to the main logger

func Panic(format string, v ...interface{})
    Panic will log with a ERROR prefix followed by panic()

func PanicOnErr(err error, format string, v ...interface{})
    PanicOnErr if error provided, will log out details of an error and exi

func SetFlags(flag int)
    SetFlags allows changing the logger flags using flags found in `log`

func SetOutput(w io.Writer)
    SetOutput allows changing the output of all loggers

func WarnOnErr(err error, format string, v ...interface{})
    WarnOnErr if error provided, will provide a warning if an error is provided

func Warning(format string, v ...interface{})
    Warning will log with a WARNING prefix