Skip to main content

This package provides a python logger which is simple to use and logs structured logs per default for the gcp.

Project description

python-gcp-logger

This repo provides a python logger wrapper for structured logs on gcp.

Installation

pip install python-custom-logger
or
poetry add python-custom-logger

Usage

from custom_logger.logger import CustomStructuredLogger

log_to_cloud: bool = True if <any condition to check if in cloud service env> else False
log_to_console: bool = not log_to_cloud
logger: CustomStructuredLogger = CustomStructuredLogger(
    project_id=<GCP_PROJECT_ID>,
    name="MyLogger",
    log_to_console=log_to_console,
    log_to_cloud=log_to_cloud,
)

logger.info(message="helloworld")
logger.info(message={"hello": "world"})
logger.error(message="helloworld")
logger.error(message={"hello": "world"})
logger.warning(message="helloworld")
logger.warning(message={"hello": "world"})

# Using additional attributes:
logger.info(message={"hello": "world"}, attributes {"foo": "bar"})

TODOs

  • add tests
  • replace google logger with python logger using structured std out log

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

python_custom_logger-1.0.3.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

python_custom_logger-1.0.3-py3-none-any.whl (4.5 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