Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

key error when moving ini file to other directory

$
0
0

I have set up an logger which reads the content of a ini file

ini_file

[logging]file=logs\\logcontainer.logrotatewhen=midnightsize=100000level=DEBUG

I want to change the directory of the ini file from the directory of the loggerconfigfilename = './config.ini'to configfilename = '.config_file/config.ini'

I moved the ini file to the new directory but get a KeyError: 'logging'

looks like problem with the nested directory, but I cant figure out the cause of the error

config = Nonedef load_logger():    # logging    conf_logging = config["logging"]    loglevel = conf_logging.get("level", fallback="DEBUG")    logger.setLevel(loglevel)    logfilename = conf_logging.get("file", fallback="./logs/%s.log"%__name__)    logdirname = os.path.dirname(logfilename)    logfilesize = conf_logging.getint("size",fallback=1e6)    rotatewhen = conf_logging.get("rotatewhen",fallback='midnight')    if not os.path.exists(logdirname): os.mkdir(logdirname)    if logger.handlers:        logger.debug("a handler was already added: %s"%logger.handlers)    else:        try:            rfh = logging.handlers.TimedRotatingFileHandler(logfilename, when=rotatewhen)        except ValueError as e:            rotatewhen = 'midnight'            rfh = logging.handlers.TimedRotatingFileHandler(logfilename, when=rotatewhen)            logger.warning("%s , using '%s'"%(e,rotatewhen))        fmt = logging.Formatter("%(asctime)-15s - %(name)-20s - %(levelname)s:%(message)s")        rfh.setFormatter(fmt)        logger.addHandler(rfh)def load_config():    global config    # configfilename = './config.ini' #    configfilename = '.config_file/config.ini' #    config = configparser.ConfigParser()    config.read(configfilename)

Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>