Commit 01d248fd authored by Luci Stanescu's avatar Luci Stanescu

Do not recompute process name and PID for each log entry

parent 640402a8
...@@ -64,6 +64,8 @@ class LogManager(object): ...@@ -64,6 +64,8 @@ class LogManager(object):
implements(IObserver) implements(IObserver)
def __init__(self): def __init__(self):
self.name = os.path.basename(sys.argv[0]).rsplit('.py', 1)[0]
self.pid = os.getpid()
self.msrp_level = log.level.INFO self.msrp_level = log.level.INFO
self.siptrace_file = Null self.siptrace_file = Null
self.msrptrace_file = Null self.msrptrace_file = Null
...@@ -115,7 +117,7 @@ class LogManager(object): ...@@ -115,7 +117,7 @@ class LogManager(object):
if notification.name not in ('SIPEngineLog', 'SIPEngineSIPTrace') and settings.logs.trace_notifications: if notification.name not in ('SIPEngineLog', 'SIPEngineSIPTrace') and settings.logs.trace_notifications:
message = 'Notification name=%s sender=%s data=%s' % (notification.name, notification.sender, pformat(notification.data)) message = 'Notification name=%s sender=%s data=%s' % (notification.name, notification.sender, pformat(notification.data))
try: try:
self.notifications_file.write('%s: %s\n' % (datetime.now(), message)) self.notifications_file.write('%s [%s %d]: %s\n' % (datetime.now(), self.name, self.pid, message))
self.notifications_file.flush() self.notifications_file.flush()
except Exception: except Exception:
pass pass
...@@ -147,7 +149,7 @@ class LogManager(object): ...@@ -147,7 +149,7 @@ class LogManager(object):
buf.append('--') buf.append('--')
message = '\n'.join(buf) message = '\n'.join(buf)
try: try:
self.siptrace_file.write('%s [%s %d]: %s\n' % (notification.data.timestamp, os.path.basename(sys.argv[0]).rstrip('.py'), os.getpid(), message)) self.siptrace_file.write('%s [%s %d]: %s\n' % (notification.data.timestamp, self.name, self.pid, message))
self.siptrace_file.flush() self.siptrace_file.flush()
except Exception: except Exception:
pass pass
...@@ -158,7 +160,7 @@ class LogManager(object): ...@@ -158,7 +160,7 @@ class LogManager(object):
return return
message = "(%(level)d) %(sender)14s: %(message)s" % notification.data.__dict__ message = "(%(level)d) %(sender)14s: %(message)s" % notification.data.__dict__
try: try:
self.pjsiptrace_file.write('%s [%s %d] %s\n' % (notification.data.timestamp, os.path.basename(sys.argv[0]).rstrip('.py'), os.getpid(), message)) self.pjsiptrace_file.write('%s [%s %d] %s\n' % (notification.data.timestamp, self.name, self.pid, message))
self.pjsiptrace_file.flush() self.pjsiptrace_file.flush()
except Exception: except Exception:
pass pass
...@@ -184,7 +186,7 @@ class LogManager(object): ...@@ -184,7 +186,7 @@ class LogManager(object):
dns.resolver.Timeout: 'no DNS response received, the query has timed out'} dns.resolver.Timeout: 'no DNS response received, the query has timed out'}
message += ' failed: %s' % message_map.get(notification.data.error.__class__, '') message += ' failed: %s' % message_map.get(notification.data.error.__class__, '')
try: try:
self.siptrace_file.write('%s [%s %d]: %s\n' % (notification.data.timestamp, os.path.basename(sys.argv[0]).rstrip('.py'), os.getpid(), message)) self.siptrace_file.write('%s [%s %d]: %s\n' % (notification.data.timestamp, self.name, self.pid, message))
self.siptrace_file.flush() self.siptrace_file.flush()
except Exception: except Exception:
pass pass
...@@ -200,7 +202,7 @@ class LogManager(object): ...@@ -200,7 +202,7 @@ class LogManager(object):
remote_address = '%s:%d' % (remote_address.host, remote_address.port) remote_address = '%s:%d' % (remote_address.host, remote_address.port)
message = '%s %s %s\n' % (local_address, arrow, remote_address) + notification.data.data message = '%s %s %s\n' % (local_address, arrow, remote_address) + notification.data.data
try: try:
self.msrptrace_file.write('%s [%s %d]: %s\n' % (notification.data.timestamp, os.path.basename(sys.argv[0]).rstrip('.py'), os.getpid(), message)) self.msrptrace_file.write('%s [%s %d]: %s\n' % (notification.data.timestamp, self.name, self.pid, message))
self.msrptrace_file.flush() self.msrptrace_file.flush()
except Exception: except Exception:
pass pass
...@@ -213,7 +215,7 @@ class LogManager(object): ...@@ -213,7 +215,7 @@ class LogManager(object):
return return
message = '%s%s' % (notification.data.level.prefix, notification.data.message) message = '%s%s' % (notification.data.level.prefix, notification.data.message)
try: try:
self.msrptrace_file.write('%s [%s %d]: %s\n' % (notification.data.timestamp, os.path.basename(sys.argv[0]).rstrip('.py'), os.getpid(), message)) self.msrptrace_file.write('%s [%s %d]: %s\n' % (notification.data.timestamp, self.name, self.pid, message))
self.msrptrace_file.flush() self.msrptrace_file.flush()
except Exception: except Exception:
pass pass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment