Skip to main content

A Python library to setup clean structured logs, for local development, and production with Google Cloud Logging.

Project description

Octopulse Python Logger Package

This is a Python library to setup clean structured logs, for local development, and production with Google Cloud Logging.

This logger uses these external packages:

  • google-cloud-logging
  • structlog
  • colorama
  • python-json-logger

Installation

Use the package manager pip to install the package.

pip install octopulse-logger

Setup

To be able to sent logs to GCP, you need to provide authentication credentials to your application code by setting the environment variable GOOGLE_APPLICATION_CREDENTIALS.
Replace [PATH] with the file path of the JSON file that contains your service account key.

export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"

Usage

You have the possibility to add global arguments that will add contextual information to all logs.

from octopulse_logger import logger_setup

# setup the logger
logger_setup.setup('logger_name', setup_google_logging=True, setup_stdout_logging=True, logger_level='DEBUG', my_global_var="foobar")

Setup setup_google_logging and/or setup_stdout_logging to send logs to Google Cloud Logging and/or std output.

Then you can start to log with default logger or structlog :

import logging
import structlog

structlog_logger = structlog.getLogger('logger_name')
structlog_logger.warning('Warning !', value_a=1)
# or
basic_logger = logging.getLogger('logger_name')
basic_logger.error('An error occurred :(')

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

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

octopulse-logger-0.2.1.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

octopulse_logger-0.2.1-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

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