Configurable CLI logger with gradient text, truecolor ANSI styling, and optional file logging to logs/.
Go port of @turkwr/logger — same API shape, same defaults, zero third-party dependencies.
go get github.com/turkwr/go-loggerpackage main
import (
"errors"
"github.com/turkwr/go-logger"
)
func main() {
log := logger.New(&logger.Config{
Colors: logger.Colors{
Success: "#7fd889",
Accent: "#a879ff",
},
Gradient: logger.Gradient{From: "#a879ff", To: "#ffffff"},
File: logger.FileConfig{
Enabled: true,
Dir: "logs",
Prefix: "app",
MinLevel: logger.LevelInfo,
},
Console: logger.ConsoleConfig{MinLevel: logger.LevelDebug},
})
log.Banner(&logger.BannerOptions{Tag: "prod", Meta: "12 servers"})
log.Info("started")
log.Success("connected")
log.Warn("slow response")
log.Error("failed", errors.New("details"))
log.Event("incoming event")
log.Fatal("critical", errors.New("boom"))
}CreateLogger is an alias for New (matches the TypeScript createLogger).
| Method | Description |
|---|---|
Debug |
Dim dot, stdout |
Info |
Dim dot, stdout |
Success |
Green check, stdout |
Warn |
Yellow bang; stderr if error passed |
Error |
Red cross, stderr |
Event |
Accent arrow, stdout |
Fatal |
Red cross, stderr (does not exit) |
Banner |
Gradient title + optional tag/meta |
Pass an optional second argument to append a formatted error:
log.Error("failed", err)
log.Warn("slow", timeoutErr)When File.Enabled is true, logs are appended to:
logs/{prefix}-YYYY-MM-DD.log
Example line:
[2026-05-16T14:32:01.123Z] [INFO] started
The logs/ directory is created automatically. File output has no ANSI colors.
type Config struct {
Colors Colors
Gradient Gradient
Banner BannerConfig
Console ConsoleConfig
File FileConfig
}
type ConsoleConfig struct {
Enabled *bool // nil → true (default). Use logger.Bool(false) to disable.
MinLevel Level
}
type FileConfig struct {
Enabled bool
Dir string
Prefix string
MinLevel Level
}Log levels (lowest → highest): debug → info → success → event → warn → error → fatal.
| Key | Default |
|---|---|
| dim | #5f5f6a |
| soft | #e8e8ea |
| accent | #a879ff |
| success | #7fd889 |
| warn | #f4b560 |
| error | #ef6a6a |
| count | #d4c2ff |
import "github.com/turkwr/go-logger"
logger.PaintGradient(text, from, to)
logger.FormatError(err)
logger.CreateTheme(colors)
logger.MergeConfig(cfg)
logger.ShouldLog(level, minLevel)go run ./demoMIT