-2

In xyz file there will be having all .py files such as abcd.py efg.py etc which are to tested with logging.info instead print statements I have set the configuration for logging.info as follows in the code but messages are not loading into log file

for example

logging.info('hi')

'hi' is not been loading into the concerned log file

import logging.config

config={

    'version': 1,
    'formatters': {'default': {
        'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
    }},
    'handlers': {'wsgi': {
        'class': 'logging.StreamHandler',
        'stream': 'ext://flask.logging.wsgi_errors_stream',
        'formatter': 'default'
    },
    'fileHandler':{
        'class':'logging.handler.RotatingFileHandler',
        'formatter':'default',
        'filename':'log_info.log'
        'maxBytes':512000,
        'backupCount':5
    }},
    'root': {
        'level': 'INFO',
        'handlers': ['wsgi']
    },
    'xyz':{
        'handler':['fileHandler'],
        'level':['info']
}}


logging.config.dictConfig(config)

log=logging.getLogger('root')
Tzane
  • 2,752
  • 1
  • 10
  • 21
dummy
  • 11
  • 3
  • 1
    With respect, the grammar is very difficult to follow. Please consider revising the question to 1) add *clarity* to what is being asked, and 2) *ask* a specific question. Thank you. – S3DEV Jun 30 '22 at 12:39
  • could you review it once – dummy Jun 30 '22 at 12:51

1 Answers1

0

There was a quite a few small typos in your config that caused the missing logs, but annoyingly didn't raise any errors

  1. Rotating file handler is located in logging.handlers.RotatingFileHandler, notice the included "s" in "handlers"
  2. Missing comma after "filename" key
  3. Loggers have to be listed under their own nesting
  4. Missing "s" in "handlers" key under logger configuration

Here's a sample in ended up with, I removed the flask part because I didn't have it installed

import logging
import logging.config

config={
    'version': 1,
    'formatters': {
        'default': {
            'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s'
        }
    },
    'handlers': {
        'fileHandler': {
            'class':'logging.handlers.RotatingFileHandler',
            'formatter':'default',
            'filename':'log_info.log',
            'maxBytes': 512000,
            'backupCount':5,
            "level": "INFO"
        }
    },
    "loggers": {
        'xyz':{
            'handlers':['fileHandler'],
            'level': "INFO"
        }
    }
}

logging.config.dictConfig(config)

logger=logging.getLogger('xyz')
logger.info("moro")
Tzane
  • 2,752
  • 1
  • 10
  • 21