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
1 changed files with 15 additions and 12 deletions

View File

@ -30,6 +30,8 @@ import tempfile
import shutil
import dnf
import dnf.logging
import librepo
import pylorax
from pylorax.cmdline import lorax_parser
@ -37,12 +39,16 @@ def setup_logging(opts):
pylorax.setup_logging(opts.logfile, log)
# dnf logging
dnf_log.setLevel(logging.DEBUG)
dnf_log.setLevel(dnf.logging.DDEBUG)
logfile = os.path.abspath(os.path.dirname(opts.logfile))+"/dnf.log"
fh = logging.FileHandler(filename=logfile, mode="w")
fh.setLevel(logging.DEBUG)
fh.setLevel(logging.NOTSET)
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():
parser = lorax_parser()
@ -80,7 +86,8 @@ def main():
dnfbase = get_dnf_base_object(installtree, opts.source, opts.mirrorlist, opts.repos,
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:
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,
enablerepos=None, disablerepos=None,
tempdir="/var/tmp", proxy=None, releasever="21",
cachedir=None):
cachedir=None, logdir=None):
""" Create a dnf Base object and setup the repositories and installroot
:param string installroot: Full path to the installroot
@ -166,20 +173,16 @@ def get_dnf_base_object(installroot, sources, mirrorlists=None, repos=None,
if not os.path.isdir(cachedir):
os.mkdir(cachedir)
logdir = os.path.join(tempdir, "dnf.logs")
if not os.path.isdir(logdir):
os.mkdir(logdir)
if not logdir:
logdir = os.path.join(tempdir, "dnf.logs")
if not os.path.isdir(logdir):
os.mkdir(logdir)
dnfbase = dnf.Base()
conf = dnfbase.conf
conf.logdir = logdir
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.releasever = releasever
conf.installroot = installroot