GCE Logging
Project description
Overview
=======
Python logging formatter for use in Google Container Engine
With this logging formatter the logs will have the correct format for google cloud logging and also include error reporting features. The package builds heavily on python-json-logger and just expends it to include the information needed for the google cloud platform.
Installing
==========
Pip:
pip install python-gce-logging
Usage
=====
Register the logging formatter and register your flask context, getters or just provide the attributes by hand:
```python
import logging
from flask import request
from pythongcelogging import GCEFormatter
formatter = GCEFormatter("myservice", "v1.2")
# Register Flask request context
formatter.use_flask_request(request)
# Register User getter
formatter.set_user_getter(lambda: "myuser")
json_handler = logging.StreamHandler()
json_handler.setFormatter(formatter)
logger = logging.getLogger('my_json')
logger.addHandler(json_handler)
logger.setLevel(logging.INFO)
# Provide Attributes
logger.info('Sign up', extra={'method': '52d6ce', 'url': "http://hooli.xyz", "user": "xyz"})
# Error reporting
try:
raise ValueError('something')
except ValueError:
logger.error('error', exc_info=True, extra={"response_code": 500})
```
=======
Python logging formatter for use in Google Container Engine
With this logging formatter the logs will have the correct format for google cloud logging and also include error reporting features. The package builds heavily on python-json-logger and just expends it to include the information needed for the google cloud platform.
Installing
==========
Pip:
pip install python-gce-logging
Usage
=====
Register the logging formatter and register your flask context, getters or just provide the attributes by hand:
```python
import logging
from flask import request
from pythongcelogging import GCEFormatter
formatter = GCEFormatter("myservice", "v1.2")
# Register Flask request context
formatter.use_flask_request(request)
# Register User getter
formatter.set_user_getter(lambda: "myuser")
json_handler = logging.StreamHandler()
json_handler.setFormatter(formatter)
logger = logging.getLogger('my_json')
logger.addHandler(json_handler)
logger.setLevel(logging.INFO)
# Provide Attributes
logger.info('Sign up', extra={'method': '52d6ce', 'url': "http://hooli.xyz", "user": "xyz"})
# Error reporting
try:
raise ValueError('something')
except ValueError:
logger.error('error', exc_info=True, extra={"response_code": 500})
```
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
python-gce-logging-0.1.tar.gz
(3.2 kB
view hashes)
Built Distributions
Close
Hashes for python_gce_logging-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2352a2d3892bc4027035965740e563a2ece77cdb20ad023bd1a539c8c78bdc5b |
|
MD5 | 56a121e8a034438476d83b5ebedee477 |
|
BLAKE2b-256 | bbb55d9abc4d86392d08b18826f18a1aa3340eca642ceb6f552a6d442813f5d0 |
Close
Hashes for python_gce_logging-0.1-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6792a70d3e1d3234be6d0753caaee1f6150c3ea4cb4dafec7d0b088e07d0f1c7 |
|
MD5 | 84df1b5c12cfb4e47b75a29f97f1f254 |
|
BLAKE2b-256 | b9913ed72676d3b7f296fff75ca11966f09ac709a59a339634191c8f993d90a6 |