Skip to main content

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})
```

Project details


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)

Uploaded Source

Built Distributions

python_gce_logging-0.1-py3-none-any.whl (4.9 kB view hashes)

Uploaded Python 3

python_gce_logging-0.1-py2-none-any.whl (4.9 kB view hashes)

Uploaded Python 2

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page