liveBook · Manning

Logging level

As explained in The Well-Grounded Python Developer: How the pros use Python and Flask

A logging level is a classification that indicates the severity or importance of a log message.

A logging level classifies message severity and controls which events an application emits. Unlike scattered print statements, levels let development capture detailed execution information while production suppresses debug noise without removing diagnostic code. section 7.8 section 12.2.3

Python logging orders levels from NOTSET through CRITICAL and uses the configured level as a filter:

  • DEBUG records detailed development information; setting the threshold to DEBUG admits DEBUG messages and more severe messages. section 7.8.1
  • INFO admits informational messages and higher-severity messages while ignoring DEBUG output, making it suitable for production configuration. section 7.8.1
  • The level can be applied to loggers and handlers, while formatters provide consistent, chronological output to destinations such as standard output. section 7.8 section 7.8.1

Development versus production

An application can leave logger.debug("rendering home page") and logger.debug("rendering about page") in its route code. Development sets logging_level to DEBUG to show these events; production sets it to INFO so the statements remain available for future diagnosis but stay out of normal logs. section 7.8.1 section 12.2.3

def _configure_logging(app, dynaconf):
    logging_config_path = Path(app.root_path).parent / "logging_config.yaml"
    with open(logging_config_path, "r") as fh:
        logging_config = yaml.safe_load(fh.read())
        env_logging_level = dynaconf.settings.get(
            "logging_level", "INFO"
        ).upper()
        logging_level = logging.INFO 
            if env_logging_level == "INFO" 
            else logging.DEBUG
        logging_config["handlers"]["console"]["level"] = logging_level
        logging_config["loggers"][""]["level"] = logging_level
        logging.config.dictConfig(logging_config)

Use the configuration listing to trace how an environment setting becomes a numeric logging threshold for the console handler and root logger. section 7.8.1

How The Well-Grounded Python Developer: How the pros use Python and Flask covers it

How deep it goes
Explains severity ordering, threshold filtering, logger and handler configuration, and YAML-driven environment selection.
Examples
Uses DEBUG route messages, INFO production output, YAML environment settings, and timestamped console log entries.
What it assumes
Assumes familiarity with Python application code and introduces logging as a structured alternative to print statements.
What you can do after
Operate/configure Python logging to preserve debug diagnostics while controlling production output through INFO and DEBUG thresholds.
How it connects
Connects logging levels with loggers, handlers, formatters, standard output, configuration dictionaries, YAML, and application environments.

Also explained in

Compare how 9 books explain logging level →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Python Developer: How the pros use Python and Flask. The section links point to the parts of the book it draws on.