@@ -113,13 +113,12 @@ def synchronize(pbatch, jobids: list, wait: int=15):
113113def setup_logging (logfile : Path = Path ()):
114114 """
115115 Set up the logging framework:
116- 1) Add a 'bcdebug', 'verbose' and a 'success' logging level
117- 2) Add a console streamhandler
118- 3) If logfile then add a normal log and a warning/error filehandler
116+ 1) Add custom logging levels: 'bcdebug', 'verbose', and 'success'.
117+ 2) Add a console stream handler for generating terminal output.
118+ 3) Optionally add file handlers for normal log and warning/error log if logfile is provided.
119119
120- :param logfile: Name of the logfile
121- :return:
122- """
120+ :param logfile: Path to the logfile. If none, logging is console-only
121+ """
123122
124123 # Set the default formats
125124 if DEBUG :
@@ -130,31 +129,7 @@ def setup_logging(logfile: Path=Path()):
130129 cfmt = '%(levelname)s | %(message)s'
131130 datefmt = '%Y-%m-%d %H:%M:%S'
132131
133- # Add a BIDScoin debug logging level = 11 (NB: using the standard debug mode will generate may debug messages from imports)
134- logging .BCDEBUG = 11
135- logging .addLevelName (logging .BCDEBUG , 'BCDEBUG' )
136- logging .__all__ += ['BCDEBUG' ] if 'BCDEBUG' not in logging .__all__ else []
137- def bcdebug (self , message , * args , ** kws ):
138- if self .isEnabledFor (logging .BCDEBUG ): self ._log (logging .BCDEBUG , message , args , ** kws )
139- logging .Logger .bcdebug = bcdebug
140-
141- # Add a verbose logging level = 15
142- logging .VERBOSE = 15
143- logging .addLevelName (logging .VERBOSE , 'VERBOSE' )
144- logging .__all__ += ['VERBOSE' ] if 'VERBOSE' not in logging .__all__ else []
145- def verbose (self , message , * args , ** kws ):
146- if self .isEnabledFor (logging .VERBOSE ): self ._log (logging .VERBOSE , message , args , ** kws )
147- logging .Logger .verbose = verbose
148-
149- # Add a success logging level = 25
150- logging .SUCCESS = 25
151- logging .addLevelName (logging .SUCCESS , 'SUCCESS' )
152- logging .__all__ += ['SUCCESS' ] if 'SUCCESS' not in logging .__all__ else []
153- def success (self , message , * args , ** kws ):
154- if self .isEnabledFor (logging .SUCCESS ): self ._log (logging .SUCCESS , message , args , ** kws )
155- logging .Logger .success = success
156-
157- # Set the root logging level
132+ # Get the root logger and set the appropriate level
158133 logger = logging .getLogger ()
159134 logger .setLevel ('BCDEBUG' if DEBUG else 'VERBOSE' )
160135
@@ -194,7 +169,7 @@ def reporterrors() -> str:
194169
195170 # Find the filehandlers and report the errors and warnings
196171 errors = ''
197- for handler in logging . getLogger () .handlers :
172+ for handler in LOGGER .handlers :
198173 if handler .name == 'errorhandler' :
199174
200175 errorfile = Path (handler .baseFilename )
0 commit comments