Clear log properly
This commit is contained in:
@@ -18,29 +18,33 @@ class Logging(Plugin):
|
|||||||
def get(self):
|
def get(self):
|
||||||
|
|
||||||
nr = int(getParam('nr', 0))
|
nr = int(getParam('nr', 0))
|
||||||
|
current_path = None
|
||||||
|
|
||||||
total = 1
|
total = 1
|
||||||
for x in range(0, 50):
|
for x in range(0, 50):
|
||||||
|
|
||||||
path = '%s%s' % (Env.get('log_path'), '.%s' % x if x > 0 else '')
|
path = '%s%s' % (Env.get('log_path'), '.%s' % x if x > 0 else '')
|
||||||
|
|
||||||
|
# Check see if the log exists
|
||||||
|
if not os.path.isfile(path):
|
||||||
|
total = x - 1
|
||||||
|
break
|
||||||
|
|
||||||
# Set current path
|
# Set current path
|
||||||
if x is nr:
|
if x is nr:
|
||||||
current_path = path
|
current_path = path
|
||||||
|
|
||||||
# Check see if the log exists
|
|
||||||
if not os.path.isfile(path):
|
|
||||||
total = x
|
|
||||||
break
|
|
||||||
|
|
||||||
# Reverse
|
|
||||||
f = open(current_path, 'r')
|
|
||||||
lines = []
|
|
||||||
for line in f.readlines():
|
|
||||||
lines.insert(0, line)
|
|
||||||
|
|
||||||
log = ''
|
log = ''
|
||||||
for line in lines:
|
if current_path:
|
||||||
log += line
|
# Reverse
|
||||||
|
f = open(current_path, 'r')
|
||||||
|
lines = []
|
||||||
|
for line in f.readlines():
|
||||||
|
lines.insert(0, line)
|
||||||
|
|
||||||
|
log = ''
|
||||||
|
for line in lines:
|
||||||
|
log += line
|
||||||
|
|
||||||
return jsonified({
|
return jsonified({
|
||||||
'success': True,
|
'success': True,
|
||||||
@@ -53,14 +57,20 @@ class Logging(Plugin):
|
|||||||
for x in range(0, 50):
|
for x in range(0, 50):
|
||||||
path = '%s%s' % (Env.get('log_path'), '.%s' % x if x > 0 else '')
|
path = '%s%s' % (Env.get('log_path'), '.%s' % x if x > 0 else '')
|
||||||
|
|
||||||
try:
|
|
||||||
os.remove(path)
|
|
||||||
except:
|
|
||||||
log.error('Couldn\'t delete file "%s": %s', (path, traceback.format_exc()))
|
|
||||||
|
|
||||||
if not os.path.isfile(path):
|
if not os.path.isfile(path):
|
||||||
break
|
break
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
# Create empty file for current logging
|
||||||
|
if x is 0:
|
||||||
|
self.createFile(path, '')
|
||||||
|
else:
|
||||||
|
os.remove(path)
|
||||||
|
|
||||||
|
except:
|
||||||
|
log.error('Couldn\'t delete file "%s": %s', (path, traceback.format_exc()))
|
||||||
|
|
||||||
return jsonified({
|
return jsonified({
|
||||||
'success': True
|
'success': True
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user