Compare commits

..

2 Commits

Author SHA1 Message Date
kingecg 27fcdad135 fix nil pointer error 2025-06-06 23:30:27 +08:00
kingecg 1004333534 fix 2025-06-06 20:23:06 +08:00
2 changed files with 12 additions and 6 deletions

View File

@ -10,11 +10,14 @@ import (
// LogFormatter is a function type that formats a LogEvent into a string. // LogFormatter is a function type that formats a LogEvent into a string.
// Example: // Example:
// formatter := func(event LogEvent) string { //
// return fmt.Sprintf("[%s] %s: %v", event.Ts.Format("2006-01-02"), event.Level, event.Data) // formatter := func(event LogEvent) string {
// } // return fmt.Sprintf("[%s] %s: %v", event.Ts.Format("2006-01-02"), event.Level, event.Data)
// }
type LogFormatter = func(LogEvent) string type LogFormatter = func(LogEvent) string
const logTemplate = "[%s] %s : %s - %s\n"
// format is the default formatter that converts a LogEvent to a string using the default template. // format is the default formatter that converts a LogEvent to a string using the default template.
// It handles both simple values and formatted strings. // It handles both simple values and formatted strings.
// Template: "[timestamp] level : category - data" // Template: "[timestamp] level : category - data"

View File

@ -57,12 +57,14 @@ type LoggersConfig struct {
Appenders map[string]LogAppenderConfig `json:"appenders"` Appenders map[string]LogAppenderConfig `json:"appenders"`
Categories map[string]LogConfig `json:"categories"` Categories map[string]LogConfig `json:"categories"`
} }
// Logger represents a logger instance for a specific category. // Logger represents a logger instance for a specific category.
// It maintains the log level and appenders for that category. // It maintains the log level and appenders for that category.
// Example: // Example:
// logger := GetLogger("mycategory") //
// logger.Info("This is an info message") // logger := GetLogger("mycategory")
// logger.Error("This is an error message") // logger.Info("This is an info message")
// logger.Error("This is an error message")
type Logger struct { type Logger struct {
category string category string
level int level int
@ -203,4 +205,5 @@ func RegistAppender(typeName string, appenderCreatCb func(LogAppenderConfig) *Lo
func init() { func init() {
loggerMap["default"] = defaultLogger loggerMap["default"] = defaultLogger
appenders["console"] = &consoleAppender
} }