Skip to content

Latest commit

 

History

17 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Config logging for my python project

Loggers are never instantiated directly, but always through the module-level function logging.getLogger(name). Multiple calls to getLogger() with the same name will always return a reference to the same Logger object.

How to use:

In main script

import logging
import other_modules
from config_log_ziwen import setup_logging

setup_logging(app_name="my_app")
logger = logging.getLogger(__name__)

if __name__ == "__main__":
    logger.info("Hello, world!")    

In other modules

import logging
logger = logging.getLogger(__name__)

logger.info("Hello, world!")

Config we can change

def setup_logging(
    app_name: str = "my_app",
    log_dir: str = "logs",
    disable_existing_loggers: bool = False,
    default_level: int = logging.DEBUG,
    file_level: int = logging.DEBUG,
    console_level: int = logging.DEBUG,
    max_bytes: int = 10 * 1024 * 1024,  # 10MB
    backup_count: int = 10,
) -> None:

About

Configured logging for future python script

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages