From: Yuri T. <qar...@gm...> - 2008-10-06 19:16:47
|
What about something like this: if logger.level = logging.NOTSET : logger.setLevel(DEBUG) This way the caller can set the logging level before importing markdown: >>> import logging >>> logging.getLogger("MARKDOWN").setLevel(logging.critical) >>> import markdown >>> markdown.logger.level <function critical at 0xb7c19a3c> (I committed this change as 2c6a74f, in case you want to look at it. But feel free to revert if we come up with a better solution.) - yuri On Mon, Oct 6, 2008 at 11:31 AM, Waylan Limberg <wa...@gm...> wrote: > Mike thanks for the bug report on Ticket 18 [1]. I'm copying the list > with my response. > >> markdown.py has a hardcoded logging setting of DEBUG, >> which allows all DEBUG messages to go out to all >> configured handlers. There's then a comment which says >> something to the effect of "this is restricted by handlers >> later". I'd like to propose that this is the incorrect usage >> of logging > > Actually, based on my testing the current behavior is correct. Suppose > we set the logger to CRITICAL. Then, someone adds a handler (perhaps > that writes to a log file) set to DEBUG. Because the logger only > allows CRITICAL messages through, the handler would never receive > anything less than CRITICAL even though its set to DEBUG. That's > unacceptable - and why the logger is wide open and the handlers later > restrict the level. > > The intention is that users would set (and/or remove) handlers and set > the level for each handler as they need. In fact, we realize that the > StreamHandler will break in some web server environments (it's > indented for command line use) and may need to be removed/replaced > with a handler appropriate for your system. That's why we recently > adopted use of Python's logger rather than our own old inflexible > home-grown solution. It's much easier to override handlers than > monkeypatch the old system. > >> The workaround for now is that you have to hardcode a call >> to "logging.getLogger("MARKDOWN").setLevel(logging.WARN)" >> to silence the MARKDOWN logger in your application code > > Actually I envisioned something very similar, except altering the > *handler* attached to the logger, not the logger itself. Perhaps it's > not the most convenient (in that it doesn't integrate with your > environment's settings file), but a solution that will work in a > variety of different situations is certainly welcome. I'm not > personally familiar with Pylons and/or Paste, but would certainly like > to see easy use of markdown in such a context. At the same time, > markdown needs to continue to work as it does now from the command > line as well as in other environments. > > If anyone has any suggestions and/or solutions I'm all ears. > > [1]: http://www.freewisdom.org/projects/python-markdown/Tickets/000018 > > -- > ---- > Waylan Limberg > wa...@gm... > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Python-markdown-discuss mailing list > Pyt...@li... > https://lists.sourceforge.net/lists/listinfo/python-markdown-discuss > -- http://sputnik.freewisdom.org/ |