mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 22:24:23 +01:00
Moved Logger from __init__ into separate file
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
import json
|
from logger import Logger
|
||||||
import time
|
|
||||||
|
|
||||||
# PISA-SERVER
|
# PISA-SERVER
|
||||||
DEFAULT_PISA_API_SERVER = 'btc.pisa.watch'
|
DEFAULT_PISA_API_SERVER = 'btc.pisa.watch'
|
||||||
@@ -21,35 +20,4 @@ logging.basicConfig(format='%(message)s', level=logging.INFO, handlers=[
|
|||||||
logging.StreamHandler()
|
logging.StreamHandler()
|
||||||
])
|
])
|
||||||
|
|
||||||
|
logger = Logger("Client")
|
||||||
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))
|
|
||||||
|
|
||||||
def warning(self, msg, **kwargs):
|
|
||||||
logging.warning(StructuredMessage(self._add_prefix(msg), actor=self.actor, **kwargs))
|
|
||||||
|
|
||||||
|
|
||||||
logger = Logger("Client")
|
|
||||||
|
|||||||
@@ -4,9 +4,7 @@ from binascii import hexlify, unhexlify
|
|||||||
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
|
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
|
||||||
|
|
||||||
from apps.cli import SUPPORTED_HASH_FUNCTIONS, SUPPORTED_CIPHERS
|
from apps.cli import SUPPORTED_HASH_FUNCTIONS, SUPPORTED_CIPHERS
|
||||||
from pisa.logger import Logger
|
from apps.cli import logger
|
||||||
|
|
||||||
logger = Logger("Client")
|
|
||||||
|
|
||||||
|
|
||||||
class Blob:
|
class Blob:
|
||||||
|
|||||||
33
apps/cli/logger.py
Normal file
33
apps/cli/logger.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import logging
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
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))
|
||||||
|
|
||||||
|
def warning(self, msg, **kwargs):
|
||||||
|
logging.warning(StructuredMessage(self._add_prefix(msg), actor=self.actor, **kwargs))
|
||||||
@@ -18,8 +18,8 @@ from cryptography.exceptions import InvalidSignature, UnsupportedAlgorithm
|
|||||||
|
|
||||||
from apps.cli.blob import Blob
|
from apps.cli.blob import Blob
|
||||||
from apps.cli.help import help_add_appointment, help_get_appointment
|
from apps.cli.help import help_add_appointment, help_get_appointment
|
||||||
from apps.cli import logger
|
|
||||||
from apps.cli import DEFAULT_PISA_API_SERVER, DEFAULT_PISA_API_PORT, PISA_PUBLIC_KEY
|
from apps.cli import DEFAULT_PISA_API_SERVER, DEFAULT_PISA_API_PORT, PISA_PUBLIC_KEY
|
||||||
|
from apps.cli import logger
|
||||||
|
|
||||||
|
|
||||||
HTTP_OK = 200
|
HTTP_OK = 200
|
||||||
|
|||||||
Reference in New Issue
Block a user