Python Agent

Use the Python Agent to post events to Loggr from your web application.

Installing
How To Use
Posting Events
Tracking Users

Installing

Installing the Python agent is very simple. Download the loggr.py file to your server and reference the file using 'import' in your Python application.

top

How To Use

This library can post events. The first thing you need to do is import the loggr module.

import loggr

Next you need to configure the module using the LOGKEY and APIKEY which can be found thru Loggr.net.

loggr.Config.logKey = 'YOUR-LOGKEY'
loggr.Config.apiKey = 'YOUR-APIKEY'

Once you have configured the module, you can follow the instructions below to write events to your log.

top

Posting Events

This agent uses a fluent-style interface for posting events to you Loggr log. The only value required for posting events is the Text property. Here is an example of posting the most simple event to your log.

loggr.Events.Create().Text("helloworld").Post()

Here's an example that shows how to post an event that utilizes all properties of an event. Keep in mind, you can use any combination that works for your app.

loggr.Events.Create() \
    .Text("More complex event") \
    .Link("http://loggr.net") \
    .Tags("tag1 tag2") \
    .Source("py") \
    .Value(35.50) \
    .User("dave.weaver") \
    .Data("<b>user-agent:</b> 12:33pm") \
    .DataType(loggr.dataType.html) \
    .Geo(40.1203, -76.2944) \
    .Post()

The tags method can accept a space-delimited string:

.Tags("tag1 tag2 tag3")

Data Property
The Data property is just a string field, however you can specify a format for how the data should be handled. To specify the format, use the DataType property like:

loggr.Events.Create() \
    .Text("this event includes JSON data") \
    .Data("{field1:true, field2:'hello'}") \
    .DataType(loggr.dataType.json) \
    .Post()

The DataType is prefixed to the actual data stored in your log. If you request the data for the previous event from our Web API you would get back:

@json
{field1:true, field2:'hello'}

Internally we parse out the DataType value when we display your event's data. We use it to show a formatted view of your data. The following table shows the currently recognized DataTypes (however, you can prefix your data with any DataType manually for your own purposes).

Value Description Prefix
DataType.plaintext Plain text data, no formatting (default)
DataType.html Text formatted as HTML @html
DataType.json Text formatted as JSON @json

Geo Property
The Geo property is used to geotag an event with location information, specifically latitude and longitude. The Geo method can be called two ways. The first way is to pass in actual latitude and longitude values.

Loggr.Events.Create() \
    .Text("Picture was posted") \
    .Geo(40.1203, -76.2944) \
    .Post()

The other currently supported way is to pass an IP address and we'll try to figure out the latitude and longitude on the server.

Loggr.Events.Create() \
    .Text("Picture was posted") \
    .GeoIP("64.265.12.365") \
    .Post()

top

Tracking Users

It's really helpful to be able to see details and activity history for the users being assigned to an event. Use trackUser(...) to register a user in your app. Once the user is registered, you'll be able to see their information when examinging an event on Loggr.

Note

We actually recommend putting a call like this on every web page in your website, within the JavaScript of your pages, but in some cases you'll want to do it on the server-side. If that's the case, use the following example. To see how to put in in your web pages, see our Javascript Agent


Each call to trackUser(...) will register an action for a user.

import loggr

# you can leave the second and third argument empty if you don't need/want it
loggr.Users.TrackUser(sUsername, sEmailAddress, "new account")

Once you make this call you should see, in realtime, the user under the Users tab in Loggr.

top