Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.
/ logmanager Public archive
forked from SelfHacked/logmanager

Manage logging related operations

License

Notifications You must be signed in to change notification settings

selfdecode/logmanager

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
]

About

Manage logging related operations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%