mirror of
https://github.com/ThomasGsp/HyperProxmox.git
synced 2025-02-15 04:32:15 +00:00
Log system core
This commit is contained in:
parent
f09356af93
commit
724b5c0f72
1 changed files with 45 additions and 12 deletions
|
@ -4,7 +4,7 @@ import sys
|
||||||
import http.client as http_client
|
import http.client as http_client
|
||||||
import datetime
|
import datetime
|
||||||
import re
|
import re
|
||||||
|
import json
|
||||||
|
|
||||||
class StreamToLogger(object):
|
class StreamToLogger(object):
|
||||||
def __init__(self, logger, log_level=logging.INFO):
|
def __init__(self, logger, log_level=logging.INFO):
|
||||||
|
@ -83,14 +83,47 @@ class Logger(object):
|
||||||
errorlog.close()
|
errorlog.close()
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
def vtype(verbose):
|
|
||||||
switcher = {
|
class Logger2:
|
||||||
1: "INFO",
|
def __init__(self, loggerconf):
|
||||||
2: "WARNING",
|
self.logs_dir = loggerconf['logs_dir']
|
||||||
3: "ERROR",
|
self.log_level = int(loggerconf['logs_level'])
|
||||||
4: "CRITICAL",
|
|
||||||
5: "DEBUG"
|
def write(self, json_text):
|
||||||
}
|
switcher = {
|
||||||
return switcher.get(verbose, "DEBUG")
|
1: "INFO",
|
||||||
"""
|
2: "WARNING",
|
||||||
|
3: "ERROR",
|
||||||
|
4: "CRITICAL",
|
||||||
|
5: "DEBUG"
|
||||||
|
}
|
||||||
|
|
||||||
|
lKeyC = [key for key, value in switcher.items() if '"{val}"'.format(val=value) == json.dumps(json_text["result"])][0]
|
||||||
|
|
||||||
|
if lKeyC >= self.log_level and lKeyC <= 4:
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
date = now.strftime("%Y-%m-%d %H:%M")
|
||||||
|
text = re.sub(r"ticket\?(.*?) ", "ticket?username=***YOUR_USER***&password=***PWD***", json_text["value"])
|
||||||
|
|
||||||
|
try:
|
||||||
|
info = "[{0}] [{1}] [{2}]".format(json_text["result"], json_text["type"], json_text["target"])
|
||||||
|
except BaseException:
|
||||||
|
info = "[{0}] [{1}]".format(json_text["result"], json_text["type"])
|
||||||
|
|
||||||
|
text = "[{date}] {info} : {text} \n".format(date=date, info=info, text=text)
|
||||||
|
|
||||||
|
if json_text["type"] == "PROXMOX":
|
||||||
|
errorlog = open("{0}/proxmox.log".format(self.logs_dir), "ab")
|
||||||
|
errorlog.write(text.encode('utf-8'))
|
||||||
|
elif json_text["type"] == "HYPERPROXMOX":
|
||||||
|
errorlog = open("{0}/hyperproxmox.log".format(self.logs_dir), "ab")
|
||||||
|
errorlog.write(text.encode('utf-8'))
|
||||||
|
elif json_text["type"] == "PYTHON":
|
||||||
|
errorlog = open("{0}/python.log".format(self.logs_dir), "ab")
|
||||||
|
errorlog.write(text.encode('utf-8'))
|
||||||
|
else:
|
||||||
|
errorlog = open("{0}/others.log".format(self.logs_dir), "ab")
|
||||||
|
errorlog.write(text.encode('utf-8'))
|
||||||
|
|
||||||
|
errorlog.close()
|
||||||
|
|
Loading…
Reference in a new issue