From c8e77101611f6dc1c84529f3981fbbdc99dd537e Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 13 Jun 2008 16:24:29 +0000 Subject: [PATCH] added activity logging ability. activity logging any REQUEST messages that come through the translator git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1345 9efc2488-bf62-4759-914b-345cdb29e865 --- src/python/osrf/const.py | 2 ++ src/python/osrf/http_translator.py | 26 ++++++++++++++++++++++++-- src/python/osrf/log.py | 8 ++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/python/osrf/const.py b/src/python/osrf/const.py index ce1055b..d888b75 100644 --- a/src/python/osrf/const.py +++ b/src/python/osrf/const.py @@ -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 diff --git a/src/python/osrf/http_translator.py b/src/python/osrf/http_translator.py index 6525e56..654cf00 100644 --- a/src/python/osrf/http_translator.py +++ b/src/python/osrf/http_translator.py @@ -2,7 +2,7 @@ import sys, os, time, md5, random 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 @@ class HTTPTranslator(object): 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 @@ class HTTPTranslator(object): 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 @@ class HTTPTranslator(object): 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)) diff --git a/src/python/osrf/log.py b/src/python/osrf/log.py index ad2f0af..a64d8a4 100644 --- a/src/python/osrf/log.py +++ b/src/python/osrf/log.py @@ -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 @@ def log_warn(debug_str): __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 @@ def __log(level, msg): 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 @@ def __log_syslog(level, msg): 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 -- 2.11.0