Re: Proposal: Logging system rewrite
will guaraldi <[email protected]>
| Newsgroups | gmane.comp.web.pyblosxom.devel |
|---|---|
| Message-ID | <[email protected]> |
I'm so +1 on this, I'm at a loss for words.
On Fri, 1 Apr 2005, Steven Armstrong wrote:
>
> As I've once posted a while ago I'm not happy with how logging currently
> works. So I'ld like to propose the change described below.
>
> Problem
> -------
>
> Every new call to tools.make_logger 'hijackes' the tools.log function
> and points it to another file. The plugin loaded last wins and gets its
> message logged to the file it specified. Messages of all other plugins
> also end up in this file.
>
>
> Proposal
> --------
>
> Use only one logfile for pyblosxom and it's plugins. The path to this
> file should be set in config.py.
> e.g:
> py['log_file'] = "/tmp/pyblosxom.log"
>
> Optionally allow a plugin to create it's own logfile by passing a full
> path to the function/method/whatever that creates and returns the
> logger. This can be handy for development.
>
> The loglevel can be set in config.py, e.g:
> py['log_level'] = "debug"
>
> A log-record would be formatted like:
>
> DATETIME [LOGLEVEL] PLUGINNAME: MESSAGE
>
> e.g.:
> 2004-02-12 12:43:22 [INFO] COMMENTS: failed special number check--spam.
> 2004-02-12 12:45:25 [INFO] CACHE: rebuilding the index cache.
> 2004-02-12 12:46:26 [INFO] COMMENTS: comment posted.
> 2004-02-12 12:47:27 [ERROR] COMMENTS: Traceback (most recent call last):
> File "/home/willg/plpy/public_html/cgi-bin/pyblosxom.cgi", line 53, in ?
> p.run()
> File "/home/willg/pyblosxom/Pyblosxom/pyblosxom.py", line 128, in run
> blosxom_handler(self._request)
> File "/home/willg/pyblosxom/Pyblosxom/pyblosxom.py", line 719, in
> blosxom_handler
> renderer.render()
> File "/home/willg/blogdata/plugins/rss2renderer.py", line 197, in render
> self._createItem(self._content[count])
>
>
> Available loglevels are:
> 'FATAL', 'CRITICAL', 'ERROR', 'WARN', 'WARNING', 'INFO', 'DEBUG', 'NOTSET'
>
>
>
>
> API
> ---
>
> Get a logger instance:
> log = tools.getLogger()
>
> The getLogger function automatically detects the calling plugins name
> and uses that as PLUGINNAME.
>
> Get a logger instance with its own logfile:
> log = tools.getLogger(log_file="/path/to/logfile")
>
> If used like this, PLUGINNAME is ignored.
>
>
> Using the logger:
> log.info("Wabadabadu")
> log.debug("variable = %s, variable2 = %r", var1, var2)
> log.error("ups I did it again")
> log.error("ups I did it again", exc_info=True)
>
> For each loglevel there exists a corresponding method.
> The logger substitutes variables 2 to n into variable 1.
> Passing exc_info=True causes the logger to also log the traceback along
> with the given message.
>
>
> Log an exception:
> try:
> ...
> except FunkyException:
> tools.log_exception()
>
> This is just a shorhand for
> log.error("Exception occured", exc_info=True).
>
>
>
> Problems
> --------
>
> How does the tools modules get access to the config dict?
>
>
>
> Notes
> -----
>
> A while back I've been mailing with Will about all this. The ideas to
> log to just one file and how to format a log-message are his.
>
> With Python 2.3 it's a piece of cake to implement the above. Most of the
> used functionality is provided through the built in logging module.
> I've written a minimal Logger class that provides the needed
> functionality for older Python installations.
> The code to make this happen is actually allready written. Just needs a
> minor rewrite.
>
>
>
> I'ld really like to have this in CVS as soon as possible. I'm getting
> sick of comenting/uncomenting resp. adding/removing debug statements all
> over the place.
>
> What say you?
>
> Ideas? Improvements?
>
> cheers
> Steven
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by Demarc:
> A global provider of Threat Management Solutions.
> Download our HomeAdmin security software for free today!
> http://www.demarc.com/Info/Sentarus/hamr30
> _______________________________________________
> Pyblosxom-devel mailing list
> Pyblosxom-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/pyblosxom-devel
>
--
whatever it is, you can find it at http://www.bluesock.org/~willg/
except Will--you can only see him in real life.
-------------------------------------------------------
This SF.net email is sponsored by Demarc:
A global provider of Threat Management Solutions.
Download our HomeAdmin security software for free today!
http://www.demarc.com/Info/Sentarus/hamr30