LoggerStructured Logging
Source Tracking
The logger can include source file and line information in log entries.
Source tracking is enabled with the AddSource configuration option and is useful during development, debugging, and
troubleshooting production issues where the exact log origin matters.
Example configuration:
package main
import (
"log/slog"
"github.com/netlifeguru/logger"
)
func main() {
closer, err := logger.Init(logger.Config{
TerminalOutput: true,
AddSource: true,
})
if err != nil {
slog.Error(err.Error())
}
defer closer.Close()
slog.Info("source tracking enabled")
}Example file output:
{
"time": "2026-05-11T12:53:20.834553+02:00",
"level": "INFO",
"source": {
"function": "main.main",
"file": "/examples/test/main.go",
"line": 20
},
"msg": "source tracking enabled"
}Source tracking helps with:
- locating where a log entry was created
- debugging complex application flows
- tracing errors back to specific files
- improving development visibility
Because source tracking requires runtime caller information, it may add a small amount of overhead and is usually enabled selectively when needed.