logger

package
v4.5.7 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

README

pxnGoCommon-Logger

latest files.poixson.com Built with Weld

A slim and modular logging library for Go. It allows you to link handlers together to format and filter logs, and write to files, the console, or other logging services.

(back to top)

Handlers

  • cli - Print to console
  • level - Filter by log level

Handlers planned:

  • Format - Apply a format to logs
  • html - Convert logs to html format
  • json - Convert logs to json format
  • tee - Fork logs to multiple child handlers
  • null - Drop logs; do nothing
  • file - Write logs to a file
  • memory - Store the latest logs in memory
  • journald - Write logs to journald
  • buffer - Buffer log messages to provide a thread-safe, lock-free, and non-blocking adapter

(back to top)

Log Levels

Log.Print ("Raw lines with no formatting");
Log.Debug ("Detailed information for debugging; ignored if not in debug mode");
Log.Info  ("Normal informational messages");
Log.Alert ("Messages to be aware of; rate limited or rare");
Log.Notice("Messages to be aware of");
Log.Warn  ("Something went wrong but normal operation can continue");
Log.Error ("Something returned an error");
Log.Panic ("Something important returned an error");
Log.Fatal ("Something went seriously wrong");

(back to top)

Dependencies

None.

(back to top)

Usage/Examples

More examples

import(
	Log      "git.poixson.com/PxnLibs/pxnGoCommon/v4/logger"          // import where needed
	Handlers "git.poixson.com/PxnLibs/pxnGoCommon/v4/logger/handlers" // import only for setup
	_        "git.poixson.com/PxnLibs/pxnGoCommon/v4/logger/pxnlog"   // import only once
);

func main() {
	Log.
		SetHandler(Handlers.NewLevelFilter("info")).
		SetHandler(Handlers.NewCLI());
	Log.Debug("This will be hidden");
	Log.Info("This will be logged");
}

(back to top)

TODO

  • more handlers
  • log file rotation
    • max file size
    • max file age
    • max file count
    • compress
  • Trace()

(back to top)

Usage

Import lib anywhere the logging interface is needed, but only import the implementation once, std in this case.

import(
	// import where logging functions are needed
	Log "git.poixson.com/PxnLibs/pxnGoCommon/v4/logger"
	// import only once
	_   "git.poixson.com/PxnLibs/pxnGoCommon/v4/logger/std"
);

func Main() {
	Log.Info("Logger works");
}

See examples for more examples.

(back to top)

Source Code

repo: git.poixson.com/PxnLibs/pxnGoCommon

(back to top)

License

AGPL+PXN, see LICENSE

Be Free and Create

(back to top)

Documentation

Overview

pxnGoCommon - Logger @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

pxnGoCommon - Logger @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

pxnGoCommon - Logger @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

pxnGoCommon - Logger @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

pxnGoCommon - Logger @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

pxnGoCommon - Logger @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

Index

Constants

View Source
const DebugFile = ".debug"
View Source
const DefaultDebugMode = false
View Source
const DefaultLogLevel = LogLvl.Info

Variables

View Source
var (
	ErrRootLoggerAlreadyRegistered = Errs.New("Root logger already registered!")
)

Functions

func Alert

func Alert(value any)

func Alertf

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

func Debug

func Debug(value any)

func Debugf

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

func DisableColors

func DisableColors()

func EnableColors

func EnableColors()

func Error

func Error(value any)

func Errorf

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

func GetLogLevel

func GetLogLevel() LogLvl.Level

log level

func GetUseColors

func GetUseColors() (bool, bool)

console colors

func Info

func Info(value any)

func Infof

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

func IsDebug

func IsDebug() bool

func IsFile

func IsFile(file string) bool

func IsLoggable

func IsLoggable(level LogLvl.Level) bool

func Notice

func Notice(value any)

func Noticef

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

func Panic

func Panic(value any)

func Panicf

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

func Print

func Print(value any)

func Printf

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

func Println

func Println()

func RegisterLogger

func RegisterLogger(log Logger)

func SetDebug

func SetDebug(val bool) bool

func SetEnableColors

func SetEnableColors(enabled bool)

func SetLogLevel

func SetLogLevel(level LogLvl.Level)

func SetQuiet

func SetQuiet()

func SetVerbose

func SetVerbose()

verbose/quiet

func Warn

func Warn(value any)

func Warnf

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

Types

type LogHandler

type LogHandler interface {
	Publish(rec *Record) error
}

type Logger

type Logger interface {
	GetLogType() string
	// handler
	GetHandler() LogHandler
	SetHandler(hand LogHandler) LogHandler
	// publish
	Publish(rec *Record)
	Println()
	Print(value any)
	Debug(value any)
	Info(value any)
	Alert(value any)
	Notice(value any)
	Warn(value any)
	Error(value any)
	Panic(value any)
	Printf(format string, args ...any)
	Debugf(format string, args ...any)
	Infof(format string, args ...any)
	Alertf(format string, args ...any)
	Noticef(format string, args ...any)
	Warnf(format string, args ...any)
	Errorf(format string, args ...any)
	Panicf(format string, args ...any)
}

type Record

type Record struct {
	Line      string
	Level     LogLvl.Level
	Timestamp Time.Time
}

func NewRecord

func NewRecord(level LogLvl.Level, line string, args ...any) *Record

Directories

Path Synopsis
pxnGoCommon - Logger @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/
pxnGoCommon - Logger @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/
pxnGoCommon - Logger @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/
pxnGoCommon - Logger @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/
pxnGoCommon - Standard Logger @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/
pxnGoCommon - Standard Logger @copyright 2026 PoiXson @license AGPL+PXN @author lorenzo at poixson.com @link https://PoiXson.com/

Jump to

Keyboard shortcuts

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