go-tlog is a lightweight and configurable logging library for Go applications.
It provides structured logging with multiple output destinations, flexible formatting,
and fine-grained log-level control.
- Simple setup via configuration struct
- Text or JSON output formats
- Multiple output targets: stdout, stderr, files
- Log levels:
Trace,Debug,Info,Warn,Error - Automatic timestamp, source file, and line number
- Stacktrace for errors
go get github.com/tarantool/go-tlog@latestThen import:
import "github.com/tarantool/go-tlog"package main
import "github.com/tarantool/go-tlog"
func main() {
log, err := tlog.New(tlog.Opts{
Level: tlog.LevelInfo,
Format: tlog.FormatText,
Path: "stdout",
})
if err != nil {
panic(err)
}
defer log.Close()
logger := log.Logger().With(tlog.String("component", "demo"))
logger.Info("service started", "port", 8080)
logger.Error("failed to connect", "err", "timeout")
}Output:
2025-11-10T13:30:01+05:00 INFO service started component=demo port=8080
2025-11-10T13:30:01+05:00 ERROR failed to connect err=timeout component=demo stacktrace="..."
type Opts struct {
Level Level // minimal log level
Format Format // FormatText or FormatJSON
Path string // comma-separated outputs: "stdout,/var/log/app.log"
}| Function | Description |
|---|---|
tlog.New(opts) |
Create a new logger |
Logger() |
Return the underlying logger for use |
Close() |
Flush buffers and close file descriptors |
| Level | When to use |
|---|---|
Trace |
Low-level tracing |
Debug |
Debugging information |
Info |
Normal operational messages |
Warn |
Non-fatal warnings |
Error |
Errors and exceptions (includes stacktrace) |
| Format | Example |
|---|---|
FormatText |
2025-11-10T13:31:45+05:00 INFO message key=value |
FormatJSON |
{"time":"...","level":"INFO","msg":"message","key":"value"} |
You can specify multiple targets separated by commas:
Path: "stdout,/tmp/app.log"Supported targets:
stdoutstderr- File paths (created automatically if not present)
Included examples:
- ExampleNew_text — basic text logger writing to stdout
- ExampleNew_json — JSON logging
- ExampleNew_multi — logging to multiple destinations (
stdout,/tmp/...)
Each example demonstrates different combinations of Path, Format, and Level, including how to log to multiple outputs at the same time.
make testBSD 2-Clause License — see LICENSE