Overview
Thelogger package provides structured logging functionality with colored console output and file logging. It supports both human-readable terminal output and JSON mode for programmatic integration with Tauri or other frontends.
Types
Logger
Main logger type that handles all logging operations.Underlying logrus logger instance
File handle for persistent log storage
JSON writer for structured output (when in JSON mode)
Whether logger is in JSON mode for programmatic output
Functions
NewLogger
Creates a new Logger instance with human-readable output.Path to log file (empty string disables file logging)
A new Logger instance
Returns an error if log file creation fails
Example
NewLoggerWithMode
Creates a new Logger instance with optional JSON mode.Path to log file (empty string disables file logging)
Enable JSON output for programmatic integration
A new Logger instance
Returns an error if log file creation fails
Example
Methods
Log
Logs a general informational message.Message to log
Example
[10:30:45] Starting conversion process
Info
Logs an informational message with an info icon.Informational message
Example
[i] Found 42 files to process
Success
Logs a success message with a checkmark icon.Success message
Example
[✓] Conversion completed successfully
Warn
Logs a warning message with a warning icon.Warning message
Example
[⚠] Skipping disk space check
Error
Logs an error message with error formatting.Error message
Example
[ERROR 10:30:45] Failed to convert photo.jpg: invalid format
Security
Logs a security-related message with bold red formatting.Security message
Example
[🔒 SECURITY] Deletion mode activated
ShowHeader
Displays the application header with deletion mode warning.Whether originals will be preserved
Example
Close
Closes the log file handle.Returns an error if file close fails
Example
GetJSONWriter
Returns the JSON writer instance (only available in JSON mode).JSON writer instance or nil if not in JSON mode
IsJSONMode
Checks if logger is in JSON mode.Returns true if in JSON mode
Output Modes
Human-Readable Mode (Default)
- Colored console output with icons
- Timestamps in
15:04:05format - Multi-writer outputs to both console and log file
- Pretty formatting with ANSI colors
JSON Mode
- Structured JSON output to stdout
- Plain text logging to file
- Emits JSON events for:
- Log messages (
logevent) - Progress updates (
progressevent) - Conversion started (
startedevent) - Conversion complete (
completeevent) - Statistics (
statisticsevent)
- Log messages (
JSON Event Example
Color Scheme
- Red: Errors and security warnings
- Green: Success messages
- Yellow: Warnings
- Blue: Timestamps
- Cyan: Informational messages
- Purple: Headers
File Logging
When a log path is provided:- All messages are written to the log file
- File format:
[LEVEL TIMESTAMP] message - Human-readable mode: Logs to both console and file
- JSON mode: Plain text logs to file, JSON to stdout
Log File Example
Best Practices
- Always close the logger: Use
defer log.Close()after creation - Use appropriate log levels: Info for status, Warn for issues, Error for failures
- Format messages clearly: Include context like file names, counts, errors
- Enable JSON mode for GUIs: When integrating with Tauri or other frontends