logger

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: AGPL-3.0, AGPL-3.0 Imports: 10 Imported by: 4

Documentation

Index

Constants

View Source
const LEVEL_DEBUG = "DEBUG"
View Source
const LEVEL_DPANIC = "DPANIC"
View Source
const LEVEL_ERROR = "ERROR"
View Source
const LEVEL_FATAL = "FATAL"
View Source
const LEVEL_INFO = "INFO"
View Source
const LEVEL_PANIC = "PANIC"
View Source
const LEVEL_WARNING = "WARNING"

Variables

This section is empty.

Functions

func Check

func Check(level string) bool

Check - проверить, что уровень выше глобального и есть подходящие логеры

func CloseLogger

func CloseLogger() error

CloseLogger - закрыть все Logger и создать дефолтный

func Debug

func Debug(mes string, args ...interface{})

Debug print message in Debug level

func Error

func Error(mes string, args ...interface{})

Error print message in Error level

func ErrorAsInfo

func ErrorAsInfo(err error, args ...interface{})

ErrorAsInfo print error in Info level

func GetCaller

func GetCaller(depth int) string

GetCaller returns a Valuer that returns a file and line from a specified depth in the callstack.

func GetCallerShort

func GetCallerShort(depth int) string

GetCallerShort returns a Valuer that returns a file and line from a specified depth in the callstack.

func GetTimestampStr

func GetTimestampStr() string

GetTimestampStr format time

func GlobalZapLogger

func GlobalZapLogger() *zap.Logger

func Info

func Info(mes string, args ...interface{})

Info print message in Info level

func Log

func Log(level string, depth int, mes string, args ...interface{})

Log print message

func NewFileLogger

func NewFileLogger(cfg FileConfig, globalFileName string) *lumberjack.Logger

NewFileLogger - создать новый логгер в файл

func SetGlobalConfig

func SetGlobalConfig(cfg Config) (err error)

SetGlobalConfig - apply new config

func SetStdFilterLevel

func SetStdFilterLevel(lev string)

SetStdFilterLevel set log level

Types

type Config

type Config struct {
	Enable         bool   `json:"enable" yaml:"enable"`                   // состояние логирования 'true', 'false'
	GlobalLevel    string `json:"global_level" yaml:"global_level"`       // debug, info, warn, error, dpanic, panic, fatal - все логгеры ниже этого уровня будут отключены
	GlobalFilename string `json:"global_filename" yaml:"global_filename"` // глобальное имя файл для логирования

	ZapConfig ZapConfig `json:"zap" yaml:"zap"`
}

Config конфигурация сервиса логирования

func GlobalConfig

func GlobalConfig() Config

type FileConfig

type FileConfig struct {
	Filename   string `json:"filename" yaml:"filename"`       // имя файл для логирования
	MaxSize    int    `json:"max_size" yaml:"max_size"`       // максимальный размер лог файла
	MaxAge     int    `json:"max_age" yaml:"max_age"`         // время хранения истории лог файлов в днях
	MaxBackups int    `json:"max_backups" yaml:"max_backups"` // максимальное количество архивных логов
	LocalTime  bool   `json:"local_time" yaml:"local_time"`   // использовать локальное время в имени архивных лог файлов
	Compress   bool   `json:"compress" yaml:"compress"`       // сжимать архивные лог файлы в zip архив
}

FileConfig

type StdConfig

type StdConfig struct {
	Enable      bool   `json:"enable" yaml:"enable"`               // состояние логирования 'true', 'false'
	Level       string `json:"log_level" yaml:"log_level"`         // уровень логирования 'DEBUG', 'INFO', 'ERROR'
	LogToFile   bool   `json:"log_to_file" yaml:"log_to_file"`     // логировать в файл 'true', 'false'
	LogToStderr bool   `json:"log_to_stderr" yaml:"log_to_stderr"` // логировать в stderr 'true', 'false'
	LogFlag     int    `json:"log_flag" yaml:"log_flag"`           // флаги настройки вывода лога
	LogPrefix   string `json:"log_prefix" yaml:"log_prefix"`       // префикс строк в лог файл

	FileConfig *FileConfig `json:"file" yaml:"file"` // конфигурация для логирования в файл, если имя файла пустое, то используется глобальное
}

StdConfig

type WrappedWriteSyncer

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

WrappedWriteSyncer is a helper struct implementing zapcore.WriteSyncer to wrap a standard os.Stdout handle, giving control over the WriteSyncer's Sync() function. Sync() results in an error on Windows in combination with os.Stdout ("sync /dev/stdout: The handle is invalid."). WrappedWriteSyncer simply does nothing when Sync() is called by Zap. https://github.com/uber-go/zap/issues/991

func (WrappedWriteSyncer) Sync

func (mws WrappedWriteSyncer) Sync() error

func (WrappedWriteSyncer) Write

func (mws WrappedWriteSyncer) Write(p []byte) (n int, err error)

type ZapConfig

type ZapConfig struct {
	Enable            bool   `json:"enable" yaml:"enable"`                                   // состояние логирования 'true', 'false'
	DisableCaller     bool   `json:"disable_caller,omitempty" yaml:"disable_caller"`         // запретить вывод в лог информации о caller
	DisableStacktrace bool   `json:"disable_stacktrace,omitempty" yaml:"disable_stacktrace"` // запретить вывод в stacktrace
	StacktraceLevel   string `json:"stacktrace_level" yaml:"stacktrace_level"`               // для какого уровня выводить stacktrace debug, info, warn, error, dpanic, panic, fatal
	Development       bool   `json:"development" yaml:"development"`                         // режим разработки для уровня dpanic

	ZapCoreConfig []ZapCoreConfig `json:"core,omitempty" yaml:"core"`

	Sampling *zap.SamplingConfig `json:"sampling,omitempty" yaml:"sampling"`
}

ZapConfig

type ZapCoreConfig

type ZapCoreConfig struct {
	Enable        bool             `json:"enable" yaml:"enable"`                 // состояние логирования 'true', 'false'
	MinLevel      string           `json:"min_level" yaml:"min_level"`           // минимальный уровень логирования debug, info, warn, error, dpanic, panic, fatal
	MaxLevel      string           `json:"max_level" yaml:"max_level"`           // максимальный уровень логирования debug, info, warn, error, dpanic, panic, fatal
	LogTo         string           `json:"log_to" yaml:"log_to"`                 // логировать в 'file', 'stderr', 'stdout', 'url', 'lumberjack'
	LoggingPath   string           `json:"logging_path" yaml:"logging_path"`     // путь для логирования
	Encoding      string           `json:"encoding,omitempty" yaml:"encoding"`   // формат вывода 'console', 'json'
	FileConfig    *FileConfig      `json:"file" yaml:"file"`                     // конфигурация для логирования в файл, если имя файла пустое, то используется глобальное
	EncoderConfig ZapEncoderConfig `json:"encoder_config" yaml:"encoder_config"` // конфигурация Encoder
}

ZapCoreConfig

type ZapEncoderConfig

type ZapEncoderConfig struct {
	MessageKey       string `json:"message_key,omitempty" yaml:"message_key"`
	LevelKey         string `json:"level_key,omitempty" yaml:"level_key"`
	TimeKey          string `json:"time_key,omitempty" yaml:"time_key"`
	NameKey          string `json:"name_key,omitempty" yaml:"name_key"`
	CallerKey        string `json:"caller_key,omitempty" yaml:"caller_key"`
	FunctionKey      string `json:"function_key,omitempty" yaml:"function_key"`
	StacktraceKey    string `json:"stacktrace_key,omitempty" yaml:"stacktrace_key"`
	SkipLineEnding   bool   `json:"skip_line_ending,omitempty" yaml:"skip_line_ending"`
	LineEnding       string `json:"line_ending,omitempty" yaml:"line_ending"`
	EncodeLevel      string `json:"encode_level,omitempty" yaml:"encode_level"`             // capital, capitalColor, color, lower
	EncodeTime       string `json:"encode_time,omitempty" yaml:"encode_time"`               // rfc3339nano, rfc3339, iso8601, millis, nanos
	EncodeTimeCustom string `json:"encode_time_custom,omitempty" yaml:"encode_time_custom"` // 2006-01-02 15:04:05.000000
	EncodeDuration   string `json:"encode_duration,omitempty" yaml:"encode_duration"`       // string, nanos, ms
	EncodeCaller     string `json:"encode_caller,omitempty" yaml:"encode_caller"`           // full, short
	ConsoleSeparator string `json:"console_separator,omitempty" yaml:"console_separator"`
}

ZapEncoderConfig

Jump to

Keyboard shortcuts

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