These docs are a work-in-progress and are currently undergoing a major rewrite!

Logging

A common, but sometimes confusing need in Django is logging.

It's easy to fall back to print() statements, but proper logging gives you log levels that can be enabled/disabled per environment. So you can leave debug statements in your code for development, and not clutter your production logs.

To make logging easier, Forge comes with default LOGGING settings which includes an app logger. You can use the app logger with an import, and everything you need will work:

from forge.logging import app_logger

def my_function():
    app_logger.info("Logging this in development and production")
    # ...
    app_logger.debug("This is only logged in development")

In Heroku, you'll see "info" (and "warning", "error", or "critical") log messages by default.

In development, you'll also see the "debug" messages.

You can configure either environment differently via the APP_LOG_LEVEL environment variable:

heroku config:set APP_LOG_LEVEL=DEBUG

You can also configure the log level for Django itself by using DJANGO_LOG_LEVEL:

heroku config:set DJANGO_LOG_LEVEL=DEBUG