[Freeipa-devel] Logging changes in master
John Dennis
jdennis at redhat.com
Thu Dec 1 14:39:46 UTC 2011
A few days ago changes were checked into the master branch to improve
the way logging works. The modules ipapython.ipa_log_manager and
ipapython.log_manager were added and contain extensive documentation
(links to their HTML version appear below). But you don't need to read
through it all, you just need to know a few basic facts for all code
going forward, items 1-3 are mandatory to know, the rest are helpful.
1) Never import the Python logging module, instead:
from ipapython.log_manager import *
2) Use of the global root logger has been replaced, instead of
logging.debug() use root_logger.debug(), etc.
3) Stand-alone programs should set up logging via this common utility,
standard_logging_setup()
4) You can now control which classes (e.g. loggers) emit debug messages,
it's no longer an all or nothing proposition, you can turn on debugging
for just the code you're working on (or other level messages). Just edit
one of the config files read by Env() and add a line like this:
log_logger_debug = comma separated list of regular expressions
where each regular expression matches a class (logger) name(s)
See IPALogManger.configure_from_env for details
5) The Env() config files now support the verbose flag to turn on info
level messages.
6) Avoid use of the global root logger if possible, instead use a logger
belonging to the logical code location.
If you have a class it's as simple as:
log_mgr.get_logger(self, True)
Now you're class will have .debug(), .info() etc. methods bound to it
and when you log your class name (or other name) will be visible (this
happens automatically for all plugins).
If you don't have a class to hang your logger on use a meaningful name
and create one, e.g.:
logger = log_mgr.get_logger('client_installer')
-or-
logger = log_mgr.get_logger(os.path.basename(sys.argv[0]))
HTML versions of the documentation can be found here:
http://jdennis.fedorapeople.org/log_manager_doc/
--
John Dennis <jdennis at redhat.com>
Looking to carve out IT costs?
www.redhat.com/carveoutcosts/
More information about the Freeipa-devel
mailing list