def defLogging(): global debug global logPath global loggingLevel global logging_setup try: if debug: logging_setup = NestedSetup([ # make sure we never bubble up to the stderr handler # if we run out of setup handling NullHandler(), StreamHandler( sys.stdout, bubble=False, level=loggingLevel ), TimedRotatingFileHandler( logPath, level=0, backup_count=3, bubble=True, date_format='%Y-%m-%d', ), ]) else: logging_setup = NestedSetup([ # make sure we never bubble up to the stderr handler # if we run out of setup handling NullHandler(), FingersCrossedHandler( TimedRotatingFileHandler( logPath, level=0, backup_count=3, bubble=False, date_format='%Y-%m-%d', ), action_level=ERROR, buffer_size=1000, # pull_information=True, # reset=False, ) ]) except (KeyboardInterrupt, SystemExit): raise except: print("Critical error attempting to setup logging. Falling back to console only.") logging_setup = NestedSetup([ # make sure we never bubble up to the stderr handler # if we run out of setup handling NullHandler(), StreamHandler( sys.stdout, bubble=False ) ])
date_format='%Y-%m-%d', ), ]) else: logging_mode = "User" logging_setup = NestedSetup([ # make sure we never bubble up to the stderr handler # if we run out of setup handling NullHandler(), FingersCrossedHandler( TimedRotatingFileHandler( config.logPath, level=0, backup_count=3, bubble=False, date_format='%Y-%m-%d', ), action_level=ERROR, buffer_size=1000, # pull_information=True, # reset=False, ) ]) except: print( "Critical error attempting to setup logging. Falling back to console only." ) logging_mode = "Console Only" logging_setup = NestedSetup([ # make sure we never bubble up to the stderr handler # if we run out of setup handling
def defLogging(): global debug global logPath global loggingLevel global logging_setup try: if debug: logging_setup = NestedSetup([ # make sure we never bubble up to the stderr handler # if we run out of setup handling NullHandler(), StreamHandler(sys.stdout, bubble=False, level=loggingLevel), TimedRotatingFileHandler( logPath, level=0, backup_count=3, bubble=True, date_format='%Y-%m-%d', ), ]) else: logging_setup = NestedSetup([ # make sure we never bubble up to the stderr handler # if we run out of setup handling NullHandler(), FingersCrossedHandler( TimedRotatingFileHandler( logPath, level=0, backup_count=3, bubble=False, date_format='%Y-%m-%d', ), action_level=ERROR, buffer_size=1000, # pull_information=True, # reset=False, ) ]) except: print( "Critical error attempting to setup logging. Falling back to console only." ) logging_setup = NestedSetup([ # make sure we never bubble up to the stderr handler # if we run out of setup handling NullHandler(), StreamHandler(sys.stdout, bubble=False) ]) with logging_setup.threadbound(): # Output all stdout (print) messages as warnings try: sys.stdout = LoggerWriter(pyfalog.warning) except: pyfalog.critical( "Cannot redirect. Continuing without writing stdout to log.") # Output all stderr (stacktrace) messages as critical try: sys.stderr = LoggerWriter(pyfalog.critical) except: pyfalog.critical( "Cannot redirect. Continuing without writing stderr to log.")