Skip to main content
coding intermediate

Write a Comprehensive Logging Configuration

Generate professional logging configurations for any programming language. Debug faster with proper log levels, formatting, and best practices.

Works with: chatgptclaudegemini

Prompt Template

You are an expert software engineer specializing in logging best practices. Create a comprehensive logging configuration for a [PROGRAMMING_LANGUAGE] application with the following requirements: **Application Context:** - Application type: [APPLICATION_TYPE] - Environment: [ENVIRONMENT] - Expected log volume: [LOG_VOLUME] - Key components to log: [COMPONENTS_TO_LOG] **Requirements:** 1. Configure appropriate log levels (DEBUG, INFO, WARN, ERROR, FATAL) 2. Set up different output destinations (console, file, external services) 3. Include proper log formatting with timestamps, log levels, and contextual information 4. Implement log rotation and retention policies 5. Add performance considerations and async logging if needed 6. Include environment-specific configurations 7. Set up structured logging where appropriate 8. Add error handling for logging failures **Additional Specifications:** - Framework/Library preference: [LOGGING_FRAMEWORK] - Special requirements: [SPECIAL_REQUIREMENTS] Provide: 1. Complete configuration file(s) with detailed comments 2. Code examples showing how to use the logger in the application 3. Best practices explanation for the chosen configuration 4. Performance and security considerations 5. Troubleshooting tips for common logging issues Make the configuration production-ready and follow industry standards for the specified technology stack.

Variables to Customize

[PROGRAMMING_LANGUAGE]

The programming language for the application

Example: Python

[APPLICATION_TYPE]

Type of application being developed

Example: REST API microservice

[ENVIRONMENT]

Target deployment environment

Example: production

[LOG_VOLUME]

Expected volume of log messages

Example: high - 10,000+ requests per minute

[COMPONENTS_TO_LOG]

Specific application components that need logging

Example: database queries, API requests, authentication, business logic errors

[LOGGING_FRAMEWORK]

Preferred logging framework or library

Example: Python logging with structlog

[SPECIAL_REQUIREMENTS]

Any special logging requirements or constraints

Example: GDPR compliance, ELK stack integration, real-time monitoring

Example Output

# Python Logging Configuration for REST API Microservice ```python import logging import logging.config from pythonjsonlogger import jsonlogger LOGGING_CONFIG = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'standard': { 'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s' }, 'json': { '()': jsonlogger.JsonFormatter, 'format': '%(asctime)s %(name)s %(levelname)s %(message)s' } }, 'handlers': { 'console': { 'level': 'INFO', 'class': 'logging.StreamHandler', 'formatter': 'json' }, 'file': { 'level': 'DEBUG', 'class': 'logging.handlers.RotatingFileHandler', 'filename': '/var/log/app/application.log', 'maxBytes': 10485760, # 10MB 'backupCount': 5, 'formatter': 'json' } }, 'loggers': { 'api': { 'handlers': ['console', 'file'], 'level': 'DEBUG', 'propagate': False }, 'database': { 'handlers': ['file'], 'level': 'INFO', 'propagate': False } } } logging.config.dictConfig(LOGGING_CONFIG) ``` **Usage Example:** ```python logger = logging.getLogger('api') logger.info('API request received', extra={'user_id': 123, 'endpoint': '/users'}) ```

Pro Tips for Best Results

  • Always use structured logging (JSON) in production environments for easier parsing and analysis
  • Set different log levels for different environments - DEBUG for development, INFO+ for production
  • Include contextual information like user IDs, request IDs, and timestamps in your log messages
  • Implement log rotation to prevent disk space issues and set appropriate retention policies
  • Test your logging configuration thoroughly, including error scenarios and high-load situations

Tags

Want 500+ Expert Prompts?

Get the Premium Prompt Pack — organized, tested, and ready to use.

Get it for $29

Related Prompts You Might Like