DocumentationAPI Reference📓 Tutorials🧑‍🍳 Cookbook🤝 Integrations💜 Discord🎨 Studio
Documentation

Logging

Logging is crucial for monitoring and debugging LLM applications during development as well as in production. Haystack provides different logging solutions out of the box to get you started quickly, depending on your use case.

Standard Library Logging (default)

Haystack logs through Python’s standard library. This gives you full flexibility and customizability to adjust the log format according to your needs.

Changing the Log Level

By default, Haystack's logging level is set to WARNING. To display more information, you can change it to INFO. This way, not only warnings but also information messages are displayed in the console output.

To change the logging level to INFO, run:

import logging

logging.basicConfig(format="%(levelname)s - %(name)s -  %(message)s", level=logging.WARNING)
logging.getLogger("haystack").setLevel(logging.INFO)

Further Configuration

See Python’s documentation on logging for more advanced configuration.

Structured Logging

Haystack leverages the structlog library to provide structured key-value logs. This provides additional metadata with each log message and is especially useful if you archive your logs with tools like ELK, Grafana, or Datadog.

If Haystack detects a structlog installation on your system, it will automatically switch to structlog for logging.

Console Rendering

To make development a more pleasurable experience, Haystack uses structlog’s ConsoleRender by default to render structured logs as a nicely aligned and colorful output:

👍

Rich Formatting

Install rich to beautify your logs even more!

JSON Rendering

We recommend JSON logging when deploying Haystack to production. Haystack will automatically switch to JSON format if it detects no interactive terminal session. If you want to enforce JSON logging:

  • Run Haystack with the environment variable HAYSTACK_LOGGING_USE_JSON set to true.

  • Or, use Python to tell Haystack to log as JSON:

    import haystack.logging
    
    haystack.logging.configure_logging(use_json=True)
    

Disabling Structured Logging

To disable structured logging despite an existing installation of structlog, set the environment variable HAYSTACK_LOGGING_IGNORE_STRUCTLOG_ENV_VAR to true when running Haystack.