[PATCH] Add syslog logging support (#1153768)

Vratislav Podzimek vpodzime at redhat.com
Thu Oct 23 07:20:06 UTC 2014


On Wed, 2014-10-22 at 18:47 +0200, Martin Kolman wrote:
> Add an Initial Setup specific log handling module that
> forwards nicely formated log messages to the system log
> and also correctly maps message log levels to system log
> priorities (in journalctl: info & debug - no highlight, warning - bold,
> error & critical - red).
> 
> This finally makes it possible to report in detail what's going on during the Initial
> Setup run, with emphasis on providing enough information on problematic areas,
> such as Kickstart parsing.
> 
> BTW, to check for all Initial Setup log messages in Journal you can
> use the -u flag with the Initial Setup unit name:
> 
> journalctl -u initial-setup-graphical
> 
> or
> 
> journalctl -u initial-setup-text
> 
> Resolves: rhbz#1153768
> Signed-off-by: Martin Kolman <mkolman at redhat.com>
> ---
>  initial_setup/__main__.py          | 49 ++++++++++++++++++++++++++++++++++---
>  initial_setup/gui/spokes/eula.py   |  9 +++++++
>  initial_setup/initial_setup_log.py | 50 ++++++++++++++++++++++++++++++++++++++
>  initial_setup/product.py           |  5 +++-
>  initial_setup/tui/spokes/eula.py   |  8 ++++++
>  5 files changed, 116 insertions(+), 5 deletions(-)
>  create mode 100644 initial_setup/initial_setup_log.py
> 
> diff --git a/initial_setup/__main__.py b/initial_setup/__main__.py
> index 4b07386..f76a600 100644
> --- a/initial_setup/__main__.py
> +++ b/initial_setup/__main__.py
> @@ -3,22 +3,37 @@ import os
>  import sys
>  import signal
>  import pykickstart
> +import logging
>  from pyanaconda.users import Users
>  from initial_setup.post_installclass import InstallClass
> +from initial_setup import initial_setup_log
> +from pyanaconda import iutil
> +
> +INPUT_KICKSTART_PATH = "/root/anaconda-ks.cfg"
> +OUTPUT_KICKSTART_PATH = "/root/initial-setup-ks.cfg"
> +
> +# set root to "/", we are now in the installed system
> +iutil.setSysroot("/")
>  
>  signal.signal(signal.SIGINT, signal.SIG_IGN)
>  
> +initial_setup_log.init()
> +log = logging.getLogger("initial-setup")
> +
>  if "DISPLAY" in os.environ and os.environ["DISPLAY"]:
>      mode="gui"
>  else:
>      mode="tui"
>  
> +log.debug("display mode detected: %s", mode)
> +
>  if mode == "gui":
>      # We need this so we can tell GI to look for overrides objects
>      # also in anaconda source directories
>      import gi.overrides
>      for p in os.environ.get("ANACONDA_WIDGETS_OVERRIDES", "").split(":"):
>          gi.overrides.__path__.insert(0, p)
> +    log.debug("GI overrides imported")
>  
>  # set the root path to / so the imported spokes
>  # know where to apply their changes
> @@ -36,18 +51,24 @@ addon_paths = ["/usr/share/initial-setup/modules", "/usr/share/anaconda/addons"]
>  sys.path.extend(addon_paths)
>  
>  addon_module_paths = collect_addon_paths(addon_paths, mode)
> +log.info("found %d addon modules:", len(addon_module_paths))
> +for addon_path in addon_module_paths:
> +    log.debug(addon_path)
>  
>  # Too bad anaconda does not have modularized logging
> +log.debug("initializing the Anaconda log")
>  from pyanaconda import anaconda_log
>  anaconda_log.init()
>  
> 
>  # init threading before Gtk can do anything and before we start using threads
>  # initThreading initializes the threadMgr instance, import it afterwards
> +log.debug("initializing threading")
>  from pyanaconda.threads import initThreading
>  initThreading()
>  
>  # initialize network logging (needed by the Network spoke that may be shown)
> +log.debug("initializing network logging")
>  from pyanaconda.network import setup_ifcfg_log
>  setup_ifcfg_log()
>  
> @@ -71,18 +92,23 @@ commandMap = dict((k, kickstart.commandMap[k]) for k in kickstart_commands)
>  # Prepare new data object
>  data = kickstart.AnacondaKSHandler(addon_module_paths["ks"], commandUpdates=commandMap)
>  
> +log.info("parsing input kickstart %s", INPUT_KICKSTART_PATH)
>  try:
>      # Read the installed kickstart
>      parser = kickstart.AnacondaKSParser(data)
> -    parser.readKickstart("/root/anaconda-ks.cfg")
> +    parser.readKickstart(INPUT_KICKSTART_PATH)
> +    log.info("kickstart parsing done")
>  except pykickstart.errors.KickstartError as kserr:
> +    log.exception("kickstart parsing failed")
>      sys.exit(1)
>  
>  if mode == "gui":
>      try:
>          # Try to import IS gui specifics
> +        log.debug("trying to import GUI")
>          import gui
>      except ImportError:
> +        log.error("GUI import failed, falling back to TUI")
>          mode = "tui"
>  
>  if mode == "gui":
> @@ -92,6 +118,7 @@ if mode == "gui":
>      gui.InitialSetupGraphicalUserInterface.update_paths(addon_module_paths)
>  
>      # Initialize the UI
> +    log.debug("initializing GUI")
>      ui = gui.InitialSetupGraphicalUserInterface(None, None, InstallClass())
>  else:
>      # Import IS gui specifics
> @@ -101,21 +128,26 @@ else:
>      tui.InitialSetupTextUserInterface.update_paths(addon_module_paths)
>  
>      # Initialize the UI
> +    log.debug("initializing TUI")
>      ui = tui.InitialSetupTextUserInterface(None, None, None)
>  
>  # Pass the data object to user inteface
> +log.debug("setting up the UI")
>  ui.setup(data)
>  
>  # Start the application
> +log.info("starting the UI")
>  ret = ui.run()
>  
>  # TUI returns False if the app was ended prematurely
>  # all other cases return True or None
>  if ret == False:
>      if data.eula.agreed:
> +	log.info("EULA accepted, shuttong down")
>          sys.exit(0)
This looks like bad indentation (at least in my Evolution).

Otherwise this looks good to me.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list