diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-10-28 01:39:02 -0600 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-10-28 01:39:02 -0600 |
commit | 316bd855d5720f4babfb79d20c391de3f8958a60 (patch) | |
tree | 6a26cd36959390fabf00fe1bba9963e2d8f87c36 /ipalib/util.py | |
parent | 2307d4ddd0409f00511c4d83ad7dab5e9d6d96df (diff) | |
download | freeipa-316bd855d5720f4babfb79d20c391de3f8958a60.tar.gz freeipa-316bd855d5720f4babfb79d20c391de3f8958a60.tar.xz freeipa-316bd855d5720f4babfb79d20c391de3f8958a60.zip |
Added util.configure_logging() function; API.bootstrap() now calls util.configure_logging()
Diffstat (limited to 'ipalib/util.py')
-rw-r--r-- | ipalib/util.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/ipalib/util.py b/ipalib/util.py index d7e2c2a4b..e65f15ca4 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -21,10 +21,13 @@ Various utility functions. """ -import krbV +import logging import os from os import path import imp +import krbV +from constants import LOGGING_CONSOLE_FORMAT, LOGGING_FILE_FORMAT + def xmlrpc_marshal(*args, **kw): """ @@ -99,3 +102,34 @@ def import_plugins_subpackage(name): for name in find_modules_in_dir(src_dir): full_name = '%s.%s' % (plugins.__name__, name) __import__(full_name) + + +def configure_logging(log_file, verbose): + """ + Configure standard logging. + """ + # Check that directory log_file is in exists: + log_dir = path.dirname(log_file) + if not path.isdir(log_dir): + os.makedirs(log_dir) + + # Set logging level: + level = logging.INFO + if verbose: + level -= 10 + + log = logging.getLogger('ipa') + + # Configure console handler + console = logging.StreamHandler() + console.setLevel(level) + console.setFormatter(logging.Formatter(LOGGING_CONSOLE_FORMAT)) + log.addHandler(console) + + # Configure file handler + file_handler = logging.FileHandler(log_file) + file_handler.setLevel(level) + file_handler.setFormatter(logging.Formatter(LOGGING_FILE_FORMAT)) + log.addHandler(file_handler) + + return log |