package gologger import ( "fmt" ) const ( ErrorTemplate = "\033[1;31m%s\033[0m" WarnTemplate = "\033[1;33m%s\033[0m" InfoTemplate = "\033[1;32m%s\033[0m" DebugTemplate = "\033[1;34m%s\033[0m" TraceTemplate = "\033[1;35m%s\033[0m" ) type ConsoleAppender struct { } // Close implements LoggerAppender. func (c *ConsoleAppender) Close() { } func (c *ConsoleAppender) GetName() string { return "console" } func (c *ConsoleAppender) Append(logEvent LogEvent) { logMsg := format(logEvent) switch logEvent.Level { case Error: fmt.Printf(ErrorTemplate, logMsg) case Warn: fmt.Printf(WarnTemplate, logMsg) case Info: fmt.Printf(InfoTemplate, logMsg) case Debug: fmt.Printf(DebugTemplate, logMsg) case Trace: fmt.Printf(TraceTemplate, logMsg) } } func makeConsoleAppender(appenderConfig LogAppenderConfig) *LoggerAppender { var appender LoggerAppender = &ConsoleAppender{} return &appender } func init() { RegistAppender("console", makeConsoleAppender) }