Graylog: Sending error logs
This documentation is part of the Using with Python guide. View the full guide here: How to send logs from Python to Graylog.
👋 Welcome to the Stackhero documentation!
Stackhero offers a ready-to-use Graylog cloud solution that provides a host of benefits, including:
- Unlimited and dedicated SMTP email server included.
- Effortless updates with just a click.
- Customizable domain name secured with HTTPS (for example, https://logs.your-company.com).
- Optimal performance and robust security powered by a private and dedicated VM.
Save time and simplify your life: it only takes 5 minutes to try Stackhero's Graylog cloud hosting solution!
Graylog is not just for regular log messages. You can also catch and forward errors for better visibility into your application's behavior. This makes it easier to monitor and receive notifications for issues via email, Slack, or Mattermost.
Here is an example where we intentionally call a function that does not exist to generate an error. Remember to substitute "<XXXXXX>.stackhero-network.com" with your actual instance hostname.
import logging
import graypy
my_logger = logging.getLogger('test_logger')
my_logger.setLevel(logging.DEBUG)
handler = graypy.GELFTLSHandler('<XXXXXX>.stackhero-network.com', 12201)
my_logger.addHandler(handler)
try:
unknown_function()
except NameError:
my_logger.debug('The "unknown_function" raised an error', exc_info=1)
You can run this script just like before. In your Graylog admin panel, you will see the error message "NameError: name 'unknown_function' is not defined" along with the full stack trace.
Error log example