Skip to main content

A python module for the handy printing of logs to StackDriver based on severity

Project description

gcp-python-logging

A python module for the handy printing of logs to StackDriver based on severity from within a Google Cloud Function

After running into an issue with Python logging not logging to the correct StackDriver severity filter, I created this helper module in order to facilitate that function. It replicates much of the logging functionality, but translated into StackDriver levels.


Severity Levels

Severity Int Level
ALL 0
DEBUG 100
INFO 200
WARNING 400
ERROR 500
CRITICAL 600

for all severity levels except ALL, only logs of that log level or higher will be printed out (ex: Log Level of WARNING only prints out WARNING, ERROR, and CRITICAL). If the ALL log level is written, it will appear in all cases.


Setup the Module

This module can be used simply by doing: pip install gcp-python-logging

This module can then be imported and initialized as such:

from gcp_python_logging import LoggingClient

logger = LoggingClient()

Passing no arguments will use the environment variables available to grab the project, function name, and function region. However you can also pass those variables into the client in order to change where these logs will be sent.


Creating a Log

In order to create a new log, simply use a similar syntax to Python logger.

logger.debug('This is a debug statement')
logger.error('Something went wrong!')

Changing Log Level

By default, this module sets the LogLevel to DEBUG, but this can be changed by running the command:

logger.setLogLevel('ERROR')

Then only logs at level ERROR or higher will be reported.


Author's Note:

This currently prints out all logs in a JsonPayload in order to meet the needs of my project. If users would prefer the ability to choose the printout type please feel free to reach out to me.

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

gcp-python-logging-1.1.1.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

gcp_python_logging-1.1.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file gcp-python-logging-1.1.1.tar.gz.

File metadata

  • Download URL: gcp-python-logging-1.1.1.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

File hashes

Hashes for gcp-python-logging-1.1.1.tar.gz
Algorithm Hash digest
SHA256 f4b8087cd3d5057b493cd1d78781c7587ba0d3f9a0a0bd1fe85b0dff3dd39044
MD5 c6cd5a9b6634355b348c9ffec3fdae0e
BLAKE2b-256 f514266552d8bed8c09c0d947bf91141674bad3c474e0a5f270d43d5ac751ff6

See more details on using hashes here.

File details

Details for the file gcp_python_logging-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: gcp_python_logging-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

File hashes

Hashes for gcp_python_logging-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e7d6eb5c151e358b9bf7f583d07af9aebac1be105e81125b56e799042f4da7e0
MD5 7ef71fcdac45e5890dc10d00d5cd0cab
BLAKE2b-256 85c21cb7685b39681b7938882ac317155fccca0662759dc63b5c299ee89286be

See more details on using hashes here.

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