-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathusdt_logger.py
More file actions
executable file
·41 lines (34 loc) · 1.55 KB
/
usdt_logger.py
File metadata and controls
executable file
·41 lines (34 loc) · 1.55 KB
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
37
38
39
40
41
#!/usr/bin/env python
import usdt
import logging
class DtraceLogger(logging.Handler):
def __init__(self):
logging.Handler.__init__(self)
self.provider = usdt.Provider("python", "dtrace-logger")
self.debug_probe = usdt.Probe("logging", "debug", ["int", "char *"])
self.info_probe = usdt.Probe("logging", "info", ["int", "char *"])
self.warning_probe = usdt.Probe("logging", "warning", ["int", "char *"])
self.error_probe = usdt.Probe("logging", "error", ["int", "char *"])
self.critical_probe = usdt.Probe("logging", "critical", ["int", "char *"])
self.notset_probe = usdt.Probe("logging", "notset", ["int", "char *"])
self.provider.add_probe(self.debug_probe)
self.provider.add_probe(self.info_probe)
self.provider.add_probe(self.warning_probe)
self.provider.add_probe(self.error_probe)
self.provider.add_probe(self.critical_probe)
self.provider.add_probe(self.notset_probe)
self.provider.enable()
def emit(self, record):
if record.levelno >= logging.CRITICAL:
probe = self.critical_probe
elif record.levelno >= logging.ERROR:
probe = self.error_probe
elif record.levelno >= logging.WARNING:
probe = self.warning_probe
elif record.levelno >= logging.INFO:
probe = self.info_probe
elif record.levelno >= logging.DEBUG:
probe = self.debug_probe
else:
probe = self.notset_probe
probe.fire([record.levelno, self.format(record)])