Documentation ¶
Index ¶
- Constants
- Variables
- func SetDefaultLogFile(filename string) error
- func SetLevel(logPathGlob string, level Level)
- func Sync() error
- func TemporarySetLevel(logPath string, level Level, d time.Duration)
- type Config
- type Console
- type ConsoleLog
- type Encoder
- type Factory
- type FileLog
- type ITemporarySetLevel
- type InnerLog
- type Level
- type Logger
- func Log[T any]() Logger
- func LogWithConfig[T any](cfg *Config) Logger
- func LogWithConfigPath[T any](cfgPath string) Logger
- func New(t any) Logger
- func NewWithConfigPath(t any, cfgPath string) Logger
- func NewWithTypePathAndConfig(typePath string, cfg *Config) Logger
- func NewWithTypePathAndConfigPath(typePath string, cfgPath string) Logger
- type Name
Constants ¶
const DefaultConfigPath = "logging"
Variables ¶
var ErrInvalidConsole = errors.New("not a valid Console")
var ErrInvalidEncoder = errors.New("not a valid Encoder")
var ErrInvalidLevel = errors.New("not a valid Level")
var ErrInvalidName = errors.New("not a valid Name")
Functions ¶
func SetDefaultLogFile ¶
Types ¶
type Config ¶
type Config struct { Level map[string]Level Console ConsoleLog File FileLog WithCaller bool `value:"true"` WithLogName Name `value:"short"` }
func (*Config) GetZapLevelByType ¶
type Console ¶
type Console string
Console is en enum
@Enum { no stdout stderr }
func ParseConsole ¶
ParseConsole converts a string to a Console.
func (Console) IsValid ¶
IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values
func (Console) MarshalText ¶
MarshalText implements the text marshaller method.
func (*Console) UnmarshalText ¶
UnmarshalText implements the text unmarshaller method.
type ConsoleLog ¶
type Encoder ¶
type Encoder int
Encoder
@Enum { text json }
func ParseEncoder ¶
ParseEncoder converts a string to an Encoder.
func (Encoder) IsValid ¶
IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values
func (Encoder) MarshalText ¶
MarshalText implements the text marshaller method.
func (*Encoder) UnmarshalText ¶
UnmarshalText implements the text unmarshaller method.
type FileLog ¶
type FileLog struct { // Filename is the file to write logs to. Backup log files will be retained // in the same directory. It uses <processname>-lumberjack.log in // os.TempDir() if empty. Filename string `json:"filename" yaml:"filename"` // MaxSize is the maximum size in megabytes of the log file before it gets // rotated. It defaults to 100 megabytes. MaxSize int `json:"maxsize" yaml:"maxsize" value:"100"` // MaxAge is the maximum number of days to retain old log files based on the // timestamp encoded in their filename. Note that a day is defined as 24 // hours and may not exactly correspond to calendar days due to daylight // savings, leap seconds, etc. The default is not to remove old log files // based on age. MaxAge int `json:"maxage" yaml:"maxage" value:"30"` // MaxBackups is the maximum number of old log files to retain. The default // is to retain all old log files (though MaxAge may still cause them to get // deleted.) MaxBackups int `json:"maxbackups" yaml:"maxbackups" value:"30"` // LocalTime determines if the time used for formatting the timestamps in // backup files is the computer's local time. The default is to use UTC // time. LocalTime bool `json:"localtime" yaml:"localtime" value:"false"` // Compress determines if the rotated log files should be compressed // using gzip. The default is not to perform compression. Compress bool `json:"compress" yaml:"compress" value:"true"` Encoder Encoder `json:"encoder" yaml:"encoder" value:"text"` }
type ITemporarySetLevel ¶
type Level ¶
type Level int8
Level is an enum
@EnumConfig(PanicIfInvalid) @Enum { Debug = -1 Info Warn Error DPanic Panic Fatal Invalid }
const ( // LevelDebug is a Level of type Debug. LevelDebug Level = -1 // LevelInfo is a Level of type Info. LevelInfo Level = 0 // LevelWarn is a Level of type Warn. LevelWarn Level = 1 // LevelError is a Level of type Error. LevelError Level = 2 // LevelDpanic is a Level of type DPanic. LevelDpanic Level = 3 // LevelPanic is a Level of type Panic. LevelPanic Level = 4 // LevelFatal is a Level of type Fatal. LevelFatal Level = 5 // LevelInvalid is a Level of type Invalid. LevelInvalid Level = 6 )
func ParseLevel ¶
ParseLevel converts a string to a Level.
func (Level) IsValid ¶
IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values
func (Level) MarshalText ¶
MarshalText implements the text marshaller method.
func (Level) ToZapLevel ¶
func (*Level) UnmarshalText ¶
UnmarshalText implements the text unmarshaller method.
type Logger ¶
type Logger interface { Level() Level SetLevel(lvl Level) TemporarySetLevel(lvl Level, d time.Duration) AddHook(func(level Level, t time.Time, name string, msg string)) Writer() io.Writer Sync() error Log(lvl Level, args ...any) Debug(args ...any) Info(args ...any) Warn(args ...any) Error(args ...any) Panic(args ...any) Fatal(args ...any) Logf(lvl Level, template string, args ...any) Debugf(template string, args ...any) Infof(template string, args ...any) Warnf(template string, args ...any) Errorf(template string, args ...any) Panicf(template string, args ...any) Fatalf(template string, args ...any) Logw(lvl Level, msg string, keysAndValues ...any) Debugw(msg string, keysAndValues ...any) Infow(msg string, keysAndValues ...any) Warnw(msg string, keysAndValues ...any) Errorw(msg string, keysAndValues ...any) Panicw(msg string, keysAndValues ...any) Fatalw(msg string, keysAndValues ...any) }
func LogWithConfig ¶
func LogWithConfigPath ¶
func NewWithConfigPath ¶
@Factory(params={self, "value:logging"})
type Name ¶
type Name string
Name is en enum
@Enum { no // no name short // with short path full // with full path }
func (Name) IsValid ¶
IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values
func (Name) MarshalText ¶
MarshalText implements the text marshaller method.
func (*Name) UnmarshalText ¶
UnmarshalText implements the text unmarshaller method.