summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelie <elie>2013-03-15 18:40:33 +0000
committerelie <elie>2013-03-15 18:40:33 +0000
commit14342b12b11dc9a8d28e47100b473cfd3522e6ec (patch)
tree33be8ecbaa6dec47e8c708546b77b15a42c8a7b8
parent7683072d24ebcbf8c513ec3551e4e82afd705824 (diff)
downloadpysnmp-git-14342b12b11dc9a8d28e47100b473cfd3522e6ec.tar.gz
timestamps to log messages added
-rw-r--r--CHANGES.txt1
-rw-r--r--pysnmp/debug.py7
2 files changed, 7 insertions, 1 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index af2f1b0b..419e9fbf 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -6,6 +6,7 @@ Revision 4.2.5rc0
value what sometimes happens with buggy SNMP implementations.
- Standard SNMP Apps and built-in proxy now ignores malformed errorIndex
value.
+- Built-in logging now includes timestamps.
- Missing import added to oneliner auth module.
- The $PYSNMP_MIB_DIR & $PYSNMP_MIB_DIRS & $PYSNMP_MIB_PKGS path separator
made platform-specific.
diff --git a/pysnmp/debug.py b/pysnmp/debug.py
index 8d75b84f..ab002869 100644
--- a/pysnmp/debug.py
+++ b/pysnmp/debug.py
@@ -1,4 +1,5 @@
import sys
+import time
from pyasn1.compat.octets import octs2ints
from pysnmp import error
from pysnmp import __version__
@@ -54,7 +55,7 @@ class Debug:
return 'logger %s, flags %x' % (self._printer, self._flags)
def __call__(self, msg):
- self._printer('DBG: %s\n' % msg)
+ self._printer('DBG: [%s]: %s\n' % (self.timestamp(), msg))
def __and__(self, flag):
return self._flags & flag
@@ -62,6 +63,10 @@ class Debug:
def __rand__(self, flag):
return flag & self._flags
+ def timestamp(self):
+ return time.strftime('%H:%M:%S', time.localtime()) + \
+ '.%s' % int((time.time() % 1) * 1000)
+
# This will yield false from bitwise and with a flag, and save
# on unnecessary calls
logger = 0