File: log-syslog.py

package info (click to toggle)
exabgp 4.2.25-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,612 kB
  • sloc: python: 37,482; sh: 581; perl: 31; makefile: 23
file content (36 lines) | stat: -rwxr-xr-x 805 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python

import os
import sys
import time
import syslog


def _prefixed(level, message):
    now = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime())
    return "%s %-8s %-6d %s" % (now, level, os.getpid(), message)


syslog.openlog("ExaBGP")

# When the parent dies we are seeing continual newlines, so we only access so many before stopping
counter = 0

while True:
    try:
        line = sys.stdin.readline().strip()
        if line == "":
            counter += 1
            if counter > 100:
                break
            continue

        counter = 0

        print >>sys.stderr, line
        syslog.syslog(syslog.LOG_ALERT, _prefixed('INFO', line))
    except KeyboardInterrupt:
        pass
    except IOError:
        # most likely a signal during readline
        pass