mirror of
https://github.com/ThomasGsp/HyperProxmox.git
synced 2025-03-09 15:40:18 +00:00
update logs lib
This commit is contained in:
parent
844b965ab3
commit
b35f648eab
1 changed files with 13 additions and 11 deletions
|
@ -16,10 +16,8 @@ class StreamToLogger(object):
|
||||||
for line in buf.rstrip().splitlines():
|
for line in buf.rstrip().splitlines():
|
||||||
self.logger.log(self.log_level, line.rstrip())
|
self.logger.log(self.log_level, line.rstrip())
|
||||||
|
|
||||||
def flush(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
class VAction(argparse.Action):
|
class VAction(argparse.Action):
|
||||||
def __call__(self, parser, args, values, option_string=None):
|
def __call__(self, parser, args, values, option_string=None):
|
||||||
# print 'values: {v!r}'.format(v=values)
|
# print 'values: {v!r}'.format(v=values)
|
||||||
|
@ -30,12 +28,14 @@ class VAction(argparse.Action):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
values = values.count('v') + 1
|
values = values.count('v') + 1
|
||||||
setattr(args, self.dest, values)
|
setattr(args, self.dest, values)
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class Logger(object):
|
class Logger(object):
|
||||||
def __init__(self, config):
|
def __init__(self, generalconf):
|
||||||
self.debug = config['common']['debug']
|
self.debug = generalconf['logger']['debug']
|
||||||
self.error_log = config['common']['error_log']
|
self.logs_dir = generalconf['logger']['logs_dir']
|
||||||
|
self.debug_level = generalconf['logger']['debug_level']
|
||||||
self.stdout_logger = None
|
self.stdout_logger = None
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
@ -45,14 +45,14 @@ class Logger(object):
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.DEBUG,
|
level=logging.DEBUG,
|
||||||
format='%(asctime)s:%(levelname)s:%(name)s:%(threadName)s:%(message)s',
|
format='%(asctime)s:%(levelname)s:%(name)s:%(threadName)s:%(message)s',
|
||||||
filename=str(self.error_log),
|
filename="{0}/debug.log".format(self.logs_dir),
|
||||||
filemode='a'
|
filemode='a'
|
||||||
)
|
)
|
||||||
|
|
||||||
http_client.HTTPConnection.debuglevel = 1
|
http_client.HTTPConnection.debuglevel = 1
|
||||||
requests_log = logging.getLogger("requests.packages.urllib3")
|
requests_log = logging.getLogger("requests.packages.urllib3")
|
||||||
requests_log.propagate = True
|
requests_log.propagate = True
|
||||||
sl = StreamToLogger(requests_log, str(self.debug))
|
sl = StreamToLogger(self.stdout_logger, logging.DEBUG)
|
||||||
sys.stdout = sl
|
sys.stdout = sl
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -60,7 +60,7 @@ class Logger(object):
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.ERROR,
|
level=logging.ERROR,
|
||||||
format='%(asctime)s:%(levelname)s:%(name)s:%(threadName)s:%(message)s',
|
format='%(asctime)s:%(levelname)s:%(name)s:%(threadName)s:%(message)s',
|
||||||
filename=str(self.error_log),
|
filename="{0}/errors.log".format(self.logs_dir),
|
||||||
filemode='a'
|
filemode='a'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -72,17 +72,18 @@ class Logger(object):
|
||||||
|
|
||||||
return self.stdout_logger
|
return self.stdout_logger
|
||||||
|
|
||||||
def write_error(self, node, errortxt, destfile):
|
def errorout(self, node, errortxt):
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
date = now.strftime("%Y-%m-%d %H:%M")
|
date = now.strftime("%Y-%m-%d %H:%M")
|
||||||
errortxt = re.sub(r"ticket\?(.*?) ", "ticket?username=***YOUR_USER***&password=***PWD***", errortxt)
|
errortxt = re.sub(r"ticket\?(.*?) ", "ticket?username=***YOUR_USER***&password=***PWD***", errortxt)
|
||||||
|
|
||||||
error = "[{date} -- {node}] : {error} \n".format(date=date, node=node, error=errortxt)
|
error = "[{date} -- {node}] : {error} \n".format(date=date, node=node, error=errortxt)
|
||||||
errorlog = open(destfile, "ab")
|
errorlog = open("{0}/proxmox.log".format(self.logs_dir), "ab")
|
||||||
errorlog.write(error.encode('utf-8'))
|
errorlog.write(error.encode('utf-8'))
|
||||||
errorlog.close()
|
errorlog.close()
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
def vtype(verbose):
|
def vtype(verbose):
|
||||||
switcher = {
|
switcher = {
|
||||||
1: "INFO",
|
1: "INFO",
|
||||||
|
@ -92,3 +93,4 @@ def vtype(verbose):
|
||||||
5: "DEBUG"
|
5: "DEBUG"
|
||||||
}
|
}
|
||||||
return switcher.get(verbose, "DEBUG")
|
return switcher.get(verbose, "DEBUG")
|
||||||
|
"""
|
Loading…
Add table
Add a link
Reference in a new issue