Skip to main content

A Python logging handler to sends logs to Splunk using HTTP event collector (HEC)

Project description

# Features
1. Log messages to Splunk via HTTP Event Collector (HEC). See [Splunk HEC Documentation](
2. All messages are logged as '_json' sourcetype by default.
3. A dictionary with 'log_level' and 'message' keys are constructed for logging records of type string.

![String log record representation in Splunk](

4. Dictionary objects are preserved as JSON.

![Dictionary log record representation in Splunk](

5. If log record (dict) does not contains a '_time' field, one is added with the value set to current time.

# Examples

## Basic
from splunk_http_handler import SplunkHecHandler
import logging

log = logging.getLogger('')
log.addHandler(SplunkHecHandler(host, token))
You should see the log message in your Splunk search.

## HTTPS Example
Additional parameters can be passed to specify port, protocol, ssl verification.

log.addHandler(SplunkHecHandler(host, token, port=8080, protocol='https', ssl_verify=True))

## Metadata Override
To override source, sourcetype and hostname:

host, token, port=8080, protocol='https', ssl_verify=True,
source='custom_source_string', sourcetype='valid_sourceytype', hostname='hostname_override'

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for splunk-hec-handler, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size splunk_hec_handler-1.0.1-py3-none-any.whl (4.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size splunk_hec_handler-1.0.1.tar.gz (3.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page