Skip to main content

Google Cloud Logger Formatter

Project description

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

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

google_cloud_logger-0.2.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

google_cloud_logger-0.2.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file google_cloud_logger-0.2.0.tar.gz.

File metadata

  • Download URL: google_cloud_logger-0.2.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for google_cloud_logger-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e726d6aad337a0696be76a20836a874907c16207af80342ca5ca12bb64c70b0d
MD5 c33bd49b8e6f4ba8d90ac79830e74c1b
BLAKE2b-256 7c84221c6187a475a90693377a087370cfee530c3156ff5048259da603e2434d

See more details on using hashes here.

File details

Details for the file google_cloud_logger-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: google_cloud_logger-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for google_cloud_logger-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e83698752d8288039f68151c79ac3e95e981e7e31115e96a3fb4e803a826e4d
MD5 e1cb96031b87ae9b1e44bbb0b562b29f
BLAKE2b-256 90abffa3e9b77e529c7c8a74a5b31e92eaaa6b6988d44350c032091507ca2b3c

See more details on using hashes here.

Supported by

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