@@ -2392,45 +2392,56 @@ def load_config_dict_from_json_file(self, filename):
23922392
23932393 def init_logging (self ):
23942394 _file = self ["LOGGING_CONFIG" ]
2395- if _file and os .path .isfile (_file ) and _file .endswith (".ini" ):
2396- logging .config .fileConfig (
2397- _file ,
2398- disable_existing_loggers = self ["LOGGING_DISABLE_LOGGERS" ])
2399- return
2400-
2401- if _file and os .path .isfile (_file ) and _file .endswith (".json" ):
2402- config_dict = self .load_config_dict_from_json_file (_file )
2403- try :
2404- logging .config .dictConfig (config_dict )
2405- except ValueError as e :
2406- # docs say these exceptions:
2407- # ValueError, TypeError, AttributeError, ImportError
2408- # could be raised, but
2409- # looking through the code, it looks like
2410- # configure() maps all exceptions (including
2411- # ImportError, TypeError) raised by functions to
2412- # ValueError.
2413- context = "No additional information available."
2414- if hasattr (e , '__context__' ) and e .__context__ :
2415- # get additional error info. E.G. if INFO
2416- # is replaced by MANGO, context is:
2417- # ValueError("Unknown level: 'MANGO'")
2418- # while str(e) is "Unable to configure handler 'access'"
2419- context = e .__context__
2420-
2421- raise LoggingConfigError (
2422- 'Error loading logging dict from %(file)s.\n '
2423- '%(msg)s\n %(context)s\n ' % {
2424- "file" : _file ,
2425- "msg" : type (e ).__name__ + ": " + str (e ),
2426- "context" : context
2427- },
2428- config_file = self .filepath ,
2429- source = "dictConfig"
2430- )
2431-
2395+ if _file and os .path .isfile (_file ):
2396+ if _file .endswith (".ini" ):
2397+ logging .config .fileConfig (
2398+ _file ,
2399+ disable_existing_loggers = self ["LOGGING_DISABLE_LOGGERS" ])
2400+ elif _file .endswith (".json" ):
2401+ config_dict = self .load_config_dict_from_json_file (_file )
2402+ try :
2403+ logging .config .dictConfig (config_dict )
2404+ except ValueError as e :
2405+ # docs say these exceptions:
2406+ # ValueError, TypeError, AttributeError, ImportError
2407+ # could be raised, but
2408+ # looking through the code, it looks like
2409+ # configure() maps all exceptions (including
2410+ # ImportError, TypeError) raised by functions to
2411+ # ValueError.
2412+ context = "No additional information available."
2413+ if hasattr (e , '__context__' ) and e .__context__ :
2414+ # get additional error info. E.G. if INFO
2415+ # is replaced by MANGO, context is:
2416+ # ValueError("Unknown level: 'MANGO'")
2417+ # while str(e) is "Unable to configure handler 'access'"
2418+ context = e .__context__
2419+
2420+ raise LoggingConfigError (
2421+ 'Error loading logging dict from %(file)s.\n '
2422+ '%(msg)s\n %(context)s\n ' % {
2423+ "file" : _file ,
2424+ "msg" : type (e ).__name__ + ": " + str (e ),
2425+ "context" : context
2426+ },
2427+ config_file = self .filepath ,
2428+ source = "dictConfig"
2429+ )
2430+ else :
2431+ raise OptionValueError (
2432+ self .options ['LOGGING_CONFIG' ],
2433+ _file ,
2434+ "Unable to load logging config file. "
2435+ "File extension must be '.ini' or '.json'.\n "
2436+ )
2437+
24322438 return
24332439
2440+ if _file :
2441+ raise OptionValueError (self .options ['LOGGING_CONFIG' ],
2442+ _file ,
2443+ "Unable to find logging config file." )
2444+
24342445 _file = self ["LOGGING_FILENAME" ]
24352446 # set file & level on the roundup logger
24362447 logger = logging .getLogger ('roundup' )
0 commit comments