From e5bd1b9249a8698585041d60d5fa6ed09d0879a6 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 4 Jun 2011 21:30:45 +0200 Subject: [PATCH] Added basic log page --- couchpotato/core/plugins/log/__init__.py | 6 +++++ couchpotato/core/plugins/log/main.py | 30 ++++++++++++++++++++++++ couchpotato/static/scripts/page/log.js | 21 ++++++++++++++++- 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 couchpotato/core/plugins/log/__init__.py create mode 100644 couchpotato/core/plugins/log/main.py diff --git a/couchpotato/core/plugins/log/__init__.py b/couchpotato/core/plugins/log/__init__.py new file mode 100644 index 00000000..33dcf338 --- /dev/null +++ b/couchpotato/core/plugins/log/__init__.py @@ -0,0 +1,6 @@ +from .main import Logging + +def start(): + return Logging() + +config = [] diff --git a/couchpotato/core/plugins/log/main.py b/couchpotato/core/plugins/log/main.py new file mode 100644 index 00000000..a3da5551 --- /dev/null +++ b/couchpotato/core/plugins/log/main.py @@ -0,0 +1,30 @@ +from couchpotato.api import addApiView +from couchpotato.core.helpers.request import jsonified, getParam +from couchpotato.core.plugins.base import Plugin +from couchpotato.environment import Env + + +class Logging(Plugin): + + def __init__(self): + addApiView('logging.get', self.get) + + def get(self): + + nr = int(getParam('nr', 0)) + path = '%s%s' % (Env.get('log_path'), '.%s' % nr if nr > 0 else '') + + # Reverse + f = open(path, 'r') + lines = [] + for line in f.readlines(): + lines.insert(0, line) + + log = '' + for line in lines: + log += line + + return jsonified({ + 'success': True, + 'log': log, + }) diff --git a/couchpotato/static/scripts/page/log.js b/couchpotato/static/scripts/page/log.js index 8c9be331..bdb41e93 100644 --- a/couchpotato/static/scripts/page/log.js +++ b/couchpotato/static/scripts/page/log.js @@ -3,6 +3,25 @@ Page.Log = new Class({ Extends: PageBase, name: 'log', - title: 'Show recent logs.' + title: 'Show recent logs.', + + indexAction: function(){ + var self = this; + + if(self.log) self.log.destroy(); + self.log = new Element('div.log', { + 'text': 'loading...' + }).inject(self.el) + + Api.request('logging.get', { + 'data': { + 'nr': 0 + }, + 'onComplete': function(json){ + self.log.set('html', '
'+json.log+'
') + } + }) + + } }) \ No newline at end of file