logger

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2025 License: MIT Imports: 10 Imported by: 0

README

��# Package "Logger"

[!NOTE] This package use "go.uber.org/zap" and "gopkg.in/natefinch/lumberjack.v2".

Provides logging of specific actions with different logging levels (debug, info, warn,error)

Work start

Use default config or create your own:

  • In your custom config for every level write:

    • filepath, where logs of this level will be stored;
    • max size of that storage file;
    • max number of backups for this file;
    • max age (in days) for logs to storage in file before rotation;
    • compress logs files or not (true/false).
  • To load default config from the package ("default_config.yml"), you can use this code: cfg, err := logger.LoadDefaultConfig()

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	String  = func(key, value string) Field { return Field{Key: key, Value: value} }
	Int     = func(key string, value int) Field { return Field{Key: key, Value: value} }
	Int64   = func(key string, value int64) Field { return Field{Key: key, Value: value} }
	Float64 = func(key string, value float64) Field { return Field{Key: key, Value: value} }
	Bool    = func(key string, value bool) Field { return Field{Key: key, Value: value} }
	Error   = func(err error) Field { return Field{Key: "error", Value: err} }
	Any     = func(key string, value interface{}) Field { return Field{Key: key, Value: value} }
)

Поля для конвертации

Functions

func SetExitFunc

func SetExitFunc(f func(int))

Types

type Config

type Config struct {
	Level      string `yaml:"level"`
	FilePath   string `yaml:"file_path"`
	MaxSizeMB  int    `yaml:"max_size"`
	MaxBackups int    `yaml:"max_backups"`
	MaxAgeDays int    `yaml:"max_age"`
	Compress   bool   `yaml:"compress"`
}

Config содержит конфигурацию логгера

type Field

type Field struct {
	Key   string
	Value interface{}
}

Field представляет собой лог-поле

type LevelConfig

type LevelConfig struct {
	Debug Config `yaml:"debug"`
	Info  Config `yaml:"info"`
	Warn  Config `yaml:"warn"`
	Error Config `yaml:"error"`
}

LevelConfig содержит конфигурацию для разных уровней логирования

func LoadConfig

func LoadConfig(configPath string) (*LevelConfig, error)

LoadConfig загружает конфигурацию из YAML файла

func LoadDefaultConfig

func LoadDefaultConfig() (*LevelConfig, error)

type LevelLogger

type LevelLogger struct {
	// contains filtered or unexported fields
}

LevelLogger представляет собой логгер с разными уровнями

func NewLevel

func NewLevel(configPath string) (*LevelLogger, error)

NewLevel создает новый LevelLogger

func (*LevelLogger) Close

func (m *LevelLogger) Close() error

func (*LevelLogger) Debug

func (m *LevelLogger) Debug(msg string, fields ...Field)

Методы LevelLogger

func (*LevelLogger) Error

func (m *LevelLogger) Error(msg string, fields ...Field)

func (*LevelLogger) Info

func (m *LevelLogger) Info(msg string, fields ...Field)

func (*LevelLogger) Sync

func (m *LevelLogger) Sync() error

func (*LevelLogger) Warn

func (m *LevelLogger) Warn(msg string, fields ...Field)

type Logger

type Logger struct {
	*zap.Logger
	// contains filtered or unexported fields
}

Logger обертка над zap.Logger

func New

func New(cfg Config) (*Logger, error)

New создает новый экземпляр логгера

func (*Logger) Close

func (l *Logger) Close() error

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields ...Field)

Методы Logger

func (*Logger) Error

func (l *Logger) Error(msg string, fields ...Field)

func (*Logger) Info

func (l *Logger) Info(msg string, fields ...Field)

func (*Logger) Sync

func (l *Logger) Sync() error

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields ...Field)

Jump to

Keyboard shortcuts

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