Exemple #1
0
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 eraseGlobalsInstance(muteLogs=False):
    global GLOBALS
    oldGlobals = str(GLOBALS)
    GLOBALS = None
    if not muteLogs:
        log.setting(
            eraseGlobalsInstance,
            f'Erasing {oldGlobals} globals instance. It is now {GLOBALS}')
def hardUpdateGlobalsInstance(globalsInstance, muteLogs=False):
    global GLOBALS
    oldGlobals = str(GLOBALS)
    GLOBALS = globalsInstance
    if not muteLogs:
        log.setting(
            hardUpdateGlobalsInstance,
            f'Hard replacing {oldGlobals} globals instance by {GLOBALS} globals instance'
        )
    return GLOBALS
def newGlobalsInstance(*args, muteLogs=False, **kwargs):
    global GLOBALS
    if globalsInstanceIsNone(muteLogs=muteLogs):
        GLOBALS = Globals(*args, **kwargs)
        if not muteLogs:
            log.setting(newGlobalsInstance,
                        f'Returning new {GLOBALS} globals instance')
    else:
        if not muteLogs:
            log.setting(newGlobalsInstance,
                        f'Returning existing {GLOBALS} globals instance')
    return GLOBALS
def updateGlobalsInstance(globalsInstance, muteLogs=False):
    global GLOBALS
    if globalsInstanceIsNone(muteLogs=muteLogs):
        oldGlobals = str(GLOBALS)
        GLOBALS = globalsInstance
        if not muteLogs:
            log.setting(
                updateGlobalsInstance,
                f'Replacing {oldGlobals} globals instance by {GLOBALS} globals instance'
            )
    else:
        if not muteLogs:
            log.setting(updateGlobalsInstance,
                        f'Returning existing {GLOBALS} globals instance')
    return GLOBALS
Exemple #6
0
def initialize(
    rootName,
    refferenceModel,
):

    app = Flask(rootName)
    api = Api(app)
    addGlobalsTo(api)
    SchedulerManager.addScheduler(api, app)
    securityKey = api.globals.getApiSetting('api.security.secret')
    if SettingHelper.LOCAL_ENVIRONMENT == SettingHelper.getActiveEnvironment():
        log.setting(initialize, f'JWT secret: {securityKey}')
    jwt = Security.getJwtMannager(app, securityKey)

    args = [api, app, jwt]
    for resourceType in FlaskManager.KW_RESOURCE_LIST:
        args.append(getResourceList(api, resourceType))
    args.append(refferenceModel)
    addFlaskApiResources(*args)
    api.app = app
    return api, app, jwt
 def setting(self, message):
     if c.TRUE == self.settingStatus:
         log.setting(self.__class__, message)