Add logging support to storage.
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Sun, 21 Aug 2011 15:41:37 +0000 (18:41 +0300)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Sun, 21 Aug 2011 15:41:37 +0000 (18:41 +0300)
ppf/new/storage.py

index e8c7750..997db03 100644 (file)
@@ -6,6 +6,31 @@ Storage class for P2P logging information.
 
 import os
 import os.path
+import re
+import logging
+
+#
+# Logging code heavily inspired by Logging HOWTO documentation:
+#     http://docs.python.org/dev/howto/logging.html#configuring-logging
+#
+
+# Create logger; default logging level is DEBUG.
+logger = logging.getLogger(__name__)
+logger.setLevel(logging.DEBUG)
+
+# Create console handler and set level to ERROR.
+ch = logging.StreamHandler()
+ch.setLevel(logging.ERROR)
+
+# Create formatter.
+formatter = logging.Formatter('%(filename)s:%(lineno)s - %(levelname)s: %(message)s')
+
+# Add formatter to console handler.
+ch.setFormatter(formatter)
+
+# Add console handler to logger.
+logger.addHandler(ch)
+
 
 message_types = {
         'CHOKE': {'id': 1, 'parameters': None},