Skip to content

Create log handlers from clients - #103

Merged
kattrali merged 2 commits into
masterfrom
kattrali/client-logger
Sep 13, 2016
Merged

Create log handlers from clients#103
kattrali merged 2 commits into
masterfrom
kattrali/client-logger

Conversation

@kattrali

@kattrali kattrali commented Sep 9, 2016

Copy link
Copy Markdown
Contributor

This changeset allows users to create log handlers using clients, and customize reports before they are sent to Bugsnag.

To create a client and handler:

client = Client(api_key='...')
handler = client.log_handler()

logger.addHandler(handler)

To alter add or remove information from log records before a report is sent to Bugsnag, use callbacks:

def add_custom_fields(record, options):
    if 'meta_data' not in options:
        options['meta_data'] = {}

    options['meta_data']['fruit'] ={'grape_count': len(record.grapes)}

handler.add_callback(add_custom_fields)

All records emitted by the logger are then sent to Bugsnag using the client.

To filter the logs sent, use logging.Filter:

class MyFilter(logging.Filter):
    def filter(self, record):
        return record.account_id != 0

handler.addFilter(MyFilter())

The existing options to pass an api_key and extra_fields to BugsnagHandler have been deprecated in favor of client-based handling

@kattrali
kattrali force-pushed the kattrali/client-logger branch 2 times, most recently from 807dca0 to 432b341 Compare September 12, 2016 09:34
@kattrali
kattrali force-pushed the kattrali/client-logger branch 3 times, most recently from 2f4b0ae to 12bdbd2 Compare September 13, 2016 10:06
* Deprecate api_key and extra_fields in favor of using clients and
  callbacks
* Add helper to client to create a log handler
@kattrali
kattrali force-pushed the kattrali/client-logger branch from 12bdbd2 to bf98820 Compare September 13, 2016 10:33
@kattrali
kattrali merged commit 1979050 into master Sep 13, 2016
@kattrali
kattrali deleted the kattrali/client-logger branch September 13, 2016 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant