Log errors via API

This commit is contained in:
Ruud
2012-01-14 11:46:53 +01:00
parent ab5d9e29d6
commit f1a682c026
2 changed files with 36 additions and 1 deletions
+20 -1
View File
@@ -1,5 +1,5 @@
from couchpotato.api import addApiView
from couchpotato.core.helpers.request import jsonified, getParam
from couchpotato.core.helpers.request import jsonified, getParam, getParams
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
from couchpotato.environment import Env
@@ -14,6 +14,7 @@ class Logging(Plugin):
def __init__(self):
addApiView('logging.get', self.get)
addApiView('logging.clear', self.clear)
addApiView('logging.log', self.log)
def get(self):
@@ -67,3 +68,21 @@ class Logging(Plugin):
return jsonified({
'success': True
})
def log(self):
params = getParams()
try:
log_message = 'API log: %s' % params
try:
getattr(log, params.get('type', 'error'))(log_message)
except:
log.error(log_message)
except:
log.error('Couldn\'t log via API: %s' % params)
return jsonified({
'success': True
})