Where do you want to collect your logs from?
Collect logs from your Django application.
Install Better Stack Python PyPI package:
Set up Django Better Stack handler in settings.py:
Use Python logger as usual:
You should see your logs in Better Stack → Live tail.
Pip version 20.0.2 or higher is required.
Collect logs from your Python code.
Install Better Stack Python PyPI package:
Set up Python logger with Better Stack:
Use Python logger as usual:
You should see your logs in Better Stack → Live tail.
Pip version 20.0.2 or higher is required.
RQ runs each job in a forked process that exits without the usual Python shutdown, so logs written inside a job would never be sent. The Better Stack worker class sends them before the job process exits.
Configure the logtail handler as in the Django or Python setup above.
Start RQ with the Better Stack worker class:
With django-rq, set the worker class in settings.py instead:
Logs from the worker process itself are sent as usual.
Older versions do not include the worker class.
Please let us know at hello@betterstack.com.
We're happy to help! 🙏
Interested in learning more about Python log levels and using formatters to customize your logs? Check out our Comprehensive Guide to Logging in Python.
Make sure your application terminates gracefully, giving the logger enough time to finish the request to Better Stack.
Use sys.exit() to end your application.
Using os._exit() would terminate all threads immediately, potentially dropping your logs.
Errors while building a log record are dropped together with the record by default, so a misconfiguration can leave you with no logs and no error message. While debugging, set raise_exceptions to True to see the exception instead:
In Django, add 'raise_exceptions': True to the logtail handler in LOGGING.
Add custom data to multiple log lines using with block:
Use logger.exception() to log exceptions with traceback:
Pass these as keyword arguments to LogtailHandler, or as keys of the logtail handler in Django LOGGING:
| Option | Default | Description |
|---|---|---|
host |
EU region | Ingesting host of your source. |
timeout |
30 |
Seconds to wait for each request to Better Stack. |
buffer_capacity |
1000 |
Logs are sent in batches of up to this many records. |
flush_interval |
1 |
Seconds after which a batch is sent even if it is not full. |
drop_extra_events |
True |
Drop new logs while the buffer is full. Set to False to block the application instead. |
include_extra_attributes |
True |
Send every value passed in extra. Set to False to send only dictionaries. |
raise_exceptions |
False |
Raise errors while building a log record instead of dropping the record. |
Want to try a more detailed example?
See our Python example project on GitHub.
We use cookies to authenticate users, improve the product user experience, and for personalized ads. Learn more.