Back to all reviewers

Follow logging best practices

vllm-project/vllm
Based on 7 comments
Python

Maintain high-quality logging throughout the codebase by following these best practices: 1. **Use appropriate log levels**: Reserve `debug` for detailed troubleshooting, `info` for general operational information, `warning` for potential issues, and `error`/`critical` for actual problems. Avoid excessive logging at higher levels.

Logging Python

Reviewer Prompt

Maintain high-quality logging throughout the codebase by following these best practices:

  1. Use appropriate log levels: Reserve debug for detailed troubleshooting, info for general operational information, warning for potential issues, and error/critical for actual problems. Avoid excessive logging at higher levels.
    # For large object dumps or detailed diagnostics
    logger.debug("Initialized config %s", config)
    # Not: logger.info("Initialized config %s", config)
    
  2. Remove temporary debugging logs: Debug statements with developer identifiers (e.g., "[Kourosh]") should be removed before merging code.

  3. Optimize logging performance: Guard expensive parameter computations to avoid unnecessary work when the log level is disabled:
    if logger.isEnabledFor(logging.DEBUG):
        logger.debug("Complex calculation result: %s", 
                     ",".join(map(str, complex_calculation())))
    
  4. Avoid logging in loops unless each iteration provides unique valuable information. Consider logging summaries before/after the loop instead.

  5. Use standard logging methods: Use logger.warning() (not the deprecated logger.warn()), and use logger.exception() for exception logging to automatically include tracebacks:
    try:
        # Some operation
    except Exception:
        logger.exception("Failed to perform operation")
        # Not: logger.error("Failed: %s", str(e))
    
  6. Initialize loggers consistently: Use the project’s standard logger initialization pattern:
    from vllm.logger import init_logger
    logger = init_logger(__name__)
    
  7. Make log messages clear and actionable: Include relevant context and avoid ambiguous messages.
7
Comments Analyzed
Python
Primary Language
Logging
Category

Source Discussions