Files
rustdesk-api/lib/logger/logger.go
T
thomasandClaude Opus 4.8 16e97c8efa i18n: Translate all Chinese to English across the codebase
Translate Chinese comments, log/error messages, validator labels and
Swagger annotations to English throughout the source code, generated
Swagger docs, config files and CI workflows.

Make the English README primary: README.md now holds the English docs
and README_EN.md holds the Chinese version, with cross-language links
updated accordingly.

Note: the generated docs/ swagger files were translated in place; run
`go generate ./...` (swag init) to regenerate them from the now-English
annotations when a Go toolchain is available.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-27 12:17:04 +02:00

55 lines
989 B
Go

package logger
import (
nested "github.com/antonfisher/nested-logrus-formatter"
log "github.com/sirupsen/logrus"
"io"
"os"
)
const (
DebugMode = "debug"
ReleaseMode = "release"
)
type Config struct {
Path string
Level string
ReportCaller bool
}
func New(c *Config) *log.Logger {
log.SetFormatter(&nested.Formatter{
// HideKeys: true,
TimestampFormat: "[2006-01-02 15:04:05]",
NoColors: true,
NoFieldsColors: true,
//FieldsOrder: []string{"name", "age"},
})
// log file
f := c.Path
var write io.Writer
if f != "" {
fwriter, err := os.OpenFile(f, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
panic("open log file fail!")
}
write = io.MultiWriter(fwriter, os.Stdout)
} else {
write = os.Stdout
}
log.SetOutput(write)
log.SetReportCaller(c.ReportCaller)
level, err2 := log.ParseLevel(c.Level)
if err2 != nil {
level = log.DebugLevel
}
log.SetLevel(level)
return log.StandardLogger()
}