def mustLogWithoutColors(): # Arrange noExceptionThrown = 'exception not thrown' someLogMessage = 'some log message' someExceptionMessage = 'some exception message' someInnerExceptionMessage = 'some inner exception message' exception = None someExceptionMessageWithStackTrace = f'{someExceptionMessage} with stacktrace' someExceptionMessageWithoutStackTrace = f'{someExceptionMessage} without stacktrace' def controlableException(logType, muteStackTrace=False): try: raise Exception( someExceptionMessageWithoutStackTrace if muteStackTrace else someExceptionMessageWithStackTrace) except Exception as exception: if logType in OPTIONAL_EXCEPTION_LOG_TYPES: logType(logType, someLogMessage, exception=exception, muteStackTrace=muteStackTrace) else: logType(logType, someLogMessage, exception, muteStackTrace=muteStackTrace) # Act log.success(log.success, someLogMessage) log.setting(log.setting, someLogMessage) log.debug(log.debug, someLogMessage) log.warning(log.warning, someLogMessage) controlableException(log.log) controlableException(log.debug) controlableException(log.warning) controlableException(log.wraper) controlableException(log.failure) controlableException(log.error) controlableException(log.test) controlableException(log.log, muteStackTrace=True) controlableException(log.debug, muteStackTrace=True) controlableException(log.warning, muteStackTrace=True) controlableException(log.wraper, muteStackTrace=True) controlableException(log.failure, muteStackTrace=True) controlableException(log.error, muteStackTrace=True) controlableException(log.test, muteStackTrace=True) log.log(log.log, someLogMessage, None) log.debug(log.debug, someLogMessage, None) log.warning(log.warning, someLogMessage, None) log.wraper(log.wraper, noExceptionThrown, None) log.failure(log.failure, noExceptionThrown, None) log.error(log.error, noExceptionThrown, None) log.test(log.test, someLogMessage, None) # Assert assert 'my environment' == EnvironmentHelper.get( SettingHelper.ACTIVE_ENVIRONMENT)
def overrideSignatures(toOverride, original): try: toOverride.__name__ = original.__name__ toOverride.__module__ = original.__module__ toOverride.__qualname__ = original.__qualname__ except Exception as exception: log.wraper( overrideSignatures, f'''failed to override signatures of {toOverride} by signatures of {original} method''', exception)
def wrapedFunction(*args, **kwargs): try: functionReturn = function(*args, **kwargs) except Exception as exception: try: functionName = f'{function.__name__}' except: functionName = f'({KW_FUNCTION} {NAME_NOT_PRESENT})' log.wraper( Function, f'''failed to execute "{functionName}" function. Received args: {args}. Received kwargs: {kwargs}''', exception) raise Exception( f'{functionName} function error{c.DOT_SPACE_CAUSE}{str(exception)}' ) return functionReturn
def wraperMethod(*args, **kwargs): try: return sessionMethod(*args, **kwargs) except Exception as exception: try: className = f' {args[0].__class__.__name__}' except: className = '' try: methodName = sessionMethod.__name__ if not className == '': methodName = f'.{methodName}' else: methodName = f' {methodName}' except: methodName = '' log.wraper(SessionMethod, f'''failed to execute{className}{methodName} method''', exception)
def wrapedMethod(*args, **kwargs): try: methodReturn = method(*args, **kwargs) except Exception as exception: try: className = f'{args[0].__class__.__name__}' except: className = f'({KW_CLASS} {NAME_NOT_PRESENT})' try: methodName = method.__name__ except: methodName = f'({KW_METHOD} {NAME_NOT_PRESENT})' log.wraper( Method, f'''failed to execute {className}{c.DOT}{methodName} method. Received args: {args}. Received kwargs: {kwargs}''', exception) raise Exception( f'{className}{methodName} method error{c.DOT_SPACE_CAUSE}{str(exception)}' ) return methodReturn