Пример #1
0
class ExtendedLogger(Logger):
  """ The logger object, for use inside the pilot. It prints messages.
      But can be also used to send messages to the queue
  """

  def __init__(self, name='Pilot', debugFlag=False, pilotOutput='pilot.out', isPilotLoggerOn=False):
    """ c'tor
    If flag PilotLoggerOn is not set, the logger will behave just like
    the original Logger object, that means it will just print logs locally on the screen
    """
    super(ExtendedLogger, self).__init__(name, debugFlag, pilotOutput)
    if isPilotLoggerOn:
      # the import here was suggest F.S cause PilotLogger imports stomp
      # which is not yet in the DIRAC externals
      # so up to now we want to turn it off
      from Pilot.PilotLogger import PilotLogger
      self.pilotLogger = PilotLogger()
    else:
      self.pilotLogger = None
    self.isPilotLoggerOn = isPilotLoggerOn

  def debug(self, msg, header=True, sendPilotLog=False):
    super(ExtendedLogger, self).debug(msg, header)
    if self.isPilotLoggerOn:
      if sendPilotLog:
        self.pilotLogger.sendMessage(msg, status="debug")

  def error(self, msg, header=True, sendPilotLog=False):
    super(ExtendedLogger, self).error(msg, header)
    if self.isPilotLoggerOn:
      if sendPilotLog:
        self.pilotLogger.sendMessage(msg, status="error")

  def warn(self, msg, header=True, sendPilotLog=False):
    super(ExtendedLogger, self).warn(msg, header)
    if self.isPilotLoggerOn:
      if sendPilotLog:
        self.pilotLogger.sendMessage(msg, status="warning")

  def info(self, msg, header=True, sendPilotLog=False):
    super(ExtendedLogger, self).info(msg, header)
    if self.isPilotLoggerOn:
      if sendPilotLog:
        self.pilotLogger.sendMessage(msg, status="info")

  def sendMessage(self, msg, source, phase, status='info', localFile=None, sendPilotLog=False):
    pass
    if self.isPilotLoggerOn:
      if sendPilotLog:
        self.pilotLogger.sendMessage(messageContent=msg,
                                     source=source,
                                     phase=phase,
                                     status=status,
                                     localOutputFile=localFile)
Пример #2
0
class ExtendedLogger(Logger):
    """ The logger object, for use inside the pilot. It prints messages.
      But can be also used to send messages to the queue
  """
    def __init__(self,
                 name='Pilot',
                 debugFlag=False,
                 pilotOutput='pilot.out',
                 isPilotLoggerOn=True,
                 setup='DIRAC-Certification'):
        """ c'tor
    If flag PilotLoggerOn is not set, the logger will behave just like
    the original Logger object, that means it will just print logs locally on the screen
    """
        super(ExtendedLogger, self).__init__(name, debugFlag, pilotOutput)
        if isPilotLoggerOn:
            self.pilotLogger = PilotLogger(setup=setup)
        else:
            self.pilotLogger = None
        self.isPilotLoggerOn = isPilotLoggerOn

    def debug(self, msg, header=True, sendPilotLog=False):
        super(ExtendedLogger, self).debug(msg, header)
        if self.isPilotLoggerOn and sendPilotLog:
            self.pilotLogger.sendMessage(msg, status="debug")

    def error(self, msg, header=True, sendPilotLog=False):
        super(ExtendedLogger, self).error(msg, header)
        if self.isPilotLoggerOn and sendPilotLog:
            self.pilotLogger.sendMessage(msg, status="error")

    def warn(self, msg, header=True, sendPilotLog=False):
        super(ExtendedLogger, self).warn(msg, header)
        if self.isPilotLoggerOn and sendPilotLog:
            self.pilotLogger.sendMessage(msg, status="warning")

    def info(self, msg, header=True, sendPilotLog=False):
        super(ExtendedLogger, self).info(msg, header)
        if self.isPilotLoggerOn and sendPilotLog:
            self.pilotLogger.sendMessage(msg, status="info")

    def sendMessage(self,
                    msg,
                    source,
                    phase,
                    status='info',
                    sendPilotLog=True):
        if self.isPilotLoggerOn and sendPilotLog:
            self.pilotLogger.sendMessage(messageContent=msg,
                                         source=source,
                                         phase=phase,
                                         status=status)
Пример #3
0
 def __init__(self, name='Pilot', debugFlag=False, pilotOutput='pilot.out', isPilotLoggerOn=False):
   """ c'tor
   If flag PilotLoggerOn is not set, the logger will behave just like
   the original Logger object, that means it will just print logs locally on the screen
   """
   super(ExtendedLogger, self).__init__(name, debugFlag, pilotOutput)
   if isPilotLoggerOn:
     # the import here was suggest F.S cause PilotLogger imports stomp
     # which is not yet in the DIRAC externals
     # so up to now we want to turn it off
     from Pilot.PilotLogger import PilotLogger
     self.pilotLogger = PilotLogger()
   else:
     self.pilotLogger = None
   self.isPilotLoggerOn = isPilotLoggerOn
Пример #4
0
 def setUp(self):
     self.testFile = 'UUID_to_store'
     self.testCfgFile = 'TestPilotLogger.cfg'
     getUniqueIDAndSaveToFile(self.testFile)
     self.logger = PilotLogger(self.testCfgFile)
     self.badFile = '////'
     self.nonExistentFile = 'abrakadabraToCzaryIMagia'
Пример #5
0
 def __init__(self,
              name='Pilot',
              debugFlag=False,
              pilotOutput='pilot.out',
              isPilotLoggerOn=True,
              setup='DIRAC-Certification'):
     """ c'tor
 If flag PilotLoggerOn is not set, the logger will behave just like
 the original Logger object, that means it will just print logs locally on the screen
 """
     super(ExtendedLogger, self).__init__(name, debugFlag, pilotOutput)
     if isPilotLoggerOn:
         self.pilotLogger = PilotLogger(setup=setup)
     else:
         self.pilotLogger = None
     self.isPilotLoggerOn = isPilotLoggerOn
Пример #6
0
class TestPilotLogger_isCorrectStatus(unittest.TestCase):
    def setUp(self):
        self.uuidFile = "PilotUUID"
        self.logger = PilotLogger()

    def tearDown(self):
        try:
            os.remove(self.uuidFile)
        except OSError:
            pass

    def test_success(self):
        for status in self.logger.STATUSES:
            self.assertTrue(self.logger._isCorrectStatus(status))

    def test_failure(self):
        self.assertFalse(self.logger._isCorrectStatus("mamma Mia"))

    def test_failureEmpty(self):
        self.assertFalse(self.logger._isCorrectStatus(""))
Пример #7
0
 def test_DefaultCtrNonJsonFile(self):
     logger = PilotLogger()
     self.assertEqual(logger.params["LoggingType"], "LOCAL_FILE")
     self.assertEqual(logger.params["LocalOutputFile"],
                      "myLocalQueueOfMessages")
     self.assertEqual(logger.params["FileWithID"], "PilotUUID")
Пример #8
0
 def setUp(self):
     self.uuidFile = "PilotUUID"
     self.logger = PilotLogger()
Пример #9
0
 def test_DefaultCtrNonJsonFile(self):
     logger = PilotLogger()
     self.assertEqual(logger.params['LoggingType'], 'LOCAL_FILE')
     self.assertEqual(logger.params['LocalOutputFile'],
                      'myLocalQueueOfMessages')
     self.assertEqual(logger.params['FileWithID'], 'PilotUUID')
Пример #10
0
 def setUp(self):
     self.uuidFile = 'PilotUUID'
     self.logger = PilotLogger()