From d67a733700a32f70c47e1975cac23a74e280e9ea Mon Sep 17 00:00:00 2001 From: Ruud Date: Wed, 5 Oct 2011 15:18:15 +0200 Subject: [PATCH] Clear log files --- couchpotato/core/plugins/log/main.py | 22 ++++++++++++++++++++++ couchpotato/core/plugins/log/static/log.js | 14 ++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/couchpotato/core/plugins/log/main.py b/couchpotato/core/plugins/log/main.py index 331dc2ee..3daeb35e 100644 --- a/couchpotato/core/plugins/log/main.py +++ b/couchpotato/core/plugins/log/main.py @@ -1,14 +1,19 @@ from couchpotato.api import addApiView from couchpotato.core.helpers.request import jsonified, getParam +from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin from couchpotato.environment import Env import os +import traceback + +log = CPLog(__name__) class Logging(Plugin): def __init__(self): addApiView('logging.get', self.get) + addApiView('logging.clear', self.clear) def get(self): @@ -42,3 +47,20 @@ class Logging(Plugin): 'log': log, 'total': total, }) + + def clear(self): + + for x in range(0, 50): + 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): + break + + return jsonified({ + 'success': True + }) diff --git a/couchpotato/core/plugins/log/static/log.js b/couchpotato/core/plugins/log/static/log.js index a91887b3..09ebed58 100644 --- a/couchpotato/core/plugins/log/static/log.js +++ b/couchpotato/core/plugins/log/static/log.js @@ -40,6 +40,20 @@ Page.Log = new Class({ } }).inject(nav); }; + + new Element('li', { + 'text': 'clear', + 'events': { + 'click': function(){ + Api.request('logging.clear', { + 'onComplete': function(){ + self.getLogs(0); + } + }); + + } + } + }).inject(nav) } });