[Opensrf-commits] r1345 - trunk/src/python/osrf
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Jun 13 12:24:31 EDT 2008
Author: erickson
Date: 2008-06-13 12:24:29 -0400 (Fri, 13 Jun 2008)
New Revision: 1345
Modified:
trunk/src/python/osrf/const.py
trunk/src/python/osrf/http_translator.py
trunk/src/python/osrf/log.py
Log:
added activity logging ability. activity logging any REQUEST messages that come through the translator
Modified: trunk/src/python/osrf/const.py
===================================================================
--- trunk/src/python/osrf/const.py 2008-05-25 12:58:38 UTC (rev 1344)
+++ trunk/src/python/osrf/const.py 2008-06-13 16:24:29 UTC (rev 1345)
@@ -19,6 +19,8 @@
# -----------------------------------------------------------------------
# log levels
# -----------------------------------------------------------------------
+OSRF_LOG_ACT = -1
+OSRF_LOG_NONE = 0
OSRF_LOG_ERR = 1
OSRF_LOG_WARN = 2
OSRF_LOG_INFO = 3
Modified: trunk/src/python/osrf/http_translator.py
===================================================================
--- trunk/src/python/osrf/http_translator.py 2008-05-25 12:58:38 UTC (rev 1344)
+++ trunk/src/python/osrf/http_translator.py 2008-06-13 16:24:29 UTC (rev 1345)
@@ -2,7 +2,7 @@
from mod_python import apache, util
import osrf.system, osrf.cache, osrf.json, osrf.conf, osrf.net, osrf.log
from osrf.const import OSRF_MESSAGE_TYPE_DISCONNECT, OSRF_MESSAGE_TYPE_CONNECT, \
- OSRF_STATUS_CONTINUE, OSRF_STATUS_TIMEOUT, OSRF_MESSAGE_TYPE_STATUS
+ OSRF_STATUS_CONTINUE, OSRF_STATUS_TIMEOUT, OSRF_MESSAGE_TYPE_STATUS, OSRF_MESSAGE_TYPE_REQUEST
'''
@@ -234,6 +234,27 @@
elif osrf_msgs[0].type() == OSRF_MESSAGE_TYPE_DISCONNECT:
self.disconnect_only = True
+ '''
+ [76.202.6.250] [] open-ils.search open-ils.search.biblio.metarecord_to_records 0, {"format":null,"org":1,"depth":"0"}
+ '''
+ for msg in osrf_msgs:
+ if msg.type() == OSRF_MESSAGE_TYPE_REQUEST:
+ method = msg.payload()
+ params = osrf.json.to_json(method.params())
+ if len(params) == 2:
+ params = ''
+ else:
+ params = params[1:len(params)-1]
+
+ osrf.log.log_activity("[%s] [%s] %s %s %s" % (
+ self.remote_host,
+ '', # XXX auth token?
+ self.service,
+ method.method(),
+ params
+ ))
+
+
return True
@@ -258,6 +279,7 @@
obj = self.cache.get(self.thread)
if obj and obj['ip'] == self.remote_host and \
obj['jid'] == self.recipient:
+ self.service = obj['service']
return True
osrf.log.log_warn("client [%s] attempted to send directly "
"[%s] without a session" % (self.remote_host, self.recipient))
@@ -274,7 +296,7 @@
else:
self.apreq.content_type = JSON_CONTENT_TYPE
self.cache.put(self.thread, \
- {'ip':self.remote_host, 'jid': net_msg.sender}, CACHE_TIME)
+ {'ip':self.remote_host, 'jid': net_msg.sender, 'service':self.service}, CACHE_TIME)
osrf.log.log_debug("caching session [%s] for host [%s] and server "
" drone [%s]" % (self.thread, self.remote_host, net_msg.sender))
Modified: trunk/src/python/osrf/log.py
===================================================================
--- trunk/src/python/osrf/log.py 2008-05-25 12:58:38 UTC (rev 1344)
+++ trunk/src/python/osrf/log.py 2008-06-13 16:24:29 UTC (rev 1345)
@@ -16,7 +16,7 @@
import traceback, sys, os, re, threading, time
from osrf.const import OSRF_LOG_DEBUG, OSRF_LOG_ERR, OSRF_LOG_INFO, \
OSRF_LOG_INTERNAL, OSRF_LOG_TYPE_FILE, OSRF_LOG_TYPE_STDERR, \
- OSRF_LOG_TYPE_SYSLOG, OSRF_LOG_WARN
+ OSRF_LOG_TYPE_SYSLOG, OSRF_LOG_WARN, OSRF_LOG_ACT
LOG_SEMAPHORE = threading.BoundedSemaphore(value=1)
@@ -85,6 +85,8 @@
__log(OSRF_LOG_WARN, debug_str)
def log_error(debug_str):
__log(OSRF_LOG_ERR, debug_str)
+def log_activity(debug_str):
+ __log(OSRF_LOG_ACT, debug_str)
def __log(level, msg):
"""Builds the log message and passes the message off to the logger."""
@@ -112,6 +114,8 @@
lvl = 'WARN'
if level == OSRF_LOG_ERR:
lvl = 'ERR '
+ if level == OSRF_LOG_ACT:
+ lvl = 'ACT '
filename = FRGX.sub('', tb[0])
msg = '[%s:%d:%s:%s:%s:%s] %s' % (lvl, os.getpid(), filename, tb[1], threading.currentThread().getName(), _xid, msg)
@@ -134,7 +138,7 @@
slvl = syslog.LOG_DEBUG
if level == OSRF_LOG_INTERNAL:
slvl = syslog.LOG_DEBUG
- if level == OSRF_LOG_INFO:
+ if level == OSRF_LOG_INFO or level == OSRF_LOG_ACT:
slvl = syslog.LOG_INFO
if level == OSRF_LOG_WARN:
slvl = syslog.LOG_WARNING
More information about the opensrf-commits
mailing list