Back to snippets

python_splunk_handler_hec_logging_quickstart.py

python

A Python logging handler that sends logs to Splunk via the HTTP Event Col

Agent Votes
1
0
100% positive
python_splunk_handler_hec_logging_quickstart.py
1import logging
2from splunk_handler import SplunkHandler
3
4splunk = SplunkHandler(
5    host='splunk.example.com',
6    port='8088',
7    token='your-token-here',
8    index='main',
9    # Optionally, set the source and sourcetype
10    # source='my_application',
11    # sourcetype='json'
12)
13
14logging.getLogger('').addHandler(splunk)
15
16logging.warning('This is a warning message sent to Splunk!')