pluginctl/logger.go
Felipe Martin 73149001eb
Replace logging system with slog and tint for structured colored output
- Add logger.go with public Logger variable and InitLogger function
- Replace all fmt.Printf/fmt.Fprintf calls with structured Logger.Info/Logger.Error
- Initialize logger in main function for consistent access across packages
- Keep fmt.Errorf for proper error creation (standard Go practice)
- Add tint dependency for colorized terminal output with timestamps
- Convert user output to structured logging with key-value pairs
- Update info command to use structured logging for plugin details
- Update updateassets command to use structured progress logging
- Update version command to use structured logging
- Update authentication logging in client.go with structured fields
- Update enable/disable commands to use structured logging
- Remove unused fmt imports after conversion

All output now uses slog with tint for beautiful, structured, colorized logging
while maintaining proper error handling with fmt.Errorf for error creation.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-09 16:51:40 +02:00

37 lines
No EOL
715 B
Go

package pluginctl
import (
"log/slog"
"os"
"time"
"github.com/lmittmann/tint"
)
// Logger is the global logger instance
var Logger *slog.Logger
// InitLogger initializes the global logger
func InitLogger() {
// Create a tint handler for colorized output
handler := tint.NewHandler(os.Stderr, &tint.Options{
Level: slog.LevelInfo,
TimeFormat: time.Kitchen,
AddSource: false,
NoColor: false,
})
Logger = slog.New(handler)
}
// SetLogLevel sets the minimum logging level
func SetLogLevel(level slog.Level) {
handler := tint.NewHandler(os.Stderr, &tint.Options{
Level: level,
TimeFormat: time.Kitchen,
AddSource: false,
NoColor: false,
})
Logger = slog.New(handler)
}