Stop using undocumented DNF logging API

DNF doesn't want users to access base.logging anymore.

Lorax already takes over the "dnf" logger and directs it to ./dnf.log,
so it wasn't really being used.

This raises the debug level to DNF's custom DDEBUG, and sets it up so
that dnf.librepo.log and hawkey.log are next to dnf.log
This commit is contained in:
Brian C. Lane 2016-06-02 10:19:24 -07:00
parent cac5140e20
commit 5ef7c093b1

View File

@ -30,6 +30,8 @@ import tempfile
import shutil import shutil
import dnf import dnf
import dnf.logging
import librepo
import pylorax import pylorax
from pylorax.cmdline import lorax_parser from pylorax.cmdline import lorax_parser
@ -37,12 +39,16 @@ def setup_logging(opts):
pylorax.setup_logging(opts.logfile, log) pylorax.setup_logging(opts.logfile, log)
# dnf logging # dnf logging
dnf_log.setLevel(logging.DEBUG) dnf_log.setLevel(dnf.logging.DDEBUG)
logfile = os.path.abspath(os.path.dirname(opts.logfile))+"/dnf.log" logfile = os.path.abspath(os.path.dirname(opts.logfile))+"/dnf.log"
fh = logging.FileHandler(filename=logfile, mode="w") fh = logging.FileHandler(filename=logfile, mode="w")
fh.setLevel(logging.DEBUG) fh.setLevel(logging.NOTSET)
dnf_log.addHandler(fh) dnf_log.addHandler(fh)
# Setup librepo logging
logfile = os.path.abspath(os.path.dirname(opts.logfile))+"/dnf.librepo.log"
librepo.log_set_file(logfile)
def main(): def main():
parser = lorax_parser() parser = lorax_parser()
@ -80,7 +86,8 @@ def main():
dnfbase = get_dnf_base_object(installtree, opts.source, opts.mirrorlist, opts.repos, dnfbase = get_dnf_base_object(installtree, opts.source, opts.mirrorlist, opts.repos,
opts.enablerepos, opts.disablerepos, opts.enablerepos, opts.disablerepos,
dnftempdir, opts.proxy, opts.version, opts.cachedir) dnftempdir, opts.proxy, opts.version, opts.cachedir,
os.path.dirname(opts.logfile))
if dnfbase is None: if dnfbase is None:
print("error: unable to create the dnf base object", file=sys.stderr) print("error: unable to create the dnf base object", file=sys.stderr)
@ -126,7 +133,7 @@ def main():
def get_dnf_base_object(installroot, sources, mirrorlists=None, repos=None, def get_dnf_base_object(installroot, sources, mirrorlists=None, repos=None,
enablerepos=None, disablerepos=None, enablerepos=None, disablerepos=None,
tempdir="/var/tmp", proxy=None, releasever="21", tempdir="/var/tmp", proxy=None, releasever="21",
cachedir=None): cachedir=None, logdir=None):
""" Create a dnf Base object and setup the repositories and installroot """ Create a dnf Base object and setup the repositories and installroot
:param string installroot: Full path to the installroot :param string installroot: Full path to the installroot
@ -166,6 +173,7 @@ def get_dnf_base_object(installroot, sources, mirrorlists=None, repos=None,
if not os.path.isdir(cachedir): if not os.path.isdir(cachedir):
os.mkdir(cachedir) os.mkdir(cachedir)
if not logdir:
logdir = os.path.join(tempdir, "dnf.logs") logdir = os.path.join(tempdir, "dnf.logs")
if not os.path.isdir(logdir): if not os.path.isdir(logdir):
os.mkdir(logdir) os.mkdir(logdir)
@ -175,11 +183,6 @@ def get_dnf_base_object(installroot, sources, mirrorlists=None, repos=None,
conf.logdir = logdir conf.logdir = logdir
conf.cachedir = cachedir conf.cachedir = cachedir
# Turn off logging to the console
conf.debuglevel = 10
conf.errorlevel = 0
dnfbase.logging.setup_from_dnf_conf(conf)
conf.install_weak_deps = False conf.install_weak_deps = False
conf.releasever = releasever conf.releasever = releasever
conf.installroot = installroot conf.installroot = installroot