~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/lib/sys_mgmt/logging_management.py

  • Committer: patrick crews
  • Date: 2011-01-15 21:27:41 UTC
  • mto: (2119.2.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 2121.
  • Revision ID: gleebix@gmail.com-20110115212741-htz3af0cib4fwdlv
Updated tree so that test-run.pl and test-run.py may live together in peace for a time

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python
 
2
# -*- mode: python; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
3
# vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
4
#
 
5
# Copyright (C) 2009 Sun Microsystems
 
6
#
 
7
# Authors:
 
8
#
 
9
#  Jay Pipes <joinfu@sun.com>
 
10
#  Monty Taylor <mordred@sun.com>
 
11
#
 
12
 
 
13
 
 
14
""" Simple replacement for python logging module that doesn't suck """
 
15
 
 
16
import time, sys
 
17
 
 
18
 
 
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.
 
24
 
 
25
        Also, this is the cleanest way I can think of to deal
 
26
        with test-reporting (again, multi-threaded and such
 
27
 
 
28
    """
 
29
 
 
30
    def __init__(self, variables):
 
31
 
 
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     
 
37
 
 
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)))
 
40
      self.log_file.flush()
 
41
 
 
42
    def setOutput(self,file_name):
 
43
      if file_name == 'stdout':
 
44
        self.log_file= sys.stdout
 
45
      else:
 
46
        self.log_file= open(variables['log_file'],'w+')
 
47
 
 
48
    def info(self,msg):
 
49
      self._write_message("INFO", msg)
 
50
 
 
51
    def warning(self,msg):
 
52
      self._write_message("WARNING", msg)
 
53
 
 
54
    def error(self,msg):
 
55
      self._write_message("ERROR", msg)
 
56
 
 
57
    def verbose(self,msg):
 
58
      self._write_message("VERBOSE", msg)
 
59
 
 
60
    def debug(self,msg):
 
61
      self._write_message("DEBUG", msg)
 
62
 
 
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)))
 
69
 
 
70
 
 
71
 
 
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
 
74
 
 
75
        """
 
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)
 
81
        if additional_output:
 
82
            additional_output=additional_output.split('\n')
 
83
            for line in additional_output:
 
84
                line = line.strip()
 
85
                self._write_message("",line)
 
86
 
 
87
    def write_report_header(self):
 
88
        self.write_thick_line()
 
89
        self.test_report("TEST NAME", "RESULT")
 
90
        self.write_thick_line()
 
91
 
 
92
    def write_thin_line(self):
 
93
        self._write_message("",self.thin_line)
 
94
 
 
95
    def write_thick_line(self):
 
96
        self._write_message("",self.thick_line)
 
97
 
 
98
 
 
99
 
 
100