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>
This commit is contained in:
Felipe M 2025-07-09 16:51:40 +02:00
parent b43e7ac3ec
commit 73149001eb
No known key found for this signature in database
GPG key ID: 52E5D65FCF99808A
11 changed files with 80 additions and 46 deletions

View file

@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"log"
"net"
"os"
"time"
@ -22,14 +21,13 @@ func getClient(ctx context.Context) (*model.Client4, error) {
client, connected := getUnixClient(socketPath)
if connected {
log.Printf("Connecting using local mode over %s", socketPath)
Logger.Info("Connecting using local mode", "socket_path", socketPath)
return client, nil
}
if os.Getenv("MM_LOCALSOCKETPATH") != "" {
log.Printf("No socket found at %s for local mode deployment. "+
"Attempting to authenticate with credentials.", socketPath)
Logger.Info("No socket found for local mode deployment. Attempting to authenticate with credentials.", "socket_path", socketPath)
}
siteURL := os.Getenv("MM_SERVICESETTINGS_SITEURL")
@ -44,7 +42,7 @@ func getClient(ctx context.Context) (*model.Client4, error) {
client = model.NewAPIv4Client(siteURL)
if adminToken != "" {
log.Printf("Authenticating using token against %s.", siteURL)
Logger.Info("Authenticating using token", "site_url", siteURL)
client.SetToken(adminToken)
return client, nil
@ -52,7 +50,7 @@ func getClient(ctx context.Context) (*model.Client4, error) {
if adminUsername != "" && adminPassword != "" {
client := model.NewAPIv4Client(siteURL)
log.Printf("Authenticating as %s against %s.", adminUsername, siteURL)
Logger.Info("Authenticating with credentials", "username", adminUsername, "site_url", siteURL)
_, _, err := client.Login(ctx, adminUsername, adminPassword)
if err != nil {
return nil, fmt.Errorf("failed to login as %s: %w", adminUsername, err)