mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-18 22:54:23 +01:00
Added Logger class to pisa-cli to avoid imports from pisa; changed log file name to pisa-cli.log
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
# PISA-SERVER
|
# PISA-SERVER
|
||||||
DEFAULT_PISA_API_SERVER = 'btc.pisa.watch'
|
DEFAULT_PISA_API_SERVER = 'btc.pisa.watch'
|
||||||
DEFAULT_PISA_API_PORT = 9814
|
DEFAULT_PISA_API_PORT = 9814
|
||||||
|
|
||||||
# PISA-CLI
|
# PISA-CLI
|
||||||
CLIENT_LOG_FILE = 'pisa.log'
|
CLIENT_LOG_FILE = 'pisa-cli.log'
|
||||||
|
|
||||||
# CRYPTO
|
# CRYPTO
|
||||||
SUPPORTED_HASH_FUNCTIONS = ["SHA256"]
|
SUPPORTED_HASH_FUNCTIONS = ["SHA256"]
|
||||||
@@ -18,3 +20,36 @@ logging.basicConfig(format='%(message)s', level=logging.INFO, handlers=[
|
|||||||
logging.FileHandler(CLIENT_LOG_FILE),
|
logging.FileHandler(CLIENT_LOG_FILE),
|
||||||
logging.StreamHandler()
|
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")
|
||||||
@@ -9,22 +9,20 @@ from binascii import unhexlify
|
|||||||
from getopt import getopt, GetoptError
|
from getopt import getopt, GetoptError
|
||||||
from requests import ConnectTimeout, ConnectionError
|
from requests import ConnectTimeout, ConnectionError
|
||||||
|
|
||||||
|
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
from cryptography.hazmat.primitives import hashes
|
from cryptography.hazmat.primitives import hashes
|
||||||
from cryptography.hazmat.primitives.serialization import load_pem_public_key
|
from cryptography.hazmat.primitives.serialization import load_pem_public_key
|
||||||
from cryptography.hazmat.primitives.asymmetric import ec
|
from cryptography.hazmat.primitives.asymmetric import ec
|
||||||
from cryptography.exceptions import InvalidSignature, UnsupportedAlgorithm
|
from cryptography.exceptions import InvalidSignature, UnsupportedAlgorithm
|
||||||
|
|
||||||
from pisa.logger import Logger
|
|
||||||
from pisa.appointment import Appointment
|
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
HTTP_OK = 200
|
|
||||||
|
|
||||||
logger = Logger("Client")
|
HTTP_OK = 200
|
||||||
|
|
||||||
pisa_public_key = None
|
pisa_public_key = None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user