save log file default when --release specified
authorGui Chen <gui.chen@intel.com>
Tue, 10 Jul 2012 10:35:44 +0000 (18:35 +0800)
committerGui Chen <gui.chen@intel.com>
Tue, 10 Jul 2012 10:35:44 +0000 (18:35 +0800)
Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/imager/baseimager.py
mic/msger.py

index 10f972a..e086255 100644 (file)
@@ -101,8 +101,6 @@ class BaseImageCreator(object):
             if 'release' in createopts and createopts['release']:
                 self.name += '-' + createopts['release']
 
-                # pending FEA: save log by default for --release
-
             if self.pack_to:
                 if '@NAME@' in self.pack_to:
                     self.pack_to = self.pack_to.replace('@NAME@', self.name)
@@ -1159,6 +1157,15 @@ class BaseImageCreator(object):
                 wf.write(fr.read().replace("@BUILD_ID@", release))
         outimages.append(new_kspath)
 
+        # save log file, logfile is only available in creator attrs
+        if hasattr(self, 'logfile') and not self.logfile:
+            log_path = _rpath(self.name + ".log")
+            # touch the log file, else outimages will filter it out
+            with open(log_path, 'w') as wf:
+                wf.write('')
+            msger.set_logfile(log_path)
+            outimages.append(_rpath(self.name + ".log"))
+
         # rename iso and usbimg
         for f in os.listdir(destdir):
             if f.endswith(".iso"):
index 33f4298..48bc40c 100644 (file)
@@ -82,16 +82,17 @@ def _general_print(head, color, msg = None, stream = None, level = 'normal'):
         errormsg = os.read(CATCHERR_BUFFILE_FD, size)
         os.ftruncate(CATCHERR_BUFFILE_FD, 0)
 
-    if LOG_FILE_FP:
-        if errormsg:
-            LOG_CONTENT += errormsg
-
-        save_msg = msg.strip() if msg else None
-        if save_msg:
-            global HOST_TIMEZONE
-            timestr = time.strftime("[%m/%d %H:%M:%S] ",
-                                    time.gmtime(time.time() - HOST_TIMEZONE))
-            LOG_CONTENT += timestr + save_msg + '\n'
+    # append error msg to LOG
+    if errormsg:
+        LOG_CONTENT += errormsg
+
+    # append normal msg to LOG
+    save_msg = msg.strip() if msg else None
+    if save_msg:
+        global HOST_TIMEZONE
+        timestr = time.strftime("[%m/%d %H:%M:%S] ",
+                                time.gmtime(time.time() - HOST_TIMEZONE))
+        LOG_CONTENT += timestr + save_msg + '\n'
 
     if errormsg:
         _color_print('', NO_COLOR, errormsg, stream, level)