diff options
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. |