Skip to content

Instantly share code, notes, and snippets.

@tusharkumawat
Last active January 19, 2022 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tusharkumawat/2403ad922bcb598f2c86a62e07968f80 to your computer and use it in GitHub Desktop.
Save tusharkumawat/2403ad922bcb598f2c86a62e07968f80 to your computer and use it in GitHub Desktop.
How to dump loggers from python script to splunk
import logging
from splunk_handler import SplunkHandler
splunk = SplunkHandler(
host='xxx.splunkcloud.com',
port='8088',
token='xx-xx-xx-xx-xx',
index='main'
#allow_overrides=True # whether to look for _<param in log data (ex: _index)
#debug=True # whether to print module activity to stdout, defaults to False
#flush_interval=15.0, # send batch of logs every n sec, defaults to 15.0, set '0' to block thread & send immediately
#force_keep_ahead=True # sleep instead of dropping logs when queue fills
#hostname='hostname', # manually set a hostname parameter, defaults to socket.gethostname()
#protocol='http', # set the protocol which will be used to connect to the splunk host
#proxies={
# 'http': 'http://10.10.1.10:3128',
# 'https': 'http://10.10.1.10:1080',
# }, set the proxies for the session request to splunk host
#
#queue_size=5000, # a throttle to prevent resource overconsumption, defaults to 5000, set to 0 for no max
#record_format=True, whether the log format will be json
#retry_backoff=1, the requests lib backoff factor, default options will retry for 1 min, defaults to 2.0
#retry_count=5, number of retry attempts on a failed/erroring connection, defaults to 5
#source='source', # manually set a source, defaults to the log record.pathname
#sourcetype='sourcetype', # manually set a sourcetype, defaults to 'text'
#verify=True, # turn SSL verification on or off, defaults to True
#timeout=60, # timeout for waiting on a 200 OK from Splunk server, defaults to 60s
)
logging.getLogger('').addHandler(splunk)
logging.warning('hello!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment