Edgewall Software

Changes between Version 27 and Version 28 of TracDev/PluginDevelopment


Ignore:
Timestamp:
Jan 7, 2010, 9:26:14 AM (11 years ago)
Author:
Christian Boos
Comment:

reformulate the #Debugging section (fixes #8912)

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/PluginDevelopment

    v27 v28  
    149149
    150150{{{
    151   env.log.info(varname) or self.env.log.info(varname)
     151#!python
     152  env.log.debug("*** Hey, varname is %r ***", varname)
    152153}}}
     154where `env` is the `Environment` instance.
    153155
    154 You need to turn on logging in the trac.ini file.  Info level log is not as often as debug level.  Thus it is very good way to debug the plug-in code.  However, you should use debug method if you want to leave the code when you finish developing the plug-in. 
     156If you are inside the methods of a `Component` subclass, better use:
     157{{{
     158#!python
     159  self.log.debug("Hey, varname is %r", varname)
     160}}}
     161This will implicitly use the `self.env` Environment, but your component name will now be used for the $module (see TracLogging#LogFormat). This makes it easier to identify the relevant debug lines.
     162
     163Note that there's no way to log something at the global level, outside the scope of a Trac environment, as the configuration of logging is done at that level and usually the log file is located in `$tracenv/log/trac.log`.
    155164
    156165----