mirror of
https://github.com/aljazceru/python-teos.git
synced 2026-02-20 14:04:27 +01:00
Moved StructuredMessage and Logger to separate file; refactored pisa-cli logging using new format
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import logging
|
||||
import json
|
||||
import time
|
||||
|
||||
from pisa.utils.auth_proxy import AuthServiceProxy
|
||||
import pisa.conf as conf
|
||||
@@ -8,33 +6,6 @@ import pisa.conf as conf
|
||||
HOST = 'localhost'
|
||||
PORT = 9814
|
||||
|
||||
|
||||
class StructuredMessage(object):
|
||||
def __init__(self, message, **kwargs):
|
||||
self.message = message
|
||||
self.time = time.asctime()
|
||||
self.kwargs = kwargs
|
||||
|
||||
def __str__(self):
|
||||
return json.dumps({**self.kwargs, "message": self.message, "time": self.time})
|
||||
|
||||
|
||||
class Logger(object):
|
||||
def __init__(self, actor=None):
|
||||
self.actor = actor
|
||||
|
||||
def _add_prefix(self, msg):
|
||||
return msg if self.actor is None else "[{}] {}".format(self.actor, msg)
|
||||
|
||||
def info(self, msg, **kwargs):
|
||||
logging.info(StructuredMessage(self._add_prefix(msg), actor=self.actor, **kwargs))
|
||||
|
||||
def debug(self, msg, **kwargs):
|
||||
logging.debug(StructuredMessage(self._add_prefix(msg), actor=self.actor, **kwargs))
|
||||
|
||||
def error(self, msg, **kwargs):
|
||||
logging.error(StructuredMessage(self._add_prefix(msg), actor=self.actor, **kwargs))
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(format='%(message)s', level=logging.INFO, handlers=[
|
||||
logging.FileHandler(conf.SERVER_LOG_FILE),
|
||||
|
||||
Reference in New Issue
Block a user