[PATCH 2/3] Move setup_logging into pylorax/__init__.py.
Brian C. Lane
bcl at redhat.com
Mon Jun 1 17:00:10 UTC 2015
On Fri, May 29, 2015 at 01:58:31PM -0400, Chris Lumens wrote:
> ---
> src/pylorax/__init__.py | 40 ++++++++++++++++++++++++++++++++++++++++
> src/sbin/livemedia-creator | 40 ++--------------------------------------
> 2 files changed, 42 insertions(+), 38 deletions(-)
>
> diff --git a/src/pylorax/__init__.py b/src/pylorax/__init__.py
> index 882be66..c903590 100644
> --- a/src/pylorax/__init__.py
> +++ b/src/pylorax/__init__.py
> @@ -25,6 +25,10 @@ import logging
> logger = logging.getLogger("pylorax")
> logger.addHandler(logging.NullHandler())
This should probably change to pylorax_log.
>
> +log = logging.getLogger("livemedia-creator")
This doesn't belong here, it should stay in lmc.
> +program_log = logging.getLogger("program")
> +pylorax_log = logging.getLogger("pylorax")
These are ok, and should be refactored with the lorax which also has a
setup_logging method.
I can handle doing that after this gets pushed.
> +
> import sys
> import os
> import configparser
> @@ -372,3 +376,39 @@ def get_buildarch(dbo):
> sys.exit(1)
>
> return buildarch
> +
> +
> +def setup_logging(logfile):
> + """
> + Setup the various logs
> +
> + :param logfile: filename to write the log to
> + :type logfile: string
> + """
> + if not os.path.isdir(os.path.abspath(os.path.dirname(logfile))):
> + os.makedirs(os.path.abspath(os.path.dirname(logfile)))
> +
> + # Setup logging to console and to logfile
> + log.setLevel(logging.DEBUG)
> + pylorax_log.setLevel(logging.DEBUG)
> +
> + sh = logging.StreamHandler()
> + sh.setLevel(logging.INFO)
> + fmt = logging.Formatter("%(asctime)s: %(message)s")
> + sh.setFormatter(fmt)
> + log.addHandler(sh)
> + pylorax_log.addHandler(sh)
> +
> + fh = logging.FileHandler(filename=logfile, mode="w")
> + fh.setLevel(logging.DEBUG)
> + fmt = logging.Formatter("%(asctime)s %(levelname)s %(name)s: %(message)s")
> + fh.setFormatter(fmt)
> + log.addHandler(fh)
> + pylorax_log.addHandler(fh)
> +
> + # External program output log
> + program_log.setLevel(logging.DEBUG)
> + f = os.path.abspath(os.path.dirname(logfile))+"/program.log"
> + fh = logging.FileHandler(filename=f, mode="w")
> + fh.setLevel(logging.DEBUG)
> + program_log.addHandler(fh)
Just setup pylorax_log and program_log here. Or maybe pass in an
external log handler from the caller to use instead of the global log?
--
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)
More information about the anaconda-patches
mailing list