mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 14:14:22 +01:00
Moved Logger from __init__ into separate file
This commit is contained in:
@@ -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")
|
||||
logger = Logger("Client")
|
||||
|
||||
@@ -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:
|
||||
|
||||
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.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
|
||||
|
||||
Reference in New Issue
Block a user