use logger instead of print as often as possible
[myslice.git] / activity / __init__.py
index e8eb5c3..62fbc9e 100644 (file)
@@ -6,8 +6,6 @@
 # The secret is a 64 chars string that is used to sign the request
 # The generated signature is a SHA256 hes digest
 
-from __future__ import print_function
-
 import urllib, urllib2
 import threading
 import hmac
@@ -16,6 +14,8 @@ import base64
 import time
 import datetime
 from myslice.configengine import ConfigEngine
+from myslice.settings import logger
+
 
 config = ConfigEngine()
 if config.activity and config.activity.apikey :
@@ -39,10 +39,10 @@ else :
 def logWrite(request, action, message, objects = None):
     
     if not apikey :
-        print("===============>> activity: no apikey")
+        logger.info("===============>> activity: no apikey")
         return
     if not secret :
-        print("===============>> activity: no secret")
+        logger.info("===============>> activity: no secret")
         return
     
     timestamp = time.mktime(datetime.datetime.today().timetuple())
@@ -71,12 +71,11 @@ def logWrite(request, action, message, objects = None):
     
     try :
         result = urllib2.urlopen(server, urllib.urlencode(log))
-        print("===============>> activity: %s <%s> %s" % (action, request.user,message))
+        logger.info("===============>> activity: {} <{}> {}".format(action, request.user,message))
         content = result.read()
     except urllib2.URLError as e:
-        print("===============>> activity: connection to " + server + " impossible, could not log action")
-        print(e.strerror)
-        print("")
+        logger.error("===============>> activity: connection to {} impossible, could not log action".format(server))
+        logger.error(e.strerror)
 
 def log(request, action, message, objects = None):
     # Create a new thread in Daemon mode to send the log entry