2
# -*- mode: python; c-basic-offset: 2; indent-tabs-mode: nil; -*-
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5
# Copyright (C) 2009 Sun Microsystems
9
# Jay Pipes <joinfu@sun.com>
10
# Monty Taylor <mordred@sun.com>
14
""" Simple replacement for python logging module that doesn't suck """
19
class loggingManager():
20
""" Class to deal with logging
21
We make a class just because we forsee ourselves being
22
multi-threaded and it will be nice to have a single
23
point of control for managing i/o.
25
Also, this is the cleanest way I can think of to deal
26
with test-reporting (again, multi-threaded and such
30
def __init__(self, variables):
32
self.log_file = sys.stdout
33
self.report_fmt = '{0:46} [ {1} ]'
34
self.report_started = 0
35
self.thick_line = '='*80
36
self.thin_line = '-'*80
38
def _write_message(self,level, msg):
39
self.log_file.write("%s %s: %s\n" % (time.strftime("%d %b %Y %H:%M:%S"), level, str(msg)))
42
def setOutput(self,file_name):
43
if file_name == 'stdout':
44
self.log_file= sys.stdout
46
self.log_file= open(variables['log_file'],'w+')
49
self._write_message("INFO", msg)
51
def warning(self,msg):
52
self._write_message("WARNING", msg)
55
self._write_message("ERROR", msg)
57
def verbose(self,msg):
58
self._write_message("VERBOSE", msg)
61
self._write_message("DEBUG", msg)
63
def debug_class(self,codeClass):
64
self._write_message("DEBUG**",codeClass)
65
skip_keys = ['skip_keys', 'debug', 'verbose']
66
for key, item in sorted(vars(codeClass).items()):
67
if key not in codeClass.skip_keys and key not in skip_keys:
68
self._write_message("DEBUG**",("%s: %s" %(key, item)))
72
def test_report(self, test_name, test_status, additional_output=None):
73
""" We use this method to deal with writing out the test report
76
if not self.report_started:
77
self.report_started = 1
78
self.write_report_header()
79
msg = self.report_fmt.format(test_name, test_status)
80
self._write_message("", msg)
82
additional_output=additional_output.split('\n')
83
for line in additional_output:
85
self._write_message("",line)
87
def write_report_header(self):
88
self.write_thick_line()
89
self.test_report("TEST NAME", "RESULT")
90
self.write_thick_line()
92
def write_thin_line(self):
93
self._write_message("",self.thin_line)
95
def write_thick_line(self):
96
self._write_message("",self.thick_line)