2018-06-01 02:08:21 +05:00
|
|
|
import subprocess
|
|
|
|
|
import time
|
2019-03-26 16:19:03 +05:00
|
|
|
|
2018-06-01 02:08:21 +05:00
|
|
|
class cliLogger:
|
|
|
|
|
fileName = "/home/cyberpanel/error-logs.txt"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def writeforCLI(message, level, method):
|
|
|
|
|
try:
|
|
|
|
|
file = open(cliLogger.fileName, 'a')
|
|
|
|
|
file.writelines("[" + time.strftime(
|
2019-10-08 13:17:33 -04:00
|
|
|
"%m.%d.%Y_%H-%M-%S") + "] [" + level + ":" + method + "] " + message + "\n")
|
2018-06-01 02:08:21 +05:00
|
|
|
file.close()
|
|
|
|
|
file.close()
|
|
|
|
|
except IOError:
|
|
|
|
|
return "Can not write to error file!"
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def readLastNFiles(numberOfLines,fileName):
|
|
|
|
|
try:
|
|
|
|
|
|
2019-12-15 13:30:40 +05:00
|
|
|
lastFewLines = subprocess.check_output(["tail", "-n",str(numberOfLines),fileName]).decode("utf-8")
|
2018-06-01 02:08:21 +05:00
|
|
|
|
|
|
|
|
return lastFewLines
|
|
|
|
|
|
2019-12-10 15:09:10 +05:00
|
|
|
except subprocess.CalledProcessError as msg:
|
2018-06-01 02:08:21 +05:00
|
|
|
return "File was empty"
|