Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install splunk-logger

How to install splunk_logger

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install splunk-logger
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
Windows (64-bit)
Mac OS X (10.5+)
Linux (32-bit)
Linux (64-bit)
0.1.6 Available View build log
 
License
GNU General Public License v2 (GPLv2)
Dependencies
Lastest release
version 0.1.6 on Jan 9th, 2014

Splunk logger

A logging handler for Splunk. Lets you send information to Splunk directly from your Python code.

Usage

import logging
from splunk_logger import SplunkLogger

ACCESS_TOKEN = '...'
PROJECT_ID = '...'

splunk_logger = SplunkLogger(access_token=ACCESS_TOKEN, project_id=PROJECT_ID)
logging.getLogger('').addHandler(splunk_logger)

logging.error('This is sent to splunk')

After a couple of seconds of waiting for Splunk to process the new information, you should be able to see something like this in the web interface:

{
    data : "This is sent to splunk",
    level : "ERROR",
    line : 1,
    module : "<stdin>"
}

When using the code in a real Python program, and not from the python console, the real line number and module name are used.

Configuration file

It is always a good idea to avoid hardcoded credentials in your source code. The module can fetch the credentials from a YAML file in the current directory or the user's home. The filename is named .splunk_logger and has the following format:

credentials:
    project_id: ...
    access_token: ...

Once the file is in place, you can use the module as follows:

import logging
from splunk_logger import SplunkLogger

splunk_logger = SplunkLogger()
logging.getLogger('').addHandler(splunk_logger)

logging.error('This is sent to splunk')

Enhancements

There are a couple of things which could be improved in this module

  • The logger could be refactored to send the messages in an async manner, this will make logging.foo() calls return immediately instead of waiting for the log message to be sent.
  • Send messages in batches

Pull requests are more than welcome!

Reporting bugs

Report your issues and feature requests in Splunk Logger's issue tracker and I'll be more than glad to fix them.

Subscribe to package updates

Last updated Jan 9th, 2014

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.