Giter Site home page Giter Site logo

logmanager's Introduction

Log Manager

Manage logging operations.

Installation

pip install -e git+git://github.com/SelfHacked/logmanager.git#egg=logmanager

Configuration

Use DefaultLogManager or LogManager to configure Django application logging. DefaultLogManager add loggers for Django modules and an additional logger named app.

Example: Add following code snippet to settings.py of the Django Application with following environment variables.

  • LOG_GROUP: Name of a CloudWatch group.
  • LOG_LEVEL: Desired log level for the output filtering.
from logmanager import DefaultLogManager

LOGGING = DefaultLogManager(
    app_name='application-name',
    log_group=os.environ.get('LOG_GROUP'),
    log_level=os.environ.get('LOG_LEVEL', 'DEBUG' if DEBUG else 'INFO'),
    loggers=[],
).config

Note: Any custom loggers (ex: application modules) should be included in loggers.

Using Log Manager

Option 1: Logging with default logger

Use logger from logmanager to log with app logger.

from logmanager import logger

logger.info('Test Log Message!')

Option 2: Logging with custom logger

Use built-in logger to log with module logger (or custom logger). If module logger (or a custom logger) is used, name of the logger should be added to logger argument of DefaultLogManager.

import logging

logger = logging.getLogger(__name__)
logger.info('Test Log Message!')

Adding Request Logger

Add LogRequestMiddleware to log requests. Middleware should be included after Authentication middleware to log user id.

MIDDLEWARE = [
    # middleware
    'logmanager.middleware.LogRequestMiddleware',
    # middleware
]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.