3

I am in confusion about django logger. I can not identify difference and purpose of "level" in logger and handler. I have configured a logger-

    "loggers": {
    "django": {
        "handlers": ["fileerror","filewarning","fileinfo"],
        "level": "DEBUG",
        "propagate": True
    },         
},
    "handlers": {
    "fileerror": {
        "level": "ERROR",
        "class": "logging.FileHandler",
        "filename": "C:/Users/samrat/Desktop/Development/uttaran/uttaran new/org_manager/static/logs/uttaran-error.log",
        "formatter": "app",
    },
    "filewarning": {
        "level": "WARNING",
        "class": "logging.FileHandler",
        "filename": "C:/Users/samrat/Desktop/Development/uttaran/uttaran new/org_manager/static/logs/uttaran-warning.log",
        "formatter": "app",
    },     
    "fileinfo": {
        "level": "INFO",
        "class": "logging.FileHandler",
        "filename": "C:/Users/samrat/Desktop/Development/uttaran/uttaran new/org_manager/static/logs/uttaran-info.log",
        "formatter": "app",
    }, 
    
},

I want to know the difference of level in loggers and handlers.

Regards, Samrat

Samrat
  • 83
  • 1
  • 5

1 Answers1

0

Django logger is not different than the standard library for Python, it is basically importing Python library for logging, so let's see what is all about...

Logging in general: Python has a built-in module logging which allows writing status messages to a file or any other output streams with levels of the log message it is similar to print but printing is not always a good idea.

For example you might want to log DEBUG message in local and not in production, this is only doable with logging.

The logging contains also much more detail by default such as information on which part of the code is executed and what problems have been arisen and date.

About level: When you set a logging level in Python using the standard module, you're telling the library you want to handle all events from that level on up. If you set the log level to INFO, it will include INFO, WARNING, ERROR, and CRITICAL messages

Insight on logging - Python

Gaëtan GR
  • 1,380
  • 1
  • 5
  • 21