Python Flask logging handler to group messages on Google Cloud Platform
Project description
Flask extension for grouped log lines for Google Cloud Logging
==============================================================
Flask extension that allows log lines emitted within a request handler
to display/render together.
Normally, when using Google Cloud Logging libraries (
`google-cloud-logging`_ and `CloudLoggingHander`_), each log entry that
gets emitted is displayed separately within the Logging UI. However, its
desireable to group all logs together that logically belong that way in
an HTTP Request. For a given HTTP Request into FLask, this extension
displays all the logs ‘together’ below the parent request.
.. code:: python
@app.route('/')
def default():
app.logger.setLevel(logging.INFO)
app.logger.info("I met a traveller from an antique land,")
app.logger.info("Who said: Two vast and trunkless legs of stone")
return 'ok'
as in
.. image:: log_entry.png
:target: https://raw.githubusercontent.com/salrashid123/flask-gcp-log-groups/master/images/log_entry.png
--------------
Usage
-----
.. code:: python
from flask_gcp_log_groups import GCPHandler
app = Flask(__name__)
g = GCPHandler(app, parentLogName="request",
childLogName="application",
traceHeaderName='X-Cloud-Trace-Context',
labels= {'foo': 'bar', 'baz': 'qux'},
resource='global')
g.setLevel(logging.INFO)
app.logger.addHandler(g)
@app.route('/')
def default():
app.logger.setLevel(logging.INFO)
app.logger.info("I met a traveller from an antique land,")
app.logger.info("Who said: Two vast and trunkless legs of stone")
==============================================================
Flask extension that allows log lines emitted within a request handler
to display/render together.
Normally, when using Google Cloud Logging libraries (
`google-cloud-logging`_ and `CloudLoggingHander`_), each log entry that
gets emitted is displayed separately within the Logging UI. However, its
desireable to group all logs together that logically belong that way in
an HTTP Request. For a given HTTP Request into FLask, this extension
displays all the logs ‘together’ below the parent request.
.. code:: python
@app.route('/')
def default():
app.logger.setLevel(logging.INFO)
app.logger.info("I met a traveller from an antique land,")
app.logger.info("Who said: Two vast and trunkless legs of stone")
return 'ok'
as in
.. image:: log_entry.png
:target: https://raw.githubusercontent.com/salrashid123/flask-gcp-log-groups/master/images/log_entry.png
--------------
Usage
-----
.. code:: python
from flask_gcp_log_groups import GCPHandler
app = Flask(__name__)
g = GCPHandler(app, parentLogName="request",
childLogName="application",
traceHeaderName='X-Cloud-Trace-Context',
labels= {'foo': 'bar', 'baz': 'qux'},
resource='global')
g.setLevel(logging.INFO)
app.logger.addHandler(g)
@app.route('/')
def default():
app.logger.setLevel(logging.INFO)
app.logger.info("I met a traveller from an antique land,")
app.logger.info("Who said: Two vast and trunkless legs of stone")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for flask-gcp-log-groups-0.0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f64e2d7cbc128404dcf481ab512f8bcdf966ff62f3731b9085950ce1a2b5172 |
|
MD5 | 776e83f75476620b307d4ff1f2a313fb |
|
BLAKE2b-256 | fa0f1b180e58387a98f5dd83b17db485064906264ff9ebe5a33cd036eedf449c |