Skip to main content
All mySpellChecker modules log under the 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 myspellchecker namespace
  • 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:

Format Strings

The logging system uses different formats based on configuration:

Examples

Development Mode:
Production Mode:
Simple Build Output:

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

  1. Configure once: Call configure_logging() once at application startup
  2. Use get_logger: Always use get_logger(__name__) for consistent naming
  3. Log levels: Use appropriate levels (DEBUG for development, INFO+ for production)
  4. Structured logging: Use JSON output in production for log aggregators
  5. Don’t log sensitive data: Be careful with user input in log messages

Troubleshooting

Duplicate Logs

If you see duplicate logs, ensure:
  1. configure_logging() is called only once
  2. You’re not adding handlers manually without removing existing ones

No Output

If logs aren’t appearing:
  1. Check the log level
  2. Verify configure_logging() was called
  3. Check the output stream

See Also