Skip to main content

python_google_cloud_logger

CircleCI PyPI version Maintainability Test Coverage

Python log formatter for Google Cloud according to v2 specification using python-json-logger formatter

Inspired by Elixir's logger_json

Instalation

Pipenv

    pipenv install google_cloud_logger 

Pip

    pip install google_cloud_logger 

Usage

LOG_CONFIG = {
    "version": 1,
    "formatters": {
        "json": {
            "()": "google_cloud_logger.GoogleCloudFormatter",
            "application_info": {
                "type": "python-application",
                "name": "Example Application"
            },
            "format": "[%(asctime)s] %(levelname)s in %(module)s: %(message)s"
        }
    },
    "handlers": {
        "json": {
            "class": "logging.StreamHandler",
            "formatter": "json"
        }
    },
    "loggers": {
        "root": {
            "level": "INFO",
            "handlers": ["json"]
        }
    }
}
import logging

from logging import config

config.dictConfig(LOG_CONFIG) # load log config from dict

logger = logging.getLogger("root") # get root logger instance


logger.info("farofa", extra={"extra": "extra"}) # log message with extra arguments  

Example output:

{"timestamp": "2018-11-03T22:05:03.818000Z", "severity": "INFO", "message": "farofa", "labels": {"type": "python-application", "name": "Example Application"}, "metadata": {"userLabels": {"extra": "extra"}}, "sourceLocation": {"file": "<ipython-input-9-8e9384d78e2a>", "line": 1, "function": "<module>"}}

Credits

Thanks @thulio, @robsonpeixoto, @ramondelemos

Metadata

Release files for google-cloud-logger 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for google-cloud-logger 0.2.1
File Size Uploaded
google_cloud_logger-0.2.1.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for google-cloud-logger 0.2.1
File Interpreter ABI Platform
google_cloud_logger-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / google_cloud_logger-0.2.1.tar.gz

Download URL google_cloud_logger-0.2.1.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a2c232c22c8e78b16dcef2d06000f4a0229ef6837f2a4bc0d4bd6efbcc6ada15
BLAKE2b-256 checksum
How to use checksums
168a7596ffed2de144c6d08b30d698a24db4f7c4378e0871b8c6805f9d1bea0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.1

Release files / google_cloud_logger-0.2.1-py3-none-any.whl

Download URL google_cloud_logger-0.2.1-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c3a998ec5f4285340c919691c71e9df26b518e81432a1e88cfc37ca3f0e40133
BLAKE2b-256 checksum
How to use checksums
8ad3fe994f9f5de1c5f3d0073efdef5f442bee7388c7a565ee93eb6a2eb51e69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.7.1

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page