Skip to main content

A simple Splunk HEC logger.

Project description

Splunk Logger

A simple Python package for sending logs to Splunk using the HTTP Event Collector (HEC).

Installation

pip install splunk-hec-logger # (or from your local wheel file)

Configuration

The SplunkLogger class retrieves its configuration from environment variables. These are required:

  • SPLUNK_HEC_URL: The URL of your Splunk HEC endpoint (e.g., https://your-splunk-instance:8088/services/collector).
  • SPLUNK_HEC_TOKEN: Your Splunk HEC token.

These are optional:

  • SPLUNK_HOST: The host field for your Splunk events (defaults to the local hostname).
  • SPLUNK_SOURCE: The source field for your Splunk events (defaults to "RPA").
  • SPLUNK_SOURCETYPE: The sourcetype field for your Splunk events (defaults to "_json").
  • SPLUNK_INDEX: The index for your Splunk events (defaults to "rdb").

Usage

import os
from splunk_logger import SplunkLogger

# Set environment variables (for demonstration; normally set outside the script)
os.environ["SPLUNK_HEC_URL"] = "YOUR_SPLUNK_HEC_URL"
os.environ["SPLUNK_HEC_TOKEN"] = "YOUR_SPLUNK_HEC_TOKEN"
os.environ["SPLUNK_HOST"] = "my-application-host"
os.environ["SPLUNK_SOURCE"] = "my-app"
os.environ["SPLUNK_SOURCETYPE"] = "_json"
os.environ["SPLUNK_INDEX"] = "my_index"

logger = SplunkLogger()

logger.info("This is an informational message.", Module="my_module", TaskId="123")
logger.warning("A potential issue occurred.", Module="my_module", StatusCode=404)
logger.error("An error occurred.", Module="my_module", ErrorCode=500, Exception="ValueError")
logger.debug("A potential error.", Module="my_module", StatusCode=200)

# You can also log events with a custom level or provide a complete event dictionary
logger.log_event({
    "Level": "DEBUG",
    "Message": "Detailed debug information.",
    "Component": "Database",
    "Query": "SELECT * FROM users"
})

Project details


Download files

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

Source Distribution

splunk_hec_logger-0.1.5.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

splunk_hec_logger-0.1.5-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file splunk_hec_logger-0.1.5.tar.gz.

File metadata

  • Download URL: splunk_hec_logger-0.1.5.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for splunk_hec_logger-0.1.5.tar.gz
Algorithm Hash digest
SHA256 4568438773dc0f86138f954a385db3f187afe18c6021f06872c212191a0aff4f
MD5 cad83d2e5daacd211a929d8bff33e6eb
BLAKE2b-256 64ac701cf3784fd2ac2a24f1a22148309eb5bd21cfa3caab07d6fe3cac522104

See more details on using hashes here.

File details

Details for the file splunk_hec_logger-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for splunk_hec_logger-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 33d856866956b7f4cfff18d32e7ebaa9ae735aec9c85ef1a32c016958f001309
MD5 6426eed27ffc5ee9787d0a25f37298c5
BLAKE2b-256 2695ce2081d055ad8c7ceedd42ace7791892ed06558e0fd3708c5ddc4fece97f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page