/* Copyright © 2026 Craig Williams This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ package log import ( "log/slog" "os" "github.com/lmittmann/tint" ) var logLevel slog.LevelVar // Set up the logger using defaults func Init() { logLevel.Set(slog.LevelWarn) opts := &slog.HandlerOptions{ Level: &logLevel, } handler := slog.NewTextHandler(os.Stdout, opts) logger := slog.New(handler) slog.SetDefault(logger) } // Enable info level logging func EnableInfo() { if logLevel.Level() > slog.LevelInfo { logLevel.Set(slog.LevelInfo) slog.Info("Info logging enabled") } } // Enable debug level logging func EnableDebug() { if logLevel.Level() > slog.LevelDebug { logLevel.Set(slog.LevelDebug) slog.Debug("Debug logging enabled") } } func LogToTerminal() { opts := &tint.Options{ Level: &logLevel, TimeFormat: "*", } handler := tint.NewTextHandler(os.Stdout, opts) logger := slog.New(handler) slog.SetDefault(logger) }