add logging

Signed-off-by: Adam Stokes <adam.stokes@ubuntu.com>
This commit is contained in:
Adam Stokes 2015-06-23 13:02:01 -04:00
parent e52aa70377
commit d480c49415
7 changed files with 54 additions and 14 deletions

1
.gitignore vendored
View File

@ -58,3 +58,4 @@ target/
# subiquity installer images # subiquity installer images
installer/*.img installer/*.img
logs/*

View File

@ -16,11 +16,12 @@
import argparse import argparse
import sys import sys
import logging
import urwid import urwid
import urwid.curses_display import urwid.curses_display
from subiquity.palette import STYLES, STYLES_MONO from subiquity.palette import STYLES, STYLES_MONO
from subiquity.controllers.welcome import WelcomeController
from subiquity.app import Application from subiquity.app import Application
from subiquity.log import setup_logger
def parse_options(argv): def parse_options(argv):
@ -35,6 +36,9 @@ def parse_options(argv):
def main(): def main():
opts = parse_options(sys.argv[1:]) opts = parse_options(sys.argv[1:])
setup_logger()
logger = logging.getLogger('subiquity')
if opts.run_on_serial: if opts.run_on_serial:
# screen = urwid.curses_display.Screen() # screen = urwid.curses_display.Screen()
screen = urwid.raw_display.Screen() screen = urwid.raw_display.Screen()

View File

@ -28,7 +28,7 @@ class Application:
def __init__(self, screen, opts): def __init__(self, screen, opts):
self.screen = screen self.screen = screen
self.opts = opts self.opts = opts
self.initial_controller = Routes.first() self.welcome_controller = Routes.first()
# Setup eventloop # Setup eventloop
self.loop = self._build_loop() self.loop = self._build_loop()
@ -38,7 +38,7 @@ class Application:
""" Builds urwid eventloop, passing in itself to the controllers """ Builds urwid eventloop, passing in itself to the controllers
for further display manipulation for further display manipulation
""" """
return urwid.MainLoop(self.initial_controller(routes=Routes, return urwid.MainLoop(self.welcome_controller(routes=Routes,
application=self).show(), application=self).show(),
screen=self.screen, screen=self.screen,
unhandled_input=self.unhandled_input) unhandled_input=self.unhandled_input)

View File

@ -16,6 +16,9 @@
from subiquity.controllers import BaseController, BaseControllerError from subiquity.controllers import BaseController, BaseControllerError
from subiquity.views.installpath import InstallpathView from subiquity.views.installpath import InstallpathView
from subiquity.models.installpath import InstallpathModel from subiquity.models.installpath import InstallpathModel
import logging
log = logging.getLogger('subiquity.installpath')
class InstallpathController(BaseController): class InstallpathController(BaseController):
@ -23,6 +26,7 @@ class InstallpathController(BaseController):
controller_name = "Installation path controller" controller_name = "Installation path controller"
def show(self, *args, **kwds): def show(self, *args, **kwds):
log.debug("Loading install path controller")
model = InstallpathModel() model = InstallpathModel()
return InstallpathView(model, self.finish) return InstallpathView(model, self.finish)

View File

@ -33,6 +33,6 @@ class WelcomeController(BaseController):
"more previous controllers to render.") "more previous controllers to render.")
self.selected_language = language self.selected_language = language
# subprocess.check_call("/usr/local/bin/curtin_wrap.sh") # subprocess.check_call("/usr/local/bin/curtin_wrap.sh")
self.next_controller() return self.next_controller()
__controller_class__ = WelcomeController __controller_class__ = WelcomeController

41
subiquity/log.py Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
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

View File

@ -51,16 +51,6 @@ class Routes:
""" end of install, last controller """ """ end of install, last controller """
return cls.route(-1) 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 @classmethod
def next(cls): def next(cls):
cls.current_route_idx = cls.current_route_idx + 1 cls.current_route_idx = cls.current_route_idx + 1