summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelie <elie>2013-03-15 18:40:33 +0000
committerelie <elie>2013-03-15 18:40:33 +0000
commit989a6dbe7394ff8276bc8a8e7c9d8dacddadc495 (patch)
tree5c7a1c63c4bf165ebac33c3825ef2a5f5846141b
parentdaad78aa25b58229a687a6a7e3c41557336f7907 (diff)
downloadpysnmp-989a6dbe7394ff8276bc8a8e7c9d8dacddadc495.tar.gz
timestamps to log messages added
-rw-r--r--CHANGES1
-rw-r--r--pysnmp/debug.py7
2 files changed, 7 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index af2f1b0..419e9fb 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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 8d75b84..ab00286 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