Improve logging display
This commit is contained in:
@@ -52,7 +52,7 @@ class Log:
|
|||||||
"""
|
"""
|
||||||
print(
|
print(
|
||||||
Log.OKBLUE + msg +
|
Log.OKBLUE + msg +
|
||||||
" [" + Log.ENDC + ".." + Log.OKBLUE + "]", end=end)
|
" [" + Log.ENDC + ".." + Log.OKBLUE + "]" + Log.ENDC, end=end)
|
||||||
if log:
|
if log:
|
||||||
self.app.log.info(Log.OKBLUE + msg + Log.ENDC)
|
self.app.log.info(Log.OKBLUE + msg + Log.ENDC)
|
||||||
|
|
||||||
@@ -63,6 +63,17 @@ class Log:
|
|||||||
print(
|
print(
|
||||||
Log.OKBLUE + msg +
|
Log.OKBLUE + msg +
|
||||||
" [" + Log.ENDC + Log.OKGREEN + "OK" +
|
" [" + Log.ENDC + Log.OKGREEN + "OK" +
|
||||||
Log.ENDC + Log.OKBLUE + "]", end=end)
|
Log.ENDC + Log.OKBLUE + "]" + Log.ENDC, end=end)
|
||||||
if log:
|
if log:
|
||||||
self.app.log.info(Log.OKBLUE + msg + Log.ENDC)
|
self.app.log.info(Log.OKGREEN + msg + Log.ENDC)
|
||||||
|
|
||||||
|
def failed(self, msg, end='\n', log=True):
|
||||||
|
"""
|
||||||
|
Logs info messages after validation step
|
||||||
|
"""
|
||||||
|
print(
|
||||||
|
Log.OKBLUE + msg +
|
||||||
|
" [" + Log.ENDC + Log.FAIL + "OK" +
|
||||||
|
Log.ENDC + Log.OKBLUE + "]" + Log.ENDC, end=end)
|
||||||
|
if log:
|
||||||
|
self.app.log.info(Log.FAIL + msg + Log.ENDC)
|
||||||
|
|||||||
@@ -15,21 +15,21 @@ class WOService():
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
if service_name in ['nginx']:
|
if service_name in ['nginx']:
|
||||||
|
Log.wait(self, "Testing Nginx configuration ")
|
||||||
# Check Nginx configuration before executing command
|
# Check Nginx configuration before executing command
|
||||||
sub = subprocess.Popen('nginx -t', stdout=subprocess.PIPE,
|
sub = subprocess.Popen('nginx -t', stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE, shell=True)
|
stderr=subprocess.PIPE, shell=True)
|
||||||
output, error_output = sub.communicate()
|
output, error_output = sub.communicate()
|
||||||
if 'emerg' not in str(error_output):
|
if 'emerg' not in str(error_output):
|
||||||
|
Log.valide(self, "Testing Nginx configuration ")
|
||||||
|
Log.wait(self, "Starting Nginx ")
|
||||||
service_cmd = ('service {0} start'.format(service_name))
|
service_cmd = ('service {0} start'.format(service_name))
|
||||||
retcode = subprocess.getstatusoutput(service_cmd)
|
retcode = subprocess.getstatusoutput(service_cmd)
|
||||||
if retcode[0] == 0:
|
if retcode[0] == 0:
|
||||||
Log.info(self, "Starting Nginx " +
|
Log.valide(self, "Starting Nginx ")
|
||||||
"[" + Log.ENDC + "OK" + Log.OKBLUE + "]")
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
Log.info(
|
Log.failed(self, "Testing Nginx configuration ")
|
||||||
self, "Starting Nginx " + "[" + Log.FAIL +
|
|
||||||
"Failed" + Log.OKBLUE+"]")
|
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
service_cmd = ('service {0} start'.format(service_name))
|
service_cmd = ('service {0} start'.format(service_name))
|
||||||
@@ -76,32 +76,35 @@ class WOService():
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
if service_name in ['nginx']:
|
if service_name in ['nginx']:
|
||||||
|
Log.wait(self, "Testing Nginx configuration ")
|
||||||
# Check Nginx configuration before executing command
|
# Check Nginx configuration before executing command
|
||||||
sub = subprocess.Popen('nginx -t', stdout=subprocess.PIPE,
|
sub = subprocess.Popen('nginx -t', stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE, shell=True)
|
stderr=subprocess.PIPE, shell=True)
|
||||||
output, error_output = sub.communicate()
|
output, error_output = sub.communicate()
|
||||||
if 'emerg' not in str(error_output):
|
if 'emerg' not in str(error_output):
|
||||||
|
Log.valide(self, "Testing Nginx configuration ")
|
||||||
|
Log.wait(self, "Restarting Nginx ")
|
||||||
service_cmd = ('service {0} restart'.format(service_name))
|
service_cmd = ('service {0} restart'.format(service_name))
|
||||||
retcode = subprocess.getstatusoutput(service_cmd)
|
retcode = subprocess.getstatusoutput(service_cmd)
|
||||||
if retcode[0] == 0:
|
if retcode[0] == 0:
|
||||||
Log.info(self, "Restarting Nginx " +
|
Log.valide(self, "Restarting Nginx ")
|
||||||
"[" + Log.ENDC + "OK" + Log.OKBLUE + "]")
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
Log.info(self, "Restarting Nginx " + "[" + Log.FAIL +
|
Log.failed(self, "Testing Nginx configuration ")
|
||||||
"Failed" + Log.OKBLUE+"]")
|
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
service_cmd = ('service {0} restart'.format(service_name))
|
service_cmd = ('service {0} restart'.format(service_name))
|
||||||
Log.info(self, "Restart : {0:10}".format(
|
Log.wait(self, "Restarting {0:10}".format(
|
||||||
service_name), end='')
|
service_name))
|
||||||
retcode = subprocess.getstatusoutput(service_cmd)
|
retcode = subprocess.getstatusoutput(service_cmd)
|
||||||
if retcode[0] == 0:
|
if retcode[0] == 0:
|
||||||
Log.info(self, "[" + Log.ENDC + "OK" + Log.OKBLUE + "]")
|
Log.valide(self, "Restarting {0:10}".format(
|
||||||
|
service_name))
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
Log.debug(self, "{0}".format(retcode[1]))
|
Log.debug(self, "{0}".format(retcode[1]))
|
||||||
Log.info(self, "[" + Log.FAIL + "Failed" + Log.OKBLUE+"]")
|
Log.failed(self, "Restarting {0:10}".format(
|
||||||
|
service_name))
|
||||||
return False
|
return False
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
Log.debug(self, "{0} {1}".format(e.errno, e.strerror))
|
Log.debug(self, "{0} {1}".format(e.errno, e.strerror))
|
||||||
@@ -116,31 +119,33 @@ class WOService():
|
|||||||
try:
|
try:
|
||||||
if service_name in ['nginx']:
|
if service_name in ['nginx']:
|
||||||
# Check Nginx configuration before executing command
|
# Check Nginx configuration before executing command
|
||||||
|
Log.wait(self, "Testing Nginx configuration ")
|
||||||
sub = subprocess.Popen('nginx -t', stdout=subprocess.PIPE,
|
sub = subprocess.Popen('nginx -t', stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE, shell=True)
|
stderr=subprocess.PIPE, shell=True)
|
||||||
output, error_output = sub.communicate()
|
output, error_output = sub.communicate()
|
||||||
if 'emerg' not in str(error_output):
|
if 'emerg' not in str(error_output):
|
||||||
|
Log.valide(self, "Testing Nginx configuration ")
|
||||||
|
Log.wait(self, "Reloading Nginx ")
|
||||||
service_cmd = ('service {0} reload'.format(service_name))
|
service_cmd = ('service {0} reload'.format(service_name))
|
||||||
retcode = subprocess.getstatusoutput(service_cmd)
|
retcode = subprocess.getstatusoutput(service_cmd)
|
||||||
if retcode[0] == 0:
|
if retcode[0] == 0:
|
||||||
Log.info(self, "Reloading Nginx " +
|
Log.valide(self, "Reloading Nginx ")
|
||||||
"[" + Log.ENDC + "OK" + Log.OKBLUE + "]")
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
Log.info(
|
Log.failed(self, "Testing Nginx configuration ")
|
||||||
self, "Reloading Nginx " + "[" + Log.FAIL +
|
|
||||||
"Failed" + Log.OKBLUE+"]")
|
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
service_cmd = ('service {0} reload'.format(service_name))
|
service_cmd = ('service {0} reload'.format(service_name))
|
||||||
Log.info(self, "Reload : {0:10}".format(service_name), end='')
|
Log.wait(self, "Reloading {0:10}".format(
|
||||||
|
service_name))
|
||||||
retcode = subprocess.getstatusoutput(service_cmd)
|
retcode = subprocess.getstatusoutput(service_cmd)
|
||||||
if retcode[0] == 0:
|
if retcode[0] == 0:
|
||||||
Log.info(self, "[" + Log.ENDC + "OK" + Log.OKBLUE + "]")
|
Log.valide(self, "Reloading {0:10}".format(
|
||||||
return True
|
service_name))
|
||||||
else:
|
else:
|
||||||
Log.debug(self, "{0}".format(retcode[1]))
|
Log.debug(self, "{0}".format(retcode[1]))
|
||||||
Log.info(self, "[" + Log.FAIL + "Failed" + Log.OKBLUE+"]")
|
Log.failed(self, "Reloading {0:10}".format(
|
||||||
|
service_name))
|
||||||
return False
|
return False
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
Log.debug(self, "{0}".format(e))
|
Log.debug(self, "{0}".format(e))
|
||||||
|
|||||||
Reference in New Issue
Block a user