Re: tools.py: patch to fix make_log/log for python installations with logging module

Steven Armstrong <[email protected]>
Newsgroups gmane.comp.web.pyblosxom.devel
Message-ID <[email protected]>
Bob Ippolito wrote:
> It's not just clearer, but more correct, to use the named functions.  On 
> Win32, as far as Python is concerned, both '/' and '\\' are valid 
> separator characters.  Splitting on os.sep only considers '\\'.
> 
> -bob
> 
> On Dec 10, 2004, at 1:07 PM, Bill Mill wrote:
> 
>> Steven,
>>
>> looks nice, and that seems like a better log() function. If I could
>> make one suggestion, could you change the line:
>>
>> loggerName = filename.split(os.sep)[-1:][0].split(".")[0]
>>
>> to:
>>
>> logger_name = os.path.splitext(os.path.basename(filename))[0]
>>
>> It seems clearer to me if you use the named functions from os.path to
>> achieve the same thing. Just a thought.
>>
>> Peace
>> Bill Mill
>> bill.mill at gmail.com
>>

Hi Bill
Hi Bob

Thanks for the input. Here's a corrected patch.

btw:
Is it a personal preference to change loggerName to logger_name or is 
there some convention when to use what? Like with methodname vs module 
function?

cheers
Steven
tools.py.diff (text/plain, 1.1 KB)
Index: tools.py
===================================================================
RCS file: /cvsroot/pyblosxom/pyblosxom/Pyblosxom/tools.py,v
retrieving revision 1.37
diff -u -r1.37 tools.py
--- tools.py	8 Dec 2004 01:20:07 -0000	1.37
+++ tools.py	10 Dec 2004 20:09:51 -0000
@@ -511,15 +511,21 @@
             f.write("\n")
             f.close()
     else:
-        logger = logging.getLogger('trackback')
+        # if all loggers have the same name,
+        # everything is logged to all files.
+        logger_name = os.path.splitext(os.path.basename(filename))[0]
+        logger = logging.getLogger(logger_name)
         hdlr = logging.FileHandler(filename)
         formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
         hdlr.setFormatter(formatter)
         logger.addHandler(hdlr) 
         logger.setLevel(logging.INFO)
 
-        def log(str):
-            logger.info(str)
+        def log(*args):
+            # adjusted to match the 'manual' log func
+            for i in args:
+                logger.info(repr(i))
+
 
 
 def update_static_entry(cdict, entry_filename):
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.