Beispiel #1
0
def test_getLevelNames():
    """
    Test getLevelNames
    """
    levels = [
        "DEBUG", "VERBOSE", "INFO", "WARN", "NOTICE", "ERROR", "ALWAYS",
        "FATAL"
    ]
    assert sorted(LogLevels.getLevelNames()) == sorted(levels)
Beispiel #2
0
    def setLevel(self, levelName):
        """
    Check if the level name exists and set it.

    :param levelName: string representing the level to give to the logger
    :return: boolean representing if the setting is done or not
    """
        result = False
        if levelName.upper() in LogLevels.getLevelNames():
            self._logger.setLevel(LogLevels.getLevelValue(levelName))
            result = True
        return result
Beispiel #3
0
    def setLevel(self, levelName):
        """
        Configure the level of the handler associated to the backend.
        Make sure the handler has been created before calling the method.

        :param int level: a level
        """
        result = False
        if levelName.upper() in LogLevels.getLevelNames():
            self._handler.setLevel(LogLevels.getLevelValue(levelName))
            self._level = levelName
            result = True
        return result
Beispiel #4
0
  def setLevel(self, levelName):
    """
    Check if the level name exists and get the integer value before setting it.

    :params levelName: string representing the level to give to the logger

    :return: boolean representing if the setting is done or not
    """
    result = False
    if levelName.upper() in LogLevels.getLevelNames():
      self._setLevel(LogLevels.getLevelValue(levelName))
      result = True
    return result
Beispiel #5
0
  def shown(self, levelName):
    """
    Determine if messages with a certain level will be displayed or not.

    :params levelName: string representing the level to analyse

    :return: boolean which give the answer
    """
    # lock to prevent a level change
    self._lockLevel.acquire()
    try:
      result = False
      if levelName.upper() in LogLevels.getLevelNames():
        result = self._level <= LogLevels.getLevelValue(levelName)
      return result
    finally:
      self._lockLevel.release()
Beispiel #6
0
 def getAllPossibleLevels():
     """
 :return: a list of all levels available
 """
     return LogLevels.getLevelNames()
Beispiel #7
0
 def getAllPossibleLevels():
   """
   :return: a list of all levels available
   """
   return LogLevels.getLevelNames()
Beispiel #8
0
    """
    _, _, _ = gLoggerReset()

    log = gLogger.getSubLogger("log")
    log.setLevel("notice")
    anotherLog = gLogger.getSubLogger("log")

    assert log.getLevel() == anotherLog.getLevel()
    assert log == anotherLog


# Run the tests for all the log levels and exceptions
# We may need to rerun the test if we are unlucky and the timestamps
# don't match
@flaky(max_runs=3)
@pytest.mark.parametrize("logLevel", ["exception"] + [lvl.lower() for lvl in LogLevels.getLevelNames()])
def test_localSubLoggerObject(logLevel):
    """
    Create a local subLogger and compare its output with the standard subLogger
    for all the log levels
    """
    capturedBackend, log, _ = gLoggerReset()
    # Set the level to debug to always make sure that something is printed
    log.setLevel("debug")

    # Create a real subLogger and a localSubLogger
    # with the same "name"
    subLog = log.getSubLogger("child")
    localSubLog = log.getSubLogger("child")

    # Print and capture a message with the real sublogger
Beispiel #9
0
    _, _, _ = gLoggerReset()

    log = gLogger.getSubLogger("log")
    log.setLevel("notice")
    anotherLog = gLogger.getSubLogger("log")

    assert log.getLevel() == anotherLog.getLevel()
    assert log == anotherLog


# Run the tests for all the log levels and exceptions
# We may need to rerun the test if we are unlucky and the timestamps
# don't match
@flaky(max_runs=3)
@pytest.mark.parametrize("logLevel", ["exception"] +
                         [lvl.lower() for lvl in LogLevels.getLevelNames()])
def test_localSubLoggerObject(logLevel):
    """
    Create a local subLogger and compare its output with the standard subLogger
    for all the log levels
    """
    capturedBackend, log, _ = gLoggerReset()
    # Set the level to debug to always make sure that something is printed
    log.setLevel("debug")

    # Create a real subLogger and a localSubLogger
    # with the same "name"
    subLog = log.getSubLogger("child")
    localSubLog = log.getSubLogger("child")

    # Print and capture a message with the real sublogger