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)[source]

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)[source]

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)[source]

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)[source]

Emits a single record and writes it to the database.

process_record(record, hash)[source]

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

record_ticket(record, data, hash)[source]

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

class logbook.ticketing.BackendBase(**options)[source]

Provides an abstract interface to various databases.

count_tickets()[source]

Returns the number of tickets.

delete_ticket(ticket_id)[source]

Deletes a ticket from the database.

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

Selects occurrences from the database for a ticket.

get_ticket(ticket_id)[source]

Return a single ticket with all occurrences.

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

Selects tickets from the database.

record_ticket(record, data, hash, app_id)[source]

Records a log record as ticket.

setup_backend()[source]

Setup the database backend.

solve_ticket(ticket_id)[source]

Marks a ticket as solved.

class logbook.ticketing.SQLAlchemyBackend(**options)[source]

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)[source]

Implements a backend that writes into a MongoDB database.