From d480c49415af32064ce6b46dc5c8ec67d1eb2a35 Mon Sep 17 00:00:00 2001 From: Adam Stokes Date: Tue, 23 Jun 2015 13:02:01 -0400 Subject: [PATCH] add logging Signed-off-by: Adam Stokes --- .gitignore | 1 + bin/subiquity | 6 +++- subiquity/app.py | 4 +-- subiquity/controllers/installpath.py | 4 +++ subiquity/controllers/welcome.py | 2 +- subiquity/log.py | 41 ++++++++++++++++++++++++++++ subiquity/routes.py | 10 ------- 7 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 subiquity/log.py diff --git a/.gitignore b/.gitignore index 1dd9fde6..fd412777 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,4 @@ target/ # subiquity installer images installer/*.img +logs/* diff --git a/bin/subiquity b/bin/subiquity index 816b7733..56bd04ee 100755 --- a/bin/subiquity +++ b/bin/subiquity @@ -16,11 +16,12 @@ import argparse import sys +import logging import urwid import urwid.curses_display from subiquity.palette import STYLES, STYLES_MONO -from subiquity.controllers.welcome import WelcomeController from subiquity.app import Application +from subiquity.log import setup_logger def parse_options(argv): @@ -35,6 +36,9 @@ def parse_options(argv): def main(): opts = parse_options(sys.argv[1:]) + setup_logger() + logger = logging.getLogger('subiquity') + if opts.run_on_serial: # screen = urwid.curses_display.Screen() screen = urwid.raw_display.Screen() diff --git a/subiquity/app.py b/subiquity/app.py index 727b3605..8c0116fc 100644 --- a/subiquity/app.py +++ b/subiquity/app.py @@ -28,7 +28,7 @@ class Application: def __init__(self, screen, opts): self.screen = screen self.opts = opts - self.initial_controller = Routes.first() + self.welcome_controller = Routes.first() # Setup eventloop self.loop = self._build_loop() @@ -38,7 +38,7 @@ class Application: """ Builds urwid eventloop, passing in itself to the controllers for further display manipulation """ - return urwid.MainLoop(self.initial_controller(routes=Routes, + return urwid.MainLoop(self.welcome_controller(routes=Routes, application=self).show(), screen=self.screen, unhandled_input=self.unhandled_input) diff --git a/subiquity/controllers/installpath.py b/subiquity/controllers/installpath.py index 9d518b6f..d1b73cf4 100644 --- a/subiquity/controllers/installpath.py +++ b/subiquity/controllers/installpath.py @@ -16,6 +16,9 @@ from subiquity.controllers import BaseController, BaseControllerError from subiquity.views.installpath import InstallpathView from subiquity.models.installpath import InstallpathModel +import logging + +log = logging.getLogger('subiquity.installpath') class InstallpathController(BaseController): @@ -23,6 +26,7 @@ class InstallpathController(BaseController): controller_name = "Installation path controller" def show(self, *args, **kwds): + log.debug("Loading install path controller") model = InstallpathModel() return InstallpathView(model, self.finish) diff --git a/subiquity/controllers/welcome.py b/subiquity/controllers/welcome.py index 21dd8318..bdcb78e0 100644 --- a/subiquity/controllers/welcome.py +++ b/subiquity/controllers/welcome.py @@ -33,6 +33,6 @@ class WelcomeController(BaseController): "more previous controllers to render.") self.selected_language = language # subprocess.check_call("/usr/local/bin/curtin_wrap.sh") - self.next_controller() + return self.next_controller() __controller_class__ = WelcomeController diff --git a/subiquity/log.py b/subiquity/log.py new file mode 100644 index 00000000..a57f438e --- /dev/null +++ b/subiquity/log.py @@ -0,0 +1,41 @@ +# Copyright 2015 Canonical, Ltd. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import logging +import os +from logging.handlers import TimedRotatingFileHandler + + +def setup_logger(name=__name__): + LOGDIR = "logs" + LOGFILE = os.path.join(LOGDIR, "debug.log") + if not os.path.isdir(LOGDIR): + os.makedirs(LOGDIR) + log = TimedRotatingFileHandler(LOGFILE, + when='D', + interval=1, + backupCount=7) + log.setLevel('DEBUG') + log.setFormatter(logging.Formatter( + "[%(levelname)-4s: %(asctime)s, " + "%(filename)s:%(lineno)d] %(message)s", + datefmt='%m-%d %H:%M:%S')) + log_filter = logging.Filter(name='subiquity') + log.addFilter(log_filter) + + logger = logging.getLogger('') + logger.setLevel('DEBUG') + logger.addHandler(log) + return logger diff --git a/subiquity/routes.py b/subiquity/routes.py index 5792a13c..bbd04b76 100644 --- a/subiquity/routes.py +++ b/subiquity/routes.py @@ -51,16 +51,6 @@ class Routes: """ end of install, last controller """ return cls.route(-1) - @classmethod - def go_to_beginning(cls): - cls.current_route_idx = 0 - return cls.route(0) - - @classmethod - def go_to_end(cls): - cls.current_route_idx = len(cls.routes) - 1 - return cls.route(-1) - @classmethod def next(cls): cls.current_route_idx = cls.current_route_idx + 1