if timeout is None:
timeout = defaultTimeout
json = to_json(val)
- osrf.log.osrfLogInternal("cache: %s => %s" % (str(key), json))
+ osrf.log.log_internal("cache: %s => %s" % (str(key), json))
return self.client.set(str(key), json, timeout)
def get(self, key):
obj = self.client.get(str(key))
- osrf.log.osrfLogInternal("cache: fetching %s => %s" % (str(key), obj))
+ osrf.log.log_internal("cache: fetching %s => %s" % (str(key), obj))
return to_object(obj or "null")
def delete(self, key):
- osrf.log.osrfLogInternal("cache: deleting %s" % str(key))
+ osrf.log.log_internal("cache: deleting %s" % str(key))
self.client.delete(str(key))
@staticmethod
'''
if self.service:
if self.recipient:
- osrf.log.osrfLogWarn("specifying both SERVICE and TO is not allowed")
+ osrf.log.log_warn("specifying both SERVICE and TO is not allowed")
return False
self.recipient = "%s@%s/%s" % \
(ROUTER_NAME, OSRF_DOMAIN, self.service)
if obj and obj['ip'] == self.remote_host and \
obj['jid'] == self.recipient:
return True
- osrf.log.osrfLogWarn("client [%s] attempted to send directly "
+ osrf.log.log_warn("client [%s] attempted to send directly "
"[%s] without a session" % (self.remote_host, self.recipient))
return False
# -----------------------------------------------------------------------
# Define wrapper functions for the log levels
# -----------------------------------------------------------------------
-def osrfLogInternal(s):
- __osrfLog(OSRF_LOG_INTERNAL, s)
+def log_internal(s):
+ __log(OSRF_LOG_INTERNAL, s)
def logDebug(s):
- __osrfLog(OSRF_LOG_DEBUG, s)
-def osrfLogInfo(s):
- __osrfLog(OSRF_LOG_INFO, s)
-def osrfLogWarn(s):
- __osrfLog(OSRF_LOG_WARN, s)
+ __log(OSRF_LOG_DEBUG, s)
+def log_info(s):
+ __log(OSRF_LOG_INFO, s)
+def log_warn(s):
+ __log(OSRF_LOG_WARN, s)
def logError(s):
- __osrfLog(OSRF_LOG_ERR, s)
+ __log(OSRF_LOG_ERR, s)
-def __osrfLog(level, msg):
+def __log(level, msg):
"""Builds the log message and passes the message off to the logger."""
global LOG_LEVEL, LOG_TYPE
self.receive_callback = func
def session_started(self):
- osrf.log.osrfLogInfo("Successfully connected to the opensrf network")
+ osrf.log.log_info("Successfully connected to the opensrf network")
self.authenticated()
self.stream.set_message_handler("normal", self.message_received)
self.isconnected = True
def send(self, message):
"""Sends the provided network message."""
- osrf.log.osrfLogInternal("jabber sending to %s: %s" % \
+ osrf.log.log_internal("jabber sending to %s: %s" % \
(message.recipient, message.body))
msg = Message(None, None, message.recipient, None, None, None, \
message.body, message.thread)
if stanza.get_type()=="headline":
return True
# check for errors
- osrf.log.osrfLogInternal("jabber received message from %s : %s"
+ osrf.log.log_internal("jabber received message from %s : %s"
% (stanza.get_from().as_utf8(), stanza.get_body()))
self.queue.append(NetworkMessage(stanza))
return True
act = self.get_stream().loop_iter(timeout)
endtime = time.time() - starttime
timeout -= endtime
- osrf.log.osrfLogInternal("exiting stream loop after %s seconds. "
+ osrf.log.log_internal("exiting stream loop after %s seconds. "
"act=%s, queue size=%d" % (str(endtime), act, len(self.queue)))
if not act:
self.idle()
def wait(self, timeout=120):
"""Wait up to <timeout> seconds for data to arrive on the network"""
- osrf.log.osrfLogInternal("Session.wait(%d)" % timeout)
+ osrf.log.log_internal("Session.wait(%d)" % timeout)
handle = osrf.net.get_network_handle()
handle.recv(timeout)
def set_remote_id(self, remoteid):
self.remote_id = remoteid
- osrf.log.osrfLogInternal("Setting request remote ID to %s" % self.remote_id)
+ osrf.log.log_internal("Setting request remote ID to %s" % self.remote_id)
def reset_remote_id(self):
"""Recovers the original remote id"""
self.remote_id = self.orig_remote_id
- osrf.log.osrfLogInternal("Resetting remote ID to %s" % self.remote_id)
+ osrf.log.log_internal("Resetting remote ID to %s" % self.remote_id)
def push_response_queue(self, message):
"""Pushes the message payload onto the response queue
try:
self.find_request(message.threadTrace()).pushResponse(message.payload())
except Exception, e:
- osrf.log.osrfLogWarn("pushing respond to non-existent request %s : %s" % (message.threadTrace(), e))
+ osrf.log.log_warn("pushing respond to non-existent request %s : %s" % (message.threadTrace(), e))
def find_request(self, rid):
"""Returns the original request matching this message's threadTrace."""
omessages = osrf.json.to_object(net_msg.body)
- osrf.log.osrfLogInternal("push(): received %d messages" \
+ osrf.log.log_internal("push(): received %d messages" \
% len(omessages))
# Pass each bundled opensrf message to the message handler
duration = time.time() - start
if isinstance(ses, osrf.ses.ServerSession):
- osrf.log.osrfLogInfo("Message processing duration %f" % duration)
+ osrf.log.log_info("Message processing duration %f" % duration)
def handle_message(session, message):
- osrf.log.osrfLogInternal("handle_message(): processing message of "
+ osrf.log.log_internal("handle_message(): processing message of "
"type %s" % message.type())
if isinstance(session, osrf.ses.ClientSession):
status_code = int(message.payload().statusCode())
status_text = message.payload().status()
- osrf.log.osrfLogInternal("handle_message(): processing STATUS, "
+ osrf.log.log_internal("handle_message(): processing STATUS, "
"status_code = %d" % status_code)
if status_code == OSRF_STATUS_COMPLETE:
# The server has informed us that this request is complete
req = session.find_request(message.threadTrace())
if req:
- osrf.log.osrfLogInternal("marking request as complete: %d" % req.rid)
+ osrf.log.log_internal("marking request as complete: %d" % req.rid)
req.set_complete()
return