diff --git a/apps/cli/__init__.py b/apps/cli/__init__.py index 9685ba2..3e4e530 100644 --- a/apps/cli/__init__.py +++ b/apps/cli/__init__.py @@ -1,6 +1,5 @@ import logging -import json -import time +from logger import Logger # PISA-SERVER DEFAULT_PISA_API_SERVER = 'btc.pisa.watch' @@ -21,35 +20,4 @@ logging.basicConfig(format='%(message)s', level=logging.INFO, handlers=[ logging.StreamHandler() ]) - -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") \ No newline at end of file +logger = Logger("Client") diff --git a/apps/cli/blob.py b/apps/cli/blob.py index 5e6f9da..3e621c0 100644 --- a/apps/cli/blob.py +++ b/apps/cli/blob.py @@ -4,9 +4,7 @@ from binascii import hexlify, unhexlify from cryptography.hazmat.primitives.ciphers.aead import AESGCM from apps.cli import SUPPORTED_HASH_FUNCTIONS, SUPPORTED_CIPHERS -from pisa.logger import Logger - -logger = Logger("Client") +from apps.cli import logger class Blob: diff --git a/apps/cli/logger.py b/apps/cli/logger.py new file mode 100644 index 0000000..08c2547 --- /dev/null +++ b/apps/cli/logger.py @@ -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)) \ No newline at end of file diff --git a/apps/cli/pisa-cli.py b/apps/cli/pisa-cli.py index a00f978..97b5428 100644 --- a/apps/cli/pisa-cli.py +++ b/apps/cli/pisa-cli.py @@ -18,8 +18,8 @@ from cryptography.exceptions import InvalidSignature, UnsupportedAlgorithm from apps.cli.blob import Blob 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 logger HTTP_OK = 200