adjusted logging format, patched $DISPLAY error

This commit is contained in:
Matteo ℱan 2019-05-17 00:31:49 +02:00 committed by GitHub
parent b13d212f05
commit 750713d0cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 13 deletions

View File

@ -198,9 +198,11 @@ class kmsBase:
loggersrv.info("SKU ID: %s" % infoDict["skuId"])
loggersrv.info("License Status: %s" % infoDict["licenseStatus"])
loggersrv.info("Request Time: %s" % local_dt.strftime('%Y-%m-%d %H:%M:%S %Z (UTC%z)'))
loggersrv.mini("", extra = {'host': socket.gethostname() + " [" + self.srv_config["ip"] + "]",
'status' : infoDict["licenseStatus"],
'product' : infoDict["skuId"]})
if self.srv_config['loglevel'] == 'MINI':
loggersrv.mini("", extra = {'host': socket.gethostname() + " [" + self.srv_config["ip"] + "]",
'status' : infoDict["licenseStatus"],
'product' : infoDict["skuId"]})
if self.srv_config['sqlite'] and self.srv_config['dbSupport']:
sql_update(self.dbName, infoDict)

View File

@ -117,7 +117,7 @@ def client_update():
break
def client_create():
loggerclt.info("\n\nConnecting to %s on port %d..." % (clt_config['ip'], clt_config['port']))
loggerclt.info("Connecting to %s on port %d..." % (clt_config['ip'], clt_config['port']))
s = socket.create_connection((clt_config['ip'], clt_config['port']))
loggerclt.info("Connection successful !")
binder = pykms_RpcBind.handler(None, clt_config)
@ -161,9 +161,11 @@ def client_create():
loggerclt.info("KMS Host Current Client Count: %s" % kmsResp['currentClientCount'])
loggerclt.info("KMS VL Activation Interval: %s" % kmsResp['vLActivationInterval'])
loggerclt.info("KMS VL Renewal Interval: %s" % kmsResp['vLRenewalInterval'])
loggerclt.mini("", extra = {'host': socket.gethostname() + " [" + clt_config["ip"] + "]",
'status' : "Activated",
'product' : clt_config["mode"]})
if clt_config['loglevel'] == 'MINI':
loggerclt.mini("", extra = {'host': socket.gethostname() + " [" + clt_config["ip"] + "]",
'status' : "Activated",
'product' : clt_config["mode"]})
ShellMessage.Process(21).run()

View File

@ -184,8 +184,11 @@ class ShellMessage(object):
# Do something with output.
toprint = self.read(0.1) # 0.1 s to let the shell output the result
# Redirect output.
from pykms_GuiBase import gui_redirect # Import after variables creation !
gui_redirect(toprint)
if sys.stdout.isatty():
print(toprint)
else:
from pykms_GuiBase import gui_redirect # Import after variables creation.
gui_redirect(toprint)
def spawn(self):
# Save everything that would otherwise go to stdout.

View File

@ -50,7 +50,7 @@ def add_logging_level(levelName, levelNum, methodName = None):
class LevelFormatter(logging.Formatter):
dfmt = '%a, %d %b %Y %H:%M:%S'
default_fmt = logging.Formatter('[%(asctime)s] [%(levelname)8s] %(message)s', datefmt = dfmt)
default_fmt = logging.Formatter('%(message)s', datefmt = dfmt)
def __init__(self, formats):
""" `formats` is a dict { loglevel : logformat } """
@ -81,8 +81,23 @@ def logger_create(log_obj, config, mode = 'a'):
backupCount = 1, encoding = None, delay = 0)
log_handler.setLevel(config['loglevel'])
# Configure formattation.
formatter = LevelFormatter({logging.MINI : '[%(asctime)s] [%(levelname)8s] %(host)s %(status)s %(product)s %(message)s'})
try:
levelnames = logging._levelToName
except AttributeError:
levelnames = logging._levelNames
levelnum = [k for k in levelnames if k != 0]
form0 = '%(asctime)s %(levelname)-8s %(message)s'
form1 = '[%(asctime)s] [%(levelname)-8s] %(host)s %(status)s %(product)s %(message)s'
levelformdict = {}
for num in levelnum:
if num != logging.CRITICAL + 10:
levelformdict[num] = form0
else:
levelformdict[num] = form1
formatter = LevelFormatter(levelformdict)
log_handler.setFormatter(formatter)
# Attach.
log_obj.setLevel(config['loglevel'])

View File

@ -119,7 +119,7 @@ def server_options():
def server_check():
# Setup hidden or not messages.
ShellMessage.view = ( False if srv_config['logfile'] == 'STDOUT' else True )
# Create log.
# Create log.
logger_create(loggersrv, srv_config, mode = 'a')
# Random HWID.
@ -180,7 +180,7 @@ def server_create():
socketserver.TCPServer.allow_reuse_address = True
server = socketserver.TCPServer((srv_config['ip'], srv_config['port']), kmsServer)
server.timeout = srv_config['timeout']
loggersrv.info("\n\nTCP server listening at %s on port %d." % (srv_config['ip'], srv_config['port']))
loggersrv.info("TCP server listening at %s on port %d." % (srv_config['ip'], srv_config['port']))
loggersrv.info("HWID: %s" % deco(binascii.b2a_hex(srv_config['hwid']), 'utf-8').upper())
return server