bugfix in sfi when running the discover subcommand
[sfa.git] / sfa / util / sfalogging.py
index 61d76a6..2b73b48 100644 (file)
@@ -23,6 +23,8 @@
 # IN THE WORK.
 #----------------------------------------------------------------------
 
+from __future__ import print_function
+
 import os, sys
 import traceback
 import logging, logging.handlers
@@ -48,9 +50,15 @@ class _SfaLogger:
         try:
             handler=logging.handlers.RotatingFileHandler(logfile,maxBytes=1000000, backupCount=5) 
         except IOError:
-            # This is usually a permissions error becaue the file is
+            # This is usually a permissions error because the file is
             # owned by root, but httpd is trying to access it.
-            tmplogfile=os.getenv("TMPDIR", "/tmp") + os.path.sep + os.path.basename(logfile)
+            tmplogfile=os.path.join(os.getenv("TMPDIR", os.getenv("TMP", os.path.normpath("/tmp"))), os.path.basename(logfile))
+            tmplogfile = os.path.normpath(tmplogfile)
+
+            tmpdir = os.path.dirname(tmplogfile)
+            if tmpdir and tmpdir != "" and not os.path.exists(tmpdir):
+                os.makedirs(tmpdir)
+
             # In strange uses, 2 users on same machine might use same code,
             # meaning they would clobber each others files
             # We could (a) rename the tmplogfile, or (b)
@@ -177,14 +185,14 @@ def profile(logger):
 
 
 if __name__ == '__main__': 
-    print 'testing sfalogging into logger.log'
+    print('testing sfalogging into logger.log')
     logger1=_SfaLogger('logger.log', loggername='std(info)')
     logger2=_SfaLogger('logger.log', loggername='error', level=logging.ERROR)
     logger3=_SfaLogger('logger.log', loggername='debug', level=logging.DEBUG)
     
     for (logger,msg) in [ (logger1,"std(info)"),(logger2,"error"),(logger3,"debug")]:
         
-        print "====================",msg, logger.logger.handlers
+        print("====================",msg, logger.logger.handlers)
    
         logger.enable_console()
         logger.critical("logger.critical")