log

package module
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 8 Imported by: 0

README

log

A versatile and modular logging library designed specifically for Go applications. With log, you can effortlessly manage and organize your logs in a way that suits your modular application structure. Whether you need a global logger for your application or specific local loggers for individual modules, log has got you covered.

go get github.com/leonidasdeim/log

Features

Modular Logging: log is tailored for modular applications, allowing you to create both global and local loggers. This flexibility empowers you to manage logs efficiently across different parts of your application while maintaining global properties.

Global and Local Logging: Enjoy the best of both worlds. Use a main logger for global logging requirements, while simultaneously creating local loggers with distinct properties for individual modules or components.

Customizable Logging Levels: log supports customizable logging levels, enabling you to fine-tune the verbosity of your logs. Choose from a range of logging levels such as DEBUG, INFO, WARNING, ERROR, and FATAL.

Formatted Logging: Format your log messages the way you want. log supports flexible log message formatting to suit your needs.

Concurrency-Safe: Built to handle concurrent access safely, log ensures that your logs won't get tangled when multiple goroutines are writing to the same logger.

Extensible: Easily extend log with custom log output targets or adjust its behavior to fit your specific application requirements.

Usage

Please check usage examples in examples/

Documentation

Index

Constants

View Source
const (
	ColorTextLogFormat = "%s | %14s | %16s | %s %s"
	TextLogFormat      = "%s | %5s | %7s | %s %s"
	TextPropFormat     = " | %s=%v"
)
View Source
const (
	DefaultLevel      = Info
	DefaultName       = "<...>"
	DefaultFormat     = FormatTextColor
	DefaultWriteMode  = ModeBlocking
	DefaultDateFormat = "2006/01/02 15:04:05"
)

Variables

This section is empty.

Functions

func NewProcessor added in v0.1.0

func NewProcessor(mode WriteMode) *processor

Types

type Format added in v0.0.2

type Format int
const (
	FormatText Format = iota
	FormatTextColor
	FormatJson
)

type JsonStruct added in v0.1.1

type JsonStruct struct {
	Time    string                 `json:"time"`
	Level   string                 `json:"level"`
	Module  string                 `json:"module"`
	Message string                 `json:"message"`
	Props   map[string]interface{} `json:"props"`
}

type Level added in v0.0.2

type Level string
const (
	Fatal   Level = "FATAL"
	Error   Level = "ERROR"
	Warning Level = "WARN"
	Info    Level = "INFO"
	Debug   Level = "DEBUG"
)

type Logger

type Logger interface {
	NewLocal(opts ...Op) Logger
	SetLevel(level Level) error
	Level() Level
	Close()
	Info() *message
	Error() *message
	Warning() *message
	Debug() *message
	Fatal() *message
}

func New

func New(opts ...Op) Logger

New main logger instance, accepts both global and local options: WithName(string), WithLevel(log.Level), WithMode(log.WriteMode), WithDateFormat(string), WithWriter(io.Writer, log.Format)

type Op added in v0.0.2

type Op func(*globalProps, *localProps)

func WithDateFormat added in v0.0.2

func WithDateFormat(f string) Op

WithDateFormat (global logger option), set date/time format (default: "2006/01/02 15:04:05")

func WithLevel added in v0.0.2

func WithLevel(l Level) Op

WithLevel (local logger option), set logger/module log level (default: Info)

func WithMode added in v0.0.2

func WithMode(m WriteMode) Op

WithMode (global logger option), set blocking or non blocking logger mode (default: log.ModeBlocking)

func WithName added in v0.0.2

func WithName(n string) Op

WithName (local logger option), set logger/module name up to 7 characters (default: "<...>")

func WithWriter added in v0.0.2

func WithWriter(w io.Writer, f Format) Op

WithWriter (global/local logger option), set custom log writer (default: os.Stdout) Several WithWriter options could be added

type WriteMode added in v0.0.2

type WriteMode int
const (
	ModeNonBlocking WriteMode = 1 + iota
	ModeBlocking
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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