我们从Python开源项目中,提取了以下15个代码示例,用于说明如何使用flask.current_app.logger()。
def rebuild_product_dashboard(slug): """Rebuild the LTD Dasher dashboard manually for a single product. Note that the dashboard is built asynchronously. **Authorization** User must be authenticated and have ``admin_product`` permissions. :statuscode 202: Dashboard rebuild trigger sent. **See also** - :http:post:`/dashboards` """ product = Product.query.filter_by(slug=slug).first_or_404() build_dashboards([product.get_url()], current_app.config['LTD_DASHER_URL'], current_app.logger) return jsonify({}), 202, {}
def rebuild_all_dashboards(): """Rebuild the LTD Dasher dashboards for all products. Note that dashboards are built asynchronously. **Authorization** User must be authenticated and have ``admin_product`` permissions. :statuscode 202: Dashboard rebuild trigger sent. **See also** - :http:post:`/products/(slug)/dashboard` for single-product dashboard rebuilds. """ build_dashboards( [product.get_url() for product in Product.query.all()], current_app.config['LTD_DASHER_URL'], current_app.logger) return jsonify({}), 202, {}
def worker(channel, queue, token, repo_ids=None, build_ids=None): allowed_repo_ids = frozenset(token['repo_ids']) while (await channel.wait_message()): msg = await channel.get_json() data = msg.get('data') if data['repository']['id'] not in allowed_repo_ids: continue if build_ids and data['id'] not in build_ids: continue if repo_ids and data['repository']['id'] not in repo_ids: continue evt = Event( msg.get('id'), msg.get('event'), data, ) await queue.put(evt) current_app.logger.debug( 'pubsub.event.received qsize=%s', queue.qsize()) # @log_errors
def logger(self): return app.logger
def _parseDuration(s): from flask import current_app logger = current_app.logger from datetime import timedelta for timefmt in TIMEFORMATS: logger.debug("timefmt is {}".format(timefmt)) match = re.match(r'\s*' + timefmt + r'\s*$', s, re.I) logger.debug("Match is {}".format(match)) if match and match.group(0).strip(): mdict = match.groupdict() logger.debug("mdict is {}".format(mdict)) return timedelta(seconds=sum( [MULTIPLIERS[k] * float(v) for (k, v) in list(mdict.items()) if v is not None]))
def post(self): from flask import current_app logger = current_app.logger from tasks import raw_query import os.path logger.debug("Entering RawQuery::post") query = request.form.lists()[0][0] headers = { key: value for (key, value) in request.headers.iteritems() if key in STENO_HEADERS } result = raw_query.apply_async(kwargs={'query': query, 'headers': headers}) while not result.ready(): pass if result.successful(): rc, message = result.result # Everything is normal if rc == 0 and os.path.isfile(message): fname = os.path.basename(message) rv = send_file( message, mimetype='application/vnd.tcpdump.pcap', as_attachment=True, attachment_filename=fname ) return rv else: HTTPException(message="Response file not found", status_code=404) else: # Something failed HTTPException(message="RC: {} Message: {}".format(rc, message), status_code=500)
def decode_token(): """Decode the authorization token read from the request header.""" token = request.headers.get('Authorization') if token is None: return {} if token.startswith('Bearer '): _, token = token.split(' ', 1) pub_key = fetch_public_key(current_app) audiences = current_app.config.get('BAYESIAN_JWT_AUDIENCE').split(',') for aud in audiences: try: decoded_token = jwt.decode(token, pub_key, audience=aud) except jwt.InvalidTokenError: current_app.logger.error('Auth Token could not be decoded for audience {}'.format(aud)) decoded_token = None if decoded_token is not None: break if decoded_token is None: raise jwt.InvalidTokenError('Auth token audience cannot be verified.') return decoded_token
def log_errors(func): @wraps(func) async def wrapped(*a, **k): try: return await func(*a, **k) except Exception as e: current_app.logger.exception(str(e)) raise return wrapped # @log_errors
def ping(loop, resp, client_guid): # periodically send ping to the browser. Any message that # starts with ":" colon ignored by a browser and could be used # as ping message. while True: await asyncio.sleep(15, loop=loop) current_app.logger.debug('pubsub.ping guid=%s', client_guid) resp.write(b': ping\r\n\r\n') # @log_errors
def build_server(loop, host, port): app = Application(loop=loop, logger=current_app.logger, debug=current_app.debug) app.router.add_route('GET', '/', stream) app.router.add_route('GET', '/healthz', health_check) return await loop.create_server(app.make_handler(), host, port)
def __init__(self, filter=everyTrue, logger=None): self._filter = filter self._logger = logger
def logger(self): if self._logger == None: return current_app.logger return self._logger
def __call__(self, event): self.logger.debug('intercept event') if self._filter(event): self.action(event)
def start_event(): current_app.logger.debug("start request %s" % request.url) request._stats_start_event = time()
def stop_event(response): stop = time() delta = stop - request._stats_start_event current_app.logger.debug("stop request %s" % request.url) Monitor().add_metric(Event(response, request, delta)) return response