Logstash Python Configuration Example
Ship logs from Python applications to logstash
This guide has been setup and tested using Python 3.6-3.11 (64-bit) environments. Code samples included can be used inside a basic Python script, or web framework such as Django or Flask. To send logs to logstash through Python you will need the python-logstash-async (version 2.5.0) Python plugin.
Follow this step by step guide to get 'logs' from your system to Logit.io:
Step 1 - Installing
Execute the following command using pip:
pip install python-logstash-async
Step 2 - Sending Logs
Step 3 - Check Logit.io for your logs
Now you should view your data:
If you don't see logs take a look at How to diagnose no data in Stack below for how to diagnose common issues.
Step 4 - how to diagnose no data in Stack
If you don't see data appearing in your Stack after following the steps, visit the Help Centre guide for steps to diagnose no data appearing in your Stack or Chat to support now.
Step 5 - Python Centralise Logging Overview
Python’s logging module is used by most third-party libraries and allows you to integrate your log messages with application-specific logs.
The five standard levels of logs aggregated by the Python module include; CRITICAL, ERROR, WARNING, INFO, DEBUG.
- Critical logs let you know that the application is shutting down and can’t recover without a reboot.
- Error logs capture unexpected bugs that can be handled without a reboot, for example, a 503 or 404 error.
- Warnings can show that resources are running low or that suspicious web requests have been identified. Warning logs can be monitored to protect the security of your applications.
- Info is log data that is sent to your ELK Stack that has captured information on your application’s behaviour metrics.
The creation of a single Python script can produce thousands of logs which only increase once migrated to a production environment. Each logging level adds complexity to being able to efficiently report on the development process, as well as increasing the risk of breaking points across the module.
Using the Logit.io platform allows you to centralise all five types of Python logs for the streamlining of monitoring, troubleshooting and debugging in the cloud. Our onboarding has your ELK Stacks ready for analysis of Python logging events in minutes by using our highly available hosted Logstash pipeline for collecting log files.
Using Logit.io you can view all of the five log types for easy analysis with our out of the box Kibana dashboards. Set alerts on errors, warnings and mission-critical Python issues from one centralised dashboard. Logit.io integrates with Opsgenie, Slack, Webhooks and PagerDuty to send notification messages to your Dev teams.
If you need any further assistance with migrating your Python application logs to Logstash we're here to help you get started. Just get in contact with our support team by visiting our dedicated Help Centre or via live chat & we'll be happy to assist.