Skip to main content

json based python logger with support for slack notification

Project description

Note: Set up ssh key in your bitbucket account, if not already set. (refer this link)


Installation

Install the package using the following command

pip install git+ssh://git@bitbucket.org/wolkustechnologysolutions/fasal_logger.git

Configuration

  • Create a file logger.yml. Copy the contents from the repository and make the necessary changes (If needed)
  • The logger defined here defaults to console. In order to log the contents into a file, make the required changes to the logger.yml.
root:
  handlers: [console, file]

loggers:
  fasalLogger:
    handlers: [console, file]

And change the filename and location.

handler:
    file:
        filename: 'logging.example.log'

Usage

In order to use the logger in your code, add the following piece of code at the top of your .py file

Note: Get the webhook from the infra team to able to send messages to slack to any other channel. (By default using #fasal-ai-infra)

import logging
import logging.config
import os
from fasal_logger import LoggerInitializer, SlackNotification

logging.captureWarnings(True)
logger = logging.getLogger(__name__)
logger_init = LoggerInitializer()
logger_init(logger=logger, config='./fasal_logger/logger.yml')
slk = SlackNotification() # set parameter for webhook, DEV (if needed)

# Use logger now
logger.info("Logger set")

# Send a message to slack channel
slk.notify(message="testing")

Variables taken from environment are:

  • SLACK_WEBHOOK: Channel webhook trigger
  • DEV: If True, no message is send to slack
  • ENV: logger environment (staging/production/development)

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

fasal_logger-0.0.1.tar.gz (4.4 kB view hashes)

Uploaded Source

Built Distribution

fasal_logger-0.0.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