Skip to content

Commit

Permalink
Stop using undocumented DNF logging API
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bcl committed Jun 2, 2016
1 parent ad4e730 commit 404d6a7
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/sbin/lorax
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,25 @@ import tempfile
import shutil

import dnf
import dnf.logging
import librepo
import pylorax
from pylorax.cmdline import lorax_parser

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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 404d6a7

Please sign in to comment.