change client-side logging to split files by severity and move them to the debug dir.  this is quite a bit more involved than the server-side change because of some buggy directory clearing code and various places that depended on the old configuration.

This also changes the TKO autoserv log viewers to point to the new .DEBUG and .ERROR autoserv logs.

Signed-off-by: Steve Howard <showard@google.com>


git-svn-id: http://test.kernel.org/svn/autotest/trunk@3266 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/bin/client_logging_config.py b/client/bin/client_logging_config.py
index 4281355..bdf1540 100644
--- a/client/bin/client_logging_config.py
+++ b/client/bin/client_logging_config.py
@@ -5,12 +5,15 @@
 class ClientLoggingConfig(logging_config.LoggingConfig):
     def add_debug_file_handlers(self, log_dir, log_name=None):
         if not log_name:
-            log_name = 'client.log'
-        self.add_file_handler(log_name, logging.DEBUG, log_dir=log_dir)
+            log_name = 'client'
+        self._add_file_handlers_for_all_levels(log_dir, log_name)
 
 
     def configure_logging(self, results_dir=None):
         super(ClientLoggingConfig, self).configure_logging(use_console=True)
 
         if results_dir:
-            self.add_debug_file_handlers(results_dir)
+            log_dir = os.path.join(results_dir, 'debug')
+            if not os.path.exists(log_dir):
+                os.mkdir(log_dir)
+            self.add_debug_file_handlers(log_dir)
diff --git a/client/bin/job.py b/client/bin/job.py
index 4ee03ba..11061d2 100755
--- a/client/bin/job.py
+++ b/client/bin/job.py
@@ -125,6 +125,9 @@
         if not os.path.exists(self.resultdir):
             os.makedirs(self.resultdir)
 
+        if not cont:
+            self._cleanup_results_dir()
+
         logging_manager.configure_logging(
                 client_logging_config.ClientLoggingConfig(),
                 results_dir=self.resultdir)
@@ -178,19 +181,6 @@
             if not os.path.exists(download):
                 os.mkdir(download)
 
-            # Clean up directory except for the client.log file that
-            # was initialized when job was instantiated anyway
-            client_logfile = os.path.join(self.resultdir, 'client.log')
-            if os.path.exists(self.resultdir):
-                list_files = glob.glob('%s/*' % self.resultdir)
-                for f in list_files:
-                    if f != client_logfile:
-                        if os.path.isdir(f):
-                            shutil.rmtree(f)
-                        elif os.path.isfile(f):
-                            os.remove(f)
-
-            os.makedirs(os.path.join(self.resultdir, 'debug'))
             os.makedirs(os.path.join(self.resultdir, 'analysis'))
 
             shutil.copyfile(self.control,
@@ -247,6 +237,17 @@
         self.config_set('boot.default_args', ' '.join(kernel_args))
 
 
+    def _cleanup_results_dir(self):
+        """Delete everything in resultsdir"""
+        assert os.path.exists(self.resultdir)
+        list_files = glob.glob('%s/*' % self.resultdir)
+        for f in list_files:
+            if os.path.isdir(f):
+                shutil.rmtree(f)
+            elif os.path.isfile(f):
+                os.remove(f)
+
+
     def disable_warnings(self, warning_type):
         self.record("INFO", None, None,
                     "disabling %s warnings" % warning_type,
diff --git a/client/bin/job_unittest.py b/client/bin/job_unittest.py
index c61f16f..cb15b99 100644
--- a/client/bin/job_unittest.py
+++ b/client/bin/job_unittest.py
@@ -65,6 +65,8 @@
         self.god.stub_class(boottool, 'boottool')
         self.god.stub_class(sysinfo, 'sysinfo')
 
+        self.god.stub_class_method(job.base_job, '_cleanup_results_dir')
+
 
     def tearDown(self):
         sys.stdout = sys.__stdout__
@@ -95,6 +97,8 @@
         # record
         os.path.exists.expect_call(resultdir).and_return(False)
         os.makedirs.expect_call(resultdir)
+        if not cont:
+            job.base_job._cleanup_results_dir.expect_call()
 
         utils.drop_caches.expect_call()
         self.job._load_state.expect_call()
@@ -114,8 +118,6 @@
             os.mkdir.expect_call(results)
             os.path.exists.expect_call(download).and_return(False)
             os.mkdir.expect_call(download)
-            os.path.exists.expect_call(resultdir).and_return(False)
-            os.makedirs.expect_call(os.path.join(resultdir, 'debug'))
             os.makedirs.expect_call(os.path.join(resultdir, 'analysis'))
             shutil.copyfile.expect_call(mock.is_string_comparator(),
                                  os.path.join(resultdir, 'control'))
diff --git a/client/bin/kernel.py b/client/bin/kernel.py
index dd6513b..dcfdf65 100755
--- a/client/bin/kernel.py
+++ b/client/bin/kernel.py
@@ -1,26 +1,19 @@
-import os, shutil, copy, pickle, re, glob, time
+import os, shutil, copy, pickle, re, glob, time, logging
 from autotest_lib.client.bin import kernel_config, os_dep, kernelexpand, test
 from autotest_lib.client.bin import utils
 from autotest_lib.client.common_lib import log, error, packages
 
 
-def _mark(filename, msg):
-    file = open(filename, 'a')
-    file.write(msg)
-    file.close()
-
-
 def tee_output_logdir_mark(fn):
     def tee_logdir_mark_wrapper(self, *args, **dargs):
         mark = self.__class__.__name__ + "." + fn.__name__
-        outfile = os.path.join(self.log_dir, 'client.log')
-        _mark(outfile, "--- START " + mark + " ---\n")
+        logging.info("--- START %s ---", mark)
         self.job.logging.tee_redirect_debug_dir(self.log_dir)
         try:
             result = fn(self, *args, **dargs)
         finally:
             self.job.logging.restore()
-            _mark(outfile, "--- END " + mark + " ---\n")
+            logging.info("--- END %s ---", mark)
 
         return result
 
diff --git a/client/bin/kernel_unittest.py b/client/bin/kernel_unittest.py
index 58986e2..8c220f6 100755
--- a/client/bin/kernel_unittest.py
+++ b/client/bin/kernel_unittest.py
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 
-import unittest, os, time, re, glob
+import unittest, os, time, re, glob, logging
 import common
 from autotest_lib.client.common_lib.test_utils import mock
 from autotest_lib.client.bin import kernel, job, utils, kernelexpand
@@ -10,6 +10,8 @@
     def setUp(self):
         self.god = mock.mock_god()
 
+        logging.disable(logging.CRITICAL)
+
         self.god.stub_function(time, "time")
         self.god.stub_function(os, "mkdir")
         self.god.stub_function(os, "chdir")
diff --git a/frontend/client/src/autotest/tko/TestDetailView.java b/frontend/client/src/autotest/tko/TestDetailView.java
index 4df2244..8e4d47e 100644
--- a/frontend/client/src/autotest/tko/TestDetailView.java
+++ b/frontend/client/src/autotest/tko/TestDetailView.java
@@ -177,11 +177,11 @@
 
     private void addLogViewers(String testName) {
         logPanel.clear();
-        addLogFileViewer(testName + "/debug/stdout", "Test stdout");
-        addLogFileViewer(testName + "/debug/stderr", "Test stderr");
+        addLogFileViewer(testName + "/debug/client.DEBUG", "Test debug log");
+        addLogFileViewer(testName + "/debug/client.ERROR", "Test error log");
         addLogFileViewer("status.log", "Job status log");
-        addLogFileViewer("debug/autoserv.stdout", "Job autoserv stdout");
-        addLogFileViewer("debug/autoserv.stderr", "Job autoserv stderr");
+        addLogFileViewer("debug/autoserv.DEBUG", "Job autoserv debug log");
+        addLogFileViewer("debug/autoserv.ERROR", "Job autoserv error log");
     }
 
     private void addLogFileViewer(String logPath, String logName) {
diff --git a/server/profiler.py b/server/profiler.py
index e4c0c5a..ccc5ce6 100644
--- a/server/profiler.py
+++ b/server/profiler.py
@@ -59,7 +59,7 @@
 def get_profiler_log_path(autodir):
     """Given the directory of a profiler client, find the client log path."""
     return os.path.join(PROFILER_TMPDIR, autodir, "results", "default",
-                        "client.log")
+                        "debug", "client.DEBUG")
 
 
 def get_profiler_results_dir(autodir):