myspellchecker namespace. Call configure_logging() once at application startup to control log level, output format (human-readable or JSON), and destination.
Overview
The logging system provides:- Centralized configuration for all myspellchecker modules
- Consistent logger naming under the
myspellcheckernamespace - Support for development (verbose) and production (JSON) modes
- Thread-safe logger caching
- Easy integration via
get_logger()
Basic Configuration
Configure logging once at the start of your application:Configuration Options
configure_logging supports several parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
level | str/int | INFO | Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
json_output | bool | False | Output as JSON for log aggregators |
debug_mode | bool | False | Verbose format with timestamps and line numbers |
format_string | str | None | Custom format string (overrides other format options) |
stream | TextIO | stderr | Output stream |
Format Strings
The logging system uses different formats based on configuration:Examples
Development Mode:Using Loggers in Your Code
If you are extending mySpellChecker or writing custom components, use the logging utility:Logger Naming
get_logger() ensures consistent naming under the myspellchecker namespace:
Logger Caching
Loggers are cached for efficiency (LRU cache with 256 entries):Setting Log Levels
Use Python’s standard logging to set levels per module:Advanced Configuration
Get the root logger for custom handlers and filters:Integration with Standard Logging
The logging utilities are compatible with Python’s standard logging:CLI Logging
The CLI automatically configures logging:Best Practices
- Configure once: Call
configure_logging()once at application startup - Use get_logger: Always use
get_logger(__name__)for consistent naming - Log levels: Use appropriate levels (DEBUG for development, INFO+ for production)
- Structured logging: Use JSON output in production for log aggregators
- Don’t log sensitive data: Be careful with user input in log messages
Troubleshooting
Duplicate Logs
If you see duplicate logs, ensure:configure_logging()is called only once- You’re not adding handlers manually without removing existing ones
No Output
If logs aren’t appearing:- Check the log level
- Verify
configure_logging()was called - Check the output stream
See Also
- Configuration Guide - General configuration
- Performance Tuning - Optimization guide