diff options
author | Tiago Gomes <tiago.gomes@codethink.co.uk> | 2015-08-13 15:07:50 +0000 |
---|---|---|
committer | Tiago Gomes <tiago.gomes@codethink.co.uk> | 2015-09-01 15:19:06 +0000 |
commit | f68a622ea0ab438f699fcd5e29f6c4167c59029e (patch) | |
tree | 96b5141c4783bce51c3ce2901dbebc7fa5383e69 /morphlib/buildcommand.py | |
parent | 29d6b3d36e40317ab72bd543b7d644161906b723 (diff) | |
download | morph-f68a622ea0ab438f699fcd5e29f6c4167c59029e.tar.gz |
Improve build loggingtiagogomes/improve-debugging
Change-Id: If9a6b17797166c295f3c597cc6d17226d45957e7
Diffstat (limited to 'morphlib/buildcommand.py')
-rw-r--r-- | morphlib/buildcommand.py | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/morphlib/buildcommand.py b/morphlib/buildcommand.py index bb354b2f..86cb8ff8 100644 --- a/morphlib/buildcommand.py +++ b/morphlib/buildcommand.py @@ -362,17 +362,21 @@ class BuildCommand(object): use_chroot = True setup_mounts = True - staging_area = self.create_staging_area(source, - build_env, - use_chroot, - extra_env=extra_env, - extra_path=extra_path) + staging_area, sa_log_handler = self.create_staging_area( + source, + build_env, + use_chroot, + extra_env=extra_env, + extra_path=extra_path) self.install_dependencies(staging_area, deps, source) else: - staging_area = self.create_staging_area(source, build_env, False) + staging_area, sa_log_handler = self.create_staging_area( + source, + build_env, + False) self.build_and_cache(staging_area, source, setup_mounts) - self.remove_staging_area(staging_area) + self.remove_staging_area(staging_area, sa_log_handler) td = datetime.datetime.now() - starttime hours, remainder = divmod(int(td.total_seconds()), 60*60) @@ -445,19 +449,35 @@ class BuildCommand(object): extra_env={}, extra_path=[]): '''Create the staging area for building a single artifact.''' - self.app.status(msg='Creating staging area') staging_dir = tempfile.mkdtemp( dir=os.path.join(self.app.settings['tempdir'], 'staging')) + + sa_log_handler = logging.FileHandler('%s.build-log' % staging_dir) + fmt = self.app.setup_logging_format() + datefmt = self.app.setup_logging_timestamp() + sa_log_handler.setFormatter(logging.Formatter(fmt, datefmt)) + logging.getLogger().addHandler(sa_log_handler) + # Configure the logger to only record DEBUG messages the staging area + # log file if the build failed, or in the chunk cache directory if the + # build succeded + logging.getLogger().handlers[0].setLevel(logging.INFO) + logging.getLogger().setLevel(logging.INFO) + + self.app.status(msg='Creating staging area') staging_area = morphlib.stagingarea.StagingArea( self.app, source, staging_dir, build_env, use_chroot, extra_env, extra_path) - return staging_area - def remove_staging_area(self, staging_area): + + return staging_area, sa_log_handler + + def remove_staging_area(self, staging_area, sa_log_handler): '''Remove the staging area.''' self.app.status(msg='Removing staging area') staging_area.remove() + logging.getLogger().removeHandler(sa_log_handler) + logging.getLogger().handlers[0].setLevel(logging.DEBUG) # Nasty hack to avoid installing chunks built in 'bootstrap' mode in a # different stratum when constructing staging areas. |