github.com/wfusion/gofusion@v1.1.14/log/types.go (about) 1 package log 2 3 import ( 4 "context" 5 6 "github.com/wfusion/gofusion/common/utils" 7 ) 8 9 type Loggable interface { 10 Debug(ctx context.Context, format string, args ...any) 11 Info(ctx context.Context, format string, args ...any) 12 Warn(ctx context.Context, format string, args ...any) 13 Error(ctx context.Context, format string, args ...any) 14 Panic(ctx context.Context, format string, args ...any) 15 Fatal(ctx context.Context, format string, args ...any) 16 Level(ctx context.Context) Level 17 flush() 18 } 19 20 const ( 21 ErrDuplicatedName utils.Error = "duplicated logger name" 22 ErrUnknownOutput utils.Error = "unknown logger output" 23 ErrDefaultLoggerNotFound utils.Error = "default logger not found" 24 ) 25 26 // A Level is a logging priority. Higher levels are more important. 27 type Level int8 28 29 const ( 30 // DebugLevel logs are typically voluminous, and are usually disabled in 31 // production. 32 DebugLevel Level = iota - 1 33 // InfoLevel is the default logging priority. 34 InfoLevel 35 // WarnLevel logs are more important than Info, but don't need individual 36 // human review. 37 WarnLevel 38 // ErrorLevel logs are high-priority. If an application is running smoothly, 39 // it shouldn't generate any error-level logs. 40 ErrorLevel 41 // dPanicLevel logs are particularly important errors. In development the 42 // logger panics after writing the message. 43 dPanicLevel 44 // PanicLevel logs a message, then panics. 45 PanicLevel 46 // FatalLevel logs a message, then calls os.Exit(1). 47 FatalLevel 48 49 _minLevel = DebugLevel 50 _maxLevel = FatalLevel 51 52 // InvalidLevel is an invalid value for Level. 53 // 54 // Core implementations may panic if they see messages of this level. 55 InvalidLevel = _maxLevel + 1 56 ) 57 58 // Conf log configure 59 //nolint: revive // struct tag too long issue 60 type Conf struct { 61 LogLevel string `yaml:"log_level" json:"log_level" toml:"log_level" default:"info"` 62 StacktraceLevel string `yaml:"stacktrace_level" json:"stacktrace_level" toml:"stacktrace_level" default:"panic"` 63 EnableConsoleOutput bool `yaml:"enable_console_output" json:"enable_console_output" toml:"enable_console_output"` 64 ConsoleOutputOption struct { 65 Layout string `yaml:"layout" json:"layout" toml:"layout" default:"console"` 66 Colorful bool `yaml:"colorful" json:"colorful" toml:"colorful" default:"false"` 67 } `yaml:"console_output_option" json:"console_output_option" toml:"console_output_option"` 68 EnableFileOutput bool `yaml:"enable_file_output" json:"enable_file_output" toml:"enable_file_output"` 69 FileOutputOption struct { 70 Layout string `yaml:"layout" json:"layout" toml:"layout" default:"json"` 71 Path string `yaml:"path" json:"path" toml:"path"` // Log save path 72 Name string `yaml:"name" json:"name" toml:"name"` // Name of the saved log, defaults to random generation 73 RotationMaxAge string `yaml:"rotation_max_age" json:"rotation_max_age" toml:"rotation_max_age" default:"720h"` 74 RotationCount int `yaml:"rotation_count" json:"rotation_count" toml:"rotation_count"` // Maximum number of files to keep 75 RotationSize string `yaml:"rotation_size" json:"rotation_size" toml:"rotation_size" default:"100mib"` // File rotation size 76 Compress bool `yaml:"compress" json:"compress" toml:"compress" default:"false"` 77 } `yaml:"file_output_option" json:"file_output_option" toml:"file_output_option"` 78 SkipCallers []string `yaml:"skip_callers" json:"skip_callers" toml:"skip_callers"` 79 ShorterFilepath bool `yaml:"shorter_filepath" json:"shorter_filepath" toml:"shorter_filepath"` 80 }