1- import abc
21import datetime
32import sys
43
5- import reframe .core .debug as debug
64import reframe .core .logging as logging
7-
8-
9- class Colorizer (abc .ABC ):
10- def __repr__ (self ):
11- return debug .repr (self )
12-
13- @abc .abstractmethod
14- def colorize (string , foreground , background ):
15- """Colorize a string.
16-
17- Keyword arguments:
18- string -- the string to be colorized
19- foreground -- the foreground color
20- background -- the background color
21- """
22-
23-
24- class AnsiColorizer (Colorizer ):
25- escape_seq = '\033 '
26- reset_term = '[0m'
27-
28- # Escape sequences for fore/background colors
29- fgcolor = '[3'
30- bgcolor = '[4'
31-
32- # color values
33- black = '0m'
34- red = '1m'
35- green = '2m'
36- yellow = '3m'
37- blue = '4m'
38- magenta = '5m'
39- cyan = '6m'
40- white = '7m'
41- default = '9m'
42-
43- def colorize (string , foreground , background = None ):
44- return (AnsiColorizer .escape_seq +
45- AnsiColorizer .fgcolor + foreground + string +
46- AnsiColorizer .escape_seq + AnsiColorizer .reset_term )
5+ import reframe .utility .color as color
476
487
498class PrettyPrinter :
509 """Pretty printing facility for the framework.
5110
52- Final printing is delegated to an internal logger, which is responsible for
53- printing both to standard output and in a special output file."""
11+ It takes care of formatting the progress output and adds some more
12+ cosmetics to specific levels of messages, such as warnings and errors.
13+
14+ The actual printing is delegated to an internal logger, which is
15+ responsible for printing.
16+ """
5417
5518 def __init__ (self ):
5619 self .colorize = True
5720 self .line_width = 78
5821 self .status_width = 10
59- self ._logger = logging .getlogger ()
60-
61- def __repr__ (self ):
62- return debug .repr (self )
6322
6423 def separator (self , linestyle , msg = '' ):
6524 if linestyle == 'short double line' :
@@ -82,13 +41,13 @@ def status(self, status, message='', just=None, level=logging.INFO):
8241 if self .colorize :
8342 status_stripped = status .strip ().lower ()
8443 if status_stripped == 'skip' :
85- status = AnsiColorizer .colorize (status , AnsiColorizer . yellow )
44+ status = color .colorize (status , color . YELLOW )
8645 elif status_stripped in ['fail' , 'failed' ]:
87- status = AnsiColorizer .colorize (status , AnsiColorizer . red )
46+ status = color .colorize (status , color . RED )
8847 else :
89- status = AnsiColorizer .colorize (status , AnsiColorizer . green )
48+ status = color .colorize (status , color . GREEN )
9049
91- self . _logger .log (level , '[ %s ] %s' % (status , message ))
50+ logging . getlogger () .log (level , '[ %s ] %s' % (status , message ))
9251
9352 def result (self , check , partition , environ , success ):
9453 if success :
@@ -107,24 +66,6 @@ def timestamp(self, msg='', separator=None):
10766 else :
10867 self .info (msg )
10968
110- def info (self , msg = '' ):
111- self ._logger .info (msg )
112-
113- def debug (self , msg = '' ):
114- self ._logger .debug (msg )
115-
116- def warning (self , msg ):
117- msg = AnsiColorizer .colorize ('%s: %s' % (sys .argv [0 ], msg ),
118- AnsiColorizer .yellow )
119- self ._logger .warning (msg )
120-
121- def error (self , msg ):
122- msg = AnsiColorizer .colorize ('%s: %s' % (sys .argv [0 ], msg ),
123- AnsiColorizer .red )
124- self ._logger .error (msg )
125-
126- def log_config (self , options ):
127- opt_list = [' %s=%s' % (attr , val )
128- for attr , val in sorted (options .__dict__ .items ())]
129-
130- self ._logger .debug ('configuration\n %s' % '\n ' .join (opt_list ))
69+ def __getattr__ (self , attr ):
70+ # delegate all other attribute lookup to the underlying logger
71+ return getattr (logging .getlogger (), attr )
0 commit comments