/usr/lib/python3/dist-packages/ghost/logger.py is in python3-ghost 0.2.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 42 43 44 45 46 | # -*- coding: utf-8 -*-
from datetime import datetime
from logging import (
Filter,
Formatter,
getLogger,
)
class SenderFilter(Filter):
def filter(self, record):
record.sender = self.sender
return True
class MillisecFormatter(Formatter):
converter = datetime.fromtimestamp
def formatTime(self, record, datefmt=None):
ct = self.converter(record.created)
if datefmt is not None:
s = ct.strftime(datefmt)
else:
t = ct.strftime("%Y-%m-%dT%H:%M:%S")
s = "%s.%03dZ" % (t, record.msecs)
return s
def configure(name, sender, level, handler=None):
logger = getLogger(name)
# Add `ghost_id` to formater
ghost_filter = SenderFilter()
ghost_filter.sender = sender
logger.addFilter(ghost_filter)
# Set the level
logger.setLevel(level)
# Configure handler formater
formatter = MillisecFormatter(
fmt='%(asctime)s [%(levelname)-8s] %(sender)s: %(message)s',
)
if handler is not None:
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger
|