Compare commits

...

5 Commits

4 changed files with 14 additions and 8 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 { // formatter := func(event LogEvent) string {
// return fmt.Sprintf("[%s] %s: %v", event.Ts.Format("2006-01-02"), event.Level, event.Data) // 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"

2
go.mod
View File

@ -1,3 +1,3 @@
module git.pyer.club/kingecg/gologger module git.kingecg.top/kingecg/gologger
go 1.19 go 1.19

View File

@ -57,9 +57,11 @@ 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 := GetLogger("mycategory")
// logger.Info("This is an info message") // logger.Info("This is an info message")
// logger.Error("This is an error message") // logger.Error("This is an error message")
@ -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
} }

View File

@ -1,7 +1,7 @@
package main package main
import ( import (
logger "git.pyer.club/kingecg/gologger" logger "git.kingecg.top/kingecg/gologger"
) )
func aqmain() { func aqmain() {