Skip to main content

Citibox Google cloud logging tools

Project description

gcloud-logger

Python log wrapper for gcloud logging format

How to use it?

Create your filter classes as needed, extending BaseContextFilter i.e.

from citibox.gcloudlogger import BaseContextFilter


class MyTestFilter(BaseContextFilter):
    def __init__(self):
        super().__init__()
        self.some_attribute = "Some Value"

    @staticmethod
    def filter_name():
        return "my_test_filter"


    def to_dict(self) -> dict:
        return {
            "some_attribute": self.some_attribute
        }

Get logger from generated dict:

  1. Import logging required

    import logging
    from logging.config import dictConfig
    
  2. Import GCloudLogConfig:

    from citibox.gcloudlogger import GCloudLogConfig
    
  3. Instance the library with your custom filters and set the logger config:

    my_log_config = GCloudLogConfig(MyTestFilter)
    dictConfig(my_log_config.config)
    
  4. Use the logger as normally:

    logger = logging.getLogger()
    
    logger.info("something good is happening")
    

Also, you can add more loggers if needed:

   import logging
   from logging.config import dictConfig
   from citibox.gcloudlogger import GCloudLogConfig

   my_log_config = GCloudLogConfig(AnyFilter)
   my_log_config.add_logger("new_logger", level=logging.INFO)
   dictConfig(my_log_config.config) 

And, add filters after the creation of the log config class:

    import logging
    from logging.config import dictConfig
    from citibox.gcloudlogger import GCloudLogConfig

    my_log_config = GCloudLogConfig(AnyFilter)
    my_log_config.add_filter(AnotherFilterClass)

Using Middlewares

Falcon

There is a Falcon middleware ready for logging Request and Response. Use Falcon middlewares adding the included class:

import falcon
from citibox.gcloudlogger.contrib.falcon import FalconMiddleware

app = falcon.API(middleware=[FalconMiddleware()])

Django

in your config file add:

MIDDLEWARE = [
    'citibox.gcloudlogger.contrib.django.DjangoMiddleware',
    ...
]

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

citibox-gcloud-logger-0.5.1.tar.gz (10.3 kB view hashes)

Uploaded Source

Built Distribution

citibox_gcloud_logger-0.5.1-py3-none-any.whl (16.8 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