def method_one(): method_two() if __name__ == '__main__': configFilePath = os.path.join(os.path.expanduser("~"), ".airbrakepy") print(configFilePath) parser = ConfigParser.SafeConfigParser() parser.read(configFilePath) api_key = parser.get("airbrake", "api_key") logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger("test-logger") handler = AirbrakeHandler(api_key, environment='dev', component_name='integration-test', node_name='server') logger.addHandler(handler) logger.error("before exception") try: method_one() except StandardError: logger.error("test with exception", exc_info=True) logger.error("test without exception", exc_info=False) logger.error("after exception") logging.shutdown()
from config import SETTINGS from datetime import datetime from flask import Flask, request import click import logging import os # initialize logger logging.basicConfig() logger = logging.getLogger("api") if SETTINGS['PYTHON_ENV'] == 'development' or SETTINGS['PYTHON_ENV'] == 'test': logger.setLevel(logging.DEBUG) else: logger.setLevel(logging.INFO) handler = AirbrakeHandler(SETTINGS['AIRBRAKE_API_KEY'], environment=SETTINGS['PYTHON_ENV'], component_name='api', node_name='data25c') handler.setLevel(logging.ERROR) logger.addHandler(handler) app = Flask(__name__) @app.route('/api/clicks/undo', methods=['POST']) def clicks_undo(): for uuid in request.form.getlist('uuids[]'): click.undo_click(uuid) return '' @app.route('/api/comments/block', methods=['POST']) def comments_block(): for uuid in request.form.getlist('uuids[]'): logger.debug('blocking comment: ' + uuid);
from airbrakepy.logging.handlers import AirbrakeHandler import logging # registering airbrake handler logger = logging.getLogger("test-logger") handler = AirbrakeHandler("API_KEY", environment='dev', component_name='SomethingWorker', node_name='IronWorker') logger.addHandler(handler) try: # your code here print 'TODO: Add actual worker code' except StandardError: logger.error("test with exception", exc_info=True) logger.error("test without exception", exc_info=False)