Create custom logging
This commit is contained in:
parent
a3e410f3a9
commit
08c9a1c7ec
@ -6,9 +6,9 @@ from pinecrypt.server import authority, errors, db
|
|||||||
from bson.objectid import ObjectId
|
from bson.objectid import ObjectId
|
||||||
from pinecrypt.server.decorators import csrf_protection
|
from pinecrypt.server.decorators import csrf_protection
|
||||||
from .utils.firewall import login_required, authorize_admin
|
from .utils.firewall import login_required, authorize_admin
|
||||||
|
from pinecrypt.server.mongolog import LogHandler
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = LogHandler()
|
||||||
|
|
||||||
|
|
||||||
class DisableEnableAccessToInstance(object):
|
class DisableEnableAccessToInstance(object):
|
||||||
@csrf_protection
|
@csrf_protection
|
||||||
|
@ -3,8 +3,9 @@ import logging
|
|||||||
from pinecrypt.server import authority, const, config
|
from pinecrypt.server import authority, const, config
|
||||||
from pinecrypt.server.common import cert_to_dn
|
from pinecrypt.server.common import cert_to_dn
|
||||||
from pinecrypt.server.decorators import serialize
|
from pinecrypt.server.decorators import serialize
|
||||||
|
from pinecrypt.server.mongolog import LogHandler
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = LogHandler()
|
||||||
|
|
||||||
class BootstrapResource(object):
|
class BootstrapResource(object):
|
||||||
@serialize
|
@serialize
|
||||||
|
@ -8,11 +8,12 @@ from asn1crypto.csr import CertificationRequest
|
|||||||
from pinecrypt.server import const, errors, authority
|
from pinecrypt.server import const, errors, authority
|
||||||
from pinecrypt.server.decorators import csrf_protection, MyEncoder
|
from pinecrypt.server.decorators import csrf_protection, MyEncoder
|
||||||
from pinecrypt.server.user import DirectoryConnection
|
from pinecrypt.server.user import DirectoryConnection
|
||||||
|
from pinecrypt.server.mongolog import LogHandler
|
||||||
from oscrypto import asymmetric
|
from oscrypto import asymmetric
|
||||||
from .utils.firewall import whitelist_subnets, whitelist_content_types, \
|
from .utils.firewall import whitelist_subnets, whitelist_content_types, \
|
||||||
login_required, login_optional, authorize_admin, validate_clock_skew
|
login_required, login_optional, authorize_admin, validate_clock_skew
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = LogHandler()
|
||||||
|
|
||||||
"""
|
"""
|
||||||
openssl genrsa -out test.key 1024
|
openssl genrsa -out test.key 1024
|
||||||
|
@ -2,8 +2,9 @@ import falcon
|
|||||||
import logging
|
import logging
|
||||||
from pinecrypt.server import authority, const, errors
|
from pinecrypt.server import authority, const, errors
|
||||||
from .utils.firewall import whitelist_subnets
|
from .utils.firewall import whitelist_subnets
|
||||||
|
from pinecrypt.server.mongolog import LogHandler
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = LogHandler()
|
||||||
|
|
||||||
class RevocationListResource(object):
|
class RevocationListResource(object):
|
||||||
@whitelist_subnets(const.CRL_SUBNETS)
|
@whitelist_subnets(const.CRL_SUBNETS)
|
||||||
|
@ -3,9 +3,10 @@ import os
|
|||||||
from pinecrypt.server import authority, const
|
from pinecrypt.server import authority, const
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
from .utils.firewall import whitelist_subject
|
from .utils.firewall import whitelist_subject
|
||||||
|
from pinecrypt.server.mongolog import LogHandler
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
env = Environment(loader=FileSystemLoader(const.SCRIPT_DIR), trim_blocks=True)
|
env = Environment(loader=FileSystemLoader(const.SCRIPT_DIR), trim_blocks=True)
|
||||||
|
logger = LogHandler()
|
||||||
|
|
||||||
class ScriptResource(object):
|
class ScriptResource(object):
|
||||||
@whitelist_subject
|
@whitelist_subject
|
||||||
|
@ -4,9 +4,9 @@ from pinecrypt.server import authority, const, config
|
|||||||
from pinecrypt.server.decorators import serialize, csrf_protection
|
from pinecrypt.server.decorators import serialize, csrf_protection
|
||||||
from pinecrypt.server.user import User
|
from pinecrypt.server.user import User
|
||||||
from .utils.firewall import login_required, authorize_admin, register_session
|
from .utils.firewall import login_required, authorize_admin, register_session
|
||||||
|
from pinecrypt.server.mongolog import LogHandler
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = LogHandler()
|
||||||
|
|
||||||
|
|
||||||
class CertificateAuthorityResource(object):
|
class CertificateAuthorityResource(object):
|
||||||
def on_get(self, req, resp):
|
def on_get(self, req, resp):
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import falcon
|
import falcon
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
@ -6,8 +5,9 @@ import hashlib
|
|||||||
from pinecrypt.server import authority, errors, db
|
from pinecrypt.server import authority, errors, db
|
||||||
from pinecrypt.server.decorators import csrf_protection
|
from pinecrypt.server.decorators import csrf_protection
|
||||||
from .utils.firewall import login_required, authorize_admin
|
from .utils.firewall import login_required, authorize_admin
|
||||||
|
from pinecrypt.server.mongolog import LogHandler
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = LogHandler()
|
||||||
|
|
||||||
class SignedCertificateDetailResource(object):
|
class SignedCertificateDetailResource(object):
|
||||||
def on_get_cn(self, req, resp, cn):
|
def on_get_cn(self, req, resp, cn):
|
||||||
|
@ -7,8 +7,9 @@ from pinecrypt.server import const, errors, authority
|
|||||||
from pinecrypt.server.decorators import serialize
|
from pinecrypt.server.decorators import serialize
|
||||||
from pinecrypt.server.user import User
|
from pinecrypt.server.user import User
|
||||||
from .utils.firewall import login_required, authorize_admin
|
from .utils.firewall import login_required, authorize_admin
|
||||||
|
from pinecrypt.server.mongolog import LogHandler
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = LogHandler()
|
||||||
|
|
||||||
class TokenResource(object):
|
class TokenResource(object):
|
||||||
def __init__(self, manager):
|
def __init__(self, manager):
|
||||||
|
@ -15,6 +15,7 @@ from datetime import datetime, timedelta
|
|||||||
from pinecrypt.server.user import User
|
from pinecrypt.server.user import User
|
||||||
from pinecrypt.server import const, errors, db
|
from pinecrypt.server import const, errors, db
|
||||||
from prometheus_client import Counter, Histogram
|
from prometheus_client import Counter, Histogram
|
||||||
|
from pinecrypt.server.mongolog import LogHandler
|
||||||
|
|
||||||
clock_skew = Histogram(
|
clock_skew = Histogram(
|
||||||
"pinecrypt_gateway_clock_skew",
|
"pinecrypt_gateway_clock_skew",
|
||||||
@ -26,8 +27,7 @@ whitelist_blocked_requests = Counter(
|
|||||||
"Requests blocked by whitelists.",
|
"Requests blocked by whitelists.",
|
||||||
["method", "path"])
|
["method", "path"])
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = LogHandler()
|
||||||
|
|
||||||
|
|
||||||
def whitelist_subnets(subnets):
|
def whitelist_subnets(subnets):
|
||||||
"""
|
"""
|
||||||
|
@ -10,12 +10,14 @@ from asn1crypto.csr import CertificationRequest
|
|||||||
from certbuilder import CertificateBuilder
|
from certbuilder import CertificateBuilder
|
||||||
from pinecrypt.server import mailer, const, errors, config, db
|
from pinecrypt.server import mailer, const, errors, config, db
|
||||||
from pinecrypt.server.common import cn_to_dn, generate_serial, cert_to_dn
|
from pinecrypt.server.common import cn_to_dn, generate_serial, cert_to_dn
|
||||||
|
from pinecrypt.server.mongolog import LogHandler
|
||||||
from crlbuilder import CertificateListBuilder, pem_armor_crl
|
from crlbuilder import CertificateListBuilder, pem_armor_crl
|
||||||
from csrbuilder import CSRBuilder, pem_armor_csr
|
from csrbuilder import CSRBuilder, pem_armor_csr
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from bson.objectid import ObjectId
|
from bson.objectid import ObjectId
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
#logger = logging.getLogger(__name__)
|
||||||
|
logger = LogHandler()
|
||||||
|
|
||||||
# Cache CA certificate
|
# Cache CA certificate
|
||||||
with open(const.AUTHORITY_CERTIFICATE_PATH, "rb") as fh:
|
with open(const.AUTHORITY_CERTIFICATE_PATH, "rb") as fh:
|
||||||
|
@ -26,12 +26,14 @@ from math import log, ceil
|
|||||||
from pinecrypt.server import const, mongolog, mailer, db
|
from pinecrypt.server import const, mongolog, mailer, db
|
||||||
from pinecrypt.server.middleware import NormalizeMiddleware, PrometheusEndpoint
|
from pinecrypt.server.middleware import NormalizeMiddleware, PrometheusEndpoint
|
||||||
from pinecrypt.server.common import cn_to_dn, generate_serial
|
from pinecrypt.server.common import cn_to_dn, generate_serial
|
||||||
|
from pinecrypt.server.mongolog import LogHandler
|
||||||
|
#from pinecrypt.server.logger import CertidudeLogger
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from wsgiref.simple_server import make_server
|
from wsgiref.simple_server import make_server
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
#logger = logging.getLogger(__name__)
|
||||||
mongolog.register()
|
#logger = CertidudeLogger()
|
||||||
|
logger = LogHandler()
|
||||||
|
|
||||||
def graceful_exit(signal_number, stack_frame):
|
def graceful_exit(signal_number, stack_frame):
|
||||||
print("Received signal %d, exiting now" % signal_number)
|
print("Received signal %d, exiting now" % signal_number)
|
||||||
|
28
pinecrypt/server/logger.py
Normal file
28
pinecrypt/server/logger.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
class LoggerObject(object):
|
||||||
|
msg = None
|
||||||
|
args = None
|
||||||
|
levelname = None
|
||||||
|
created = None
|
||||||
|
|
||||||
|
|
||||||
|
class CertidudeLogger(object):
|
||||||
|
|
||||||
|
def info(self, msg, *args):
|
||||||
|
self.pre_emit(msg, *args, level="Info")
|
||||||
|
def warning(self, msg, *args):
|
||||||
|
self.pre_emit(msg, *args, level="Warning")
|
||||||
|
def error(self, msg, *args):
|
||||||
|
self.pre_emit(msg, *args, level="Error")
|
||||||
|
def debug(self, msg, *args):
|
||||||
|
self.pre_emit(msg, *args, level="Debug")
|
||||||
|
def pre_emit(self, msg, *args, level):
|
||||||
|
record = LoggerObject()
|
||||||
|
record.msg = msg
|
||||||
|
record.args = args
|
||||||
|
record.levelname = level
|
||||||
|
record.created = time.time()
|
||||||
|
self.emit(record)
|
||||||
|
def emit(self,record):
|
||||||
|
console.log(record)
|
@ -1,27 +1,20 @@
|
|||||||
|
|
||||||
import logging
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pinecrypt.server import db
|
from pinecrypt.server import db
|
||||||
|
from pinecrypt.server.logger import CertidudeLogger
|
||||||
|
|
||||||
class LogHandler(logging.Handler):
|
class LogHandler(CertidudeLogger):
|
||||||
def emit(self, record):
|
def emit(self, record):
|
||||||
d= {}
|
d= {}
|
||||||
d["created"] = datetime.utcfromtimestamp(record.created)
|
d["created"] = datetime.utcfromtimestamp(record.created)
|
||||||
d["facility"] = record.name
|
# d["facility"] = record.name
|
||||||
d["level"] = record.levelno
|
# d["level"] = record.levelno
|
||||||
d["severity"] = record.levelname.lower()
|
d["severity"] = record.levelname.lower()
|
||||||
d["message"] = record.msg % record.args
|
d["message"] = record.msg % record.args
|
||||||
d["module"] = record.module
|
# d["module"] = record.module
|
||||||
d["func"] = record.funcName
|
# d["func"] = record.funcName
|
||||||
d["lineno"] = record.lineno
|
# d["lineno"] = record.lineno
|
||||||
d["exception"] = logging._defaultFormatter.formatException(record.exc_info) if record.exc_info else "",
|
# d["exception"] = logging._defaultFormatter.formatException(record.exc_info) if record.exc_info else "",
|
||||||
d["process"] = record.process
|
# d["process"] = record.process
|
||||||
d["thread"] = record.thread
|
# d["thread"] = record.thread
|
||||||
d["thread_name"] = record.threadName
|
# d["thread_name"] = record.threadName
|
||||||
db.eventlog.insert(d, w=1)
|
db.eventlog.insert(d, w=1)
|
||||||
|
|
||||||
def register():
|
|
||||||
for j in logging.Logger.manager.loggerDict.values():
|
|
||||||
if isinstance(j, logging.Logger):
|
|
||||||
j.setLevel(logging.DEBUG)
|
|
||||||
j.addHandler(LogHandler())
|
|
||||||
|
Loading…
Reference in New Issue
Block a user