(new): prepare v2.1.0 release
Golang lint / lint (push) Successful in 24s

- add custom LogLevel constructors and richer color configuration
- support ANSI, 256-color, RGB, and text attributes on LogLevel
- introduce clearer preferred APIs such as NewLogger and SetName
- preserve backward compatibility with deprecated wrappers for v2.0.1 APIs
- restore legacy ColorStringBuilder signatures as compatibility wrappers
- fix newline separator handling in Println-style output
- add tests for color precedence, deprecated aliases, and LogLevel attributes
- update GoDoc and bilingual README documentation
This commit is contained in:
2026-04-27 15:42:24 +03:00
parent b4c9203a79
commit 3eac1851ec
11 changed files with 669 additions and 118 deletions
+23 -22
View File
@@ -7,85 +7,85 @@ import (
// Infof logs a formatted info message.
func (l *Logger) Infof(format string, args ...any) {
l.print(INFO, fmt.Sprintf(format, args...))
l.Print(INFO, fmt.Sprintf(format, args...))
}
// Info logs an info message.
func (l *Logger) Info(m ...any) {
l.print(INFO, m...)
l.Print(INFO, m...)
}
// Infoln logs an info message and appends a newline semantic for writers that need it.
func (l *Logger) Infoln(m ...any) {
l.println(INFO, m...)
l.Println(INFO, m...)
}
// Warnf logs a formatted warning message.
func (l *Logger) Warnf(format string, args ...any) {
l.print(WARN, fmt.Sprintf(format, args...))
l.Print(WARN, fmt.Sprintf(format, args...))
}
// Warn logs a warning message.
func (l *Logger) Warn(m ...any) {
l.print(WARN, m...)
l.Print(WARN, m...)
}
// Warnln logs a warning message with newline semantic.
func (l *Logger) Warnln(m ...any) {
l.println(WARN, m...)
l.Println(WARN, m...)
}
// Errorf logs a formatted error message.
func (l *Logger) Errorf(format string, args ...any) {
l.print(ERROR, fmt.Sprintf(format, args...))
l.Print(ERROR, fmt.Sprintf(format, args...))
}
// Error logs an error message.
func (l *Logger) Error(m ...any) {
l.print(ERROR, m...)
l.Print(ERROR, m...)
}
// Errorln logs an error message with newline semantic.
func (l *Logger) Errorln(m ...any) {
l.println(ERROR, m...)
l.Println(ERROR, m...)
}
// Fatalf logs a formatted fatal message and exits the process with code 1.
func (l *Logger) Fatalf(format string, args ...any) {
l.print(FATAL, fmt.Sprintf(format, args...))
l.Print(FATAL, fmt.Sprintf(format, args...))
os.Exit(1)
}
// Fatal logs a fatal message and exits the process with code 1.
func (l *Logger) Fatal(m ...any) {
l.print(FATAL, m...)
l.Print(FATAL, m...)
os.Exit(1)
}
// Fatalln logs a fatal message with newline semantic and exits the process with code 1.
func (l *Logger) Fatalln(m ...any) {
l.println(FATAL, m...)
l.Println(FATAL, m...)
os.Exit(1)
}
// Debugf logs a formatted debug message.
func (l *Logger) Debugf(format string, args ...any) {
l.print(DEBUG, fmt.Sprintf(format, args...))
l.Print(DEBUG, fmt.Sprintf(format, args...))
}
// Debug logs a debug message.
func (l *Logger) Debug(m ...any) {
l.print(DEBUG, m...)
l.Print(DEBUG, m...)
}
// Debugln logs a debug message with newline semantic.
func (l *Logger) Debugln(m ...any) {
l.println(DEBUG, m...)
l.Println(DEBUG, m...)
}
// Write message without trailing "\n"
// Print write message without trailing "\n"
// Good for database
func (l *Logger) print(level LogLevel, m ...any) {
func (l *Logger) Print(level LogLevel, m ...any) {
if l.level.n < level.n {
return
}
@@ -93,7 +93,7 @@ func (l *Logger) print(level LogLevel, m ...any) {
return
}
tb := getFullTraceback(0)
tb := getFullTraceback(1)
for _, writer := range l.writers {
if writer == nil {
continue
@@ -105,9 +105,10 @@ func (l *Logger) print(level LogLevel, m ...any) {
}
}
// Println
// Docker requires "\n" at end to write to log.
// print not work for docker, otherwise it will work and write into stdout
func (l *Logger) println(level LogLevel, m ...any) {
func (l *Logger) Println(level LogLevel, m ...any) {
if l.level.n < level.n {
return
}
@@ -115,13 +116,13 @@ func (l *Logger) println(level LogLevel, m ...any) {
return
}
tb := getFullTraceback(0)
messages := append(append(make([]any, 0, len(m)+1), m...), "\n")
tb := getFullTraceback(1)
messages := append(append(make([]any, 0, len(m)+1), l.replaceAll(m...)...), "\n")
for _, writer := range l.writers {
if writer == nil {
continue
}
err := writer.Print(level, l.prefix, tb, l.replaceAll(messages...)...)
err := writer.Print(level, l.prefix, tb, messages...)
if err != nil {
l.reportWriterError(err)
}