Ticketing Support

This documents the support classes for ticketing. With ticketing handlers log records are categorized by location and for every emitted log record a count is added. That way you know how often certain messages are triggered, at what times and when the last occurrence was.

class logbook.ticketing.TicketingBaseHandler(hash_salt, level=0, filter=None, bubble=False)

Baseclass for ticketing handlers. This can be used to interface ticketing systems that do not necessarily provide an interface that would be compatible with the BackendBase interface.

hash_record_raw(record)

Returns the unique hash of a record.

class logbook.ticketing.TicketingHandler(uri, app_id='generic', level=0, filter=None, bubble=False, hash_salt=None, backend=None, **db_options)

A handler that writes log records into a remote database. This database can be connected to from different dispatchers which makes this a nice setup for web applications:

from logbook.ticketing import TicketingHandler
handler = TicketingHandler('sqlite:////tmp/myapp-logs.db')
Parameters:
  • uri – a backend specific string or object to decide where to log to.
  • app_id – a string with an optional ID for an application. Can be used to keep multiple application setups apart when logging into the same database.
  • hash_salt – an optional salt (binary string) for the hashes.
  • backend – A backend class that implements the proper database handling. Backends available are: SQLAlchemyBackend, MongoDBBackend.
default_backend

The default backend that is being used when no backend is specified. Unless overriden by a subclass this will be the SQLAlchemyBackend.

alias of SQLAlchemyBackend

emit(record)

Emits a single record and writes it to the database.

process_record(record, hash)

Subclasses can override this to tamper with the data dict that is sent to the database as JSON.

record_ticket(record, data, hash)

Record either a new ticket or a new occurrence for a ticket based on the hash.

class logbook.ticketing.BackendBase(**options)

Provides an abstract interface to various databases.

count_tickets()

Returns the number of tickets.

delete_ticket(ticket_id)

Deletes a ticket from the database.

get_occurrences(ticket, order_by='-time', limit=50, offset=0)

Selects occurrences from the database for a ticket.

get_ticket(ticket_id)

Return a single ticket with all occurrences.

get_tickets(order_by='-last_occurrence_time', limit=50, offset=0)

Selects tickets from the database.

record_ticket(record, data, hash, app_id)

Records a log record as ticket.

setup_backend()

Setup the database backend.

solve_ticket(ticket_id)

Marks a ticket as solved.

class logbook.ticketing.SQLAlchemyBackend(**options)

Implements a backend that is writing into a database SQLAlchemy can interface.

This backend takes some additional options:

table_prefix
an optional table prefix for all tables created by the logbook ticketing handler.
metadata
an optional SQLAlchemy metadata object for the table creation.
autocreate_tables
can be set to False to disable the automatic creation of the logbook tables.
class logbook.ticketing.MongoDBBackend(**options)

Implements a backend that writes into a MongoDB database.