Beispiel #1
0
    def log(self, message=None, locator=None):
        if not self.state:
            return

        if message is not None:
            self._entry.line(message)

        meta = self._entry.meta

        if locator is None:
            locator = here(1)

        # These are required by 'journal.devices.Renderer'.
        meta["filename"] = ""
        meta["function"] = ""
        meta["line"] = ""

        locator.getAttributes(meta)

        meta["facility"] = self.facility
        meta["severity"] = self.severity

        journal().record(self._entry)

        if self.fatal:
            raise self.Fatal(message)

        self._entry = Entry()
        return self
Beispiel #2
0
    def init(self, channel, defaultState, fatal=False):
        self._index = {}
        self._channel = channel
        self._defaultState = defaultState
        self._fatal = fatal

        from pythia.journal import journal
        journal().channel(channel, self)

        return
Beispiel #3
0
 def test_channels(self):
     CHANNELS = ("firewall", "debug", "info", "warning", "error")
     j = journal.journal()
     channels = j.channels()
     self.assertEqual(len(CHANNELS), len(channels))
     for channel in channels:
         self.assertTrue(channel in CHANNELS)
Beispiel #4
0
    def record(self):
        if not self.state:
            return

        meta = self._entry.meta
        meta["facility"] = self.facility
        meta["severity"] = self.severity
        meta.setdefault("filename", "<unknown>")
        meta.setdefault("function", "<unknown>")
        meta.setdefault("line", "<unknown>")

        journal().record(self._entry)

        if self.fatal:
            raise self.Fatal()

        self._entry = Entry()
        return self
Beispiel #5
0
    def updateConfiguration(self, registry):
        from pythia.pyre.util.bool import bool
        listing = self._listing(registry)

        from pythia.journal import journal
        for category, state in listing:
            journal().channel(
                self.name).diagnostic(category).state = bool(state)

        return []
Beispiel #6
0
    def _init(self):
        from pythia.journal import journal
        theJournal = journal()

        device = self.inventory.device.device
        theJournal.device = device

        Component._init(self)

        return
Beispiel #7
0
def remote(key, port, host="localhost", protocol="tcp"):

    if protocol == "tcp":
        from .TCPDevice import TCPDevice
        device = TCPDevice(key, port, host)
    elif protocol == "udp":
        from .UDPDevice import UDPDevice
        device = UDPDevice(key, port, host)
    else:
        from pythia.journal import diagnostics
        diagnostics.error('journal').log("unknown protocol '%s'" % protocol)
        return

    journal().device = device
    return device
Beispiel #8
0
    def test_textfile(self):
        from pythia.journal.devices.TextFile import TextFile

        filename = "debug.log"
        with open(filename, "w") as log:
            journal.journal().device = TextFile(log)
            self.journal.log("Hello")

        with open(filename, "r") as log:
            logLines = log.readlines()
            iLog = 1
            self.assertEqual(">> test(debug)", logLines[iLog].strip())
            iLog += 1
            self.assertEqual("-- Hello", logLines[iLog].strip())
            iLog += 1
        os.remove(filename)
Beispiel #9
0
 def test_colorconsole(self):
     from pythia.journal.devices.ANSIColorConsole import ANSIColorConsole
     journal.journal().device = ANSIColorConsole()
     self.journal.log("Hello")
Beispiel #10
0
 def test_console(self):
     from pythia.journal.devices.Console import Console
     journal.journal().device = Console()
     self.journal.log("Hello")
Beispiel #11
0
def logfile(stream):
    from .File import File
    device = File(stream)

    journal().device = device
    return device
Beispiel #12
0
 def test_entry(self):
     j = journal.journal()
     entry = j.entry()
     self.assertEqual({}, entry.meta)
     self.assertEqual([], entry.text)