From patchwork Tue Jun 22 01:52:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 107320 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o5M1qX8R008160 for ; Tue, 22 Jun 2010 01:52:33 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752630Ab0FVBwb (ORCPT ); Mon, 21 Jun 2010 21:52:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:27273 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752568Ab0FVBwb (ORCPT ); Mon, 21 Jun 2010 21:52:31 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5M1qToi029047 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 21 Jun 2010 21:52:30 -0400 Received: from localhost.localdomain (vpn-11-188.rdu.redhat.com [10.11.11.188]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5M1qRtj011261; Mon, 21 Jun 2010 21:52:28 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Michael Goldish Subject: [PATCH 01/13] KVM test: kvm_utils.py: add a primitive logging mechanism for kvm_subprocess Date: Mon, 21 Jun 2010 22:52:13 -0300 Message-Id: <1277171545-23003-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 22 Jun 2010 01:52:33 +0000 (UTC) diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index 040124b..367e1e5 100644 --- a/client/tests/kvm/kvm_utils.py +++ b/client/tests/kvm/kvm_utils.py @@ -733,6 +733,43 @@ def find_free_ports(start_port, end_port, count): return ports +# An easy way to log lines to files when the logging system can't be used + +_open_log_files = {} +_log_file_dir = "/tmp" + + +def log_line(filename, line): + """ + Write a line to a file. '\n' is appended to the line. + + @param filename: Path of file to write to, either absolute or relative to + the dir set by set_log_file_dir(). + @param line: Line to write. + """ + global _open_log_files, _log_file_dir + if filename not in _open_log_files: + path = get_path(_log_file_dir, filename) + try: + os.makedirs(os.path.dirname(path)) + except OSError: + pass + _open_log_files[filename] = open(path, "w") + timestr = time.strftime("%Y-%m-%d %H:%M:%S") + _open_log_files[filename].write("%s: %s\n" % (timestr, line)) + _open_log_files[filename].flush() + + +def set_log_file_dir(dir): + """ + Set the base directory for log files created by log_line(). + + @param dir: Directory for log files. + """ + global _log_file_dir + _log_file_dir = dir + + # The following are miscellaneous utility functions. def get_path(base_path, user_path):