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.1.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

google_cloud_logger-0.1.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: google_cloud_logger-0.1.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for google_cloud_logger-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d1f92e6f562d20c11a1f7099d9ebbd71622854afaeeffa7a0e5457ca2abb25d5
MD5 240f69b86ec2a5d15613022248a00828
BLAKE2b-256 fa9c494a2c80030fb16c48d9401292c8903dcc5f60c3848de54e5744e528b23c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: google_cloud_logger-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for google_cloud_logger-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a8b4179905fc96a9d01ae313b949de973219950082c5b35d7bc0ce81e480a281
MD5 038c7d12575e8cd274f97641d56f1f7c
BLAKE2b-256 400f4cc77fc88a5b703c9f37c1c64f1212064313bc242eed326ed4f8c3ec1f16

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