Stalkeer uses a modularized logging system that allows independent control of application and database logging. This provides better visibility and tuning capabilities for production deployments.
Configure application and database log levels and output format independently:
logging:
format: json # json or text (default: json)
app:
level: info # debug, info, warn, error
database:
level: warn # debug, info, warn, errorStalkeer supports two output formats:
-
json: Structured JSON logs (recommended for production)
{"timestamp":"2026-02-01T10:30:45.123456Z","level":"INFO","message":"Processing started","context":{"file":"playlist.m3u","items":100}} -
text: Human-readable text logs (useful for development)
2026-02-01T10:30:45.123456Z [INFO] Processing started file=playlist.m3u items=100
The format configuration is global and applies to both application and database logging.
The legacy single log level configuration is still supported but will show a deprecation warning:
logging:
level: info # debug, info, warn, error
format: jsonLog levels are resolved in the following priority order:
- Specific component level (
logging.app.levelorlogging.database.level) - Legacy level (
logging.level) - Default (
info)
- debug: Detailed diagnostic information for development
- info: General informational messages about application flow
- warn: Warning messages about potential issues
- error: Error messages for failures and exceptions
Database logging uses GORM's logger with the following mapping:
- debug → Shows all SQL queries with execution time
- info → Shows slow queries (>200ms) and errors
- warn → Shows slow queries and errors
- error → Shows only database errors
Use the AppLogger() function to get the application logger:
import "github.com/glefebvre/stalkeer/internal/logger"
func MyFunction() {
log := logger.AppLogger()
log.Info("Processing started")
if err := doSomething(); err != nil {
log.Error("Failed to do something", err)
}
}Loggers are automatically initialized when the application starts. The main application initializes loggers with the configured format after loading configuration:
cfg := config.Get()
logger.InitializeLoggersWithFormat(cfg.GetAppLogLevel(), cfg.GetDatabaseLogLevel(), cfg.Logging.Format)For backward compatibility, you can also initialize without format (defaults to JSON):
logger.InitializeLoggers(cfg.GetAppLogLevel(), cfg.GetDatabaseLogLevel())For testing, you can set custom loggers:
import "github.com/glefebvre/stalkeer/internal/logger"
func TestMyFunction(t *testing.T) {
// Create a test logger
testLogger := logger.NewWithLevel("debug")
logger.SetAppLogger(testLogger)
// Your test code here
// Cleanup
logger.SetAppLogger(nil)
}Minimize logs while capturing important events:
logging:
format: json
app:
level: info
database:
level: errorEnable detailed logging for debugging:
logging:
format: json
app:
level: debug
database:
level: debugFocus on database query performance:
logging:
format: json
app:
level: warn
database:
level: debug # Shows all SQL queriesMinimize noise while debugging application errors:
logging:
format: json
app:
level: debug
database:
level: warn # Only slow queries and errorsIf you're currently using:
logging:
level: info
format: jsonMigrate to:
logging:
format: json
app:
level: info
database:
level: warn # or whatever level suits your needs- Independent Control: Tune application and database logging separately
- Better Performance: Reduce database log overhead in production
- Improved Debugging: Enable verbose database logs without flooding application logs
- Future-Proof: New logging features will build on modular configuration
You can override configuration via environment variables:
# Legacy
export STALKEER_LOGGING_LEVEL=debug
# Modular (recommended)
export STALKEER_LOGGING_APP_LEVEL=debug
export STALKEER_LOGGING_DATABASE_LEVEL=warnThe system uses singleton logger instances for efficiency:
AppLogger()returns the application loggerDatabaseLogger()returns the database logger
These are thread-safe and lazily initialized.
Database logging is integrated with GORM using a custom adapter (logger.GormAdapter) that:
- Maps application log levels to GORM log levels
- Formats SQL queries for readability
- Tracks slow query threshold (200ms)
- Handles query execution time logging
If you see:
Using deprecated 'logging.level' configuration. Please migrate to 'logging.app.level' and 'logging.database.level' for better control.
Update your config.yml to use the modular configuration format.
If database logs are flooding your output, increase the database log level:
logging:
database:
level: error # Only show errorsEnsure the app log level is appropriate:
logging:
app:
level: debug # Show all logs- Check that loggers are initialized after config loading
- Verify log level configuration
- Ensure you're using
logger.AppLogger()notlogger.Default()
Potential future improvements to the logging system:
- Per-package log level configuration
- Dynamic log level changes via API
- Log output to separate files
- Structured logging fields standardization
- Log sampling and rate limiting