Author: janne.t.harkonen
Date: Tue Mar 24 07:04:16 2009
New Revision: 1502
Modified:
trunk/src/robot/__init__.py
trunk/src/robot/output/abstractlogger.py
trunk/src/robot/output/monitor.py
trunk/src/robot/output/output.py
trunk/src/robot/output/systemlogger.py
Log:
Merge branch 'syslog'
Modified: trunk/src/robot/__init__.py
==============================================================================
--- trunk/src/robot/__init__.py (original)
+++ trunk/src/robot/__init__.py Tue Mar 24 07:04:16 2009
@@ -40,6 +40,7 @@
_run_or_rebot_from_cli(rebot, args, usage)
def _run_or_rebot_from_cli(method, cliargs, usage, **argparser_config):
+ SYSLOG.register_command_line_monitor()
SYSLOG.register_file_logger()
ap = utils.ArgumentParser(usage, utils.get_full_version())
try:
@@ -59,7 +60,6 @@
except (KeyboardInterrupt, SystemExit):
_exit(STOPPED_BY_USER, 'Execution stopped by user.')
except:
- raise
error, details = utils.get_error_details()
_exit(FRAMEWORK_ERROR, 'Unexpected error: %s' % error, details)
else:
@@ -82,9 +82,9 @@
pybot --log mylog.html /path/to/tests.html /path/to/tests2.html
"""
settings = RobotSettings(options)
- monitor = CommandLineMonitor(settings['MonitorWidth'],
settings['MonitorColors'])
- SYSLOG.register_logger(monitor)
- output = Output(monitor, settings)
+ SYSLOG.register_command_line_monitor(settings['MonitorWidth'],
+ settings['MonitorColors'])
+ output = Output(settings)
settings.report_possible_errors()
init_global_variables(settings)
_syslog_start_info('Robot', datasources, settings)
@@ -120,8 +120,7 @@
rebot --report myrep.html --log NONE /path/out1.xml /path/out2.xml
"""
settings = RebotSettings(options)
- monitor = CommandLineMonitor(settings['MonitorWidth'],
settings['MonitorColors'])
- SYSLOG.register_logger(monitor)
+ SYSLOG.register_command_line_monitor(colors=settings['MonitorColors'])
settings.report_possible_errors()
_syslog_start_info('Rebot', datasources, settings)
testoutput = RebotTestOutput(datasources, settings)
Modified: trunk/src/robot/output/abstractlogger.py
==============================================================================
--- trunk/src/robot/output/abstractlogger.py (original)
+++ trunk/src/robot/output/abstractlogger.py Tue Mar 24 07:04:16 2009
@@ -38,7 +38,7 @@
if int_value == old_int:
return level
- def write(self, msg, level='INFO', html=False):
+ def write(self, msg, level, html=False):
"""Implementing classes must override this or implement _write."""
if self._is_logged(level):
if not isinstance(msg, Message):
@@ -70,12 +70,6 @@
def error(self, msg):
self.write(msg, 'ERROR')
-
- def output_file(self, name, path):
- pass
-
- def close(self):
- pass
class Message:
Modified: trunk/src/robot/output/monitor.py
==============================================================================
--- trunk/src/robot/output/monitor.py (original)
+++ trunk/src/robot/output/monitor.py Tue Mar 24 07:04:16 2009
@@ -27,9 +27,9 @@
class CommandLineMonitor:
- def __init__(self, monitor_width=78, monitor_colors=True):
- self._width = monitor_width
- self._colors = monitor_colors
+ def __init__(self, width=78, colors=True):
+ self.width = width
+ self.colors = colors
self._started = False
def start_suite(self, suite):
@@ -71,7 +71,7 @@
stream.flush()
def _write_info(self, name, doc, start_suite=False):
- maxwidth = self._width
+ maxwidth = self.width
if not start_suite:
maxwidth -= len(' | PASS |')
info = self._get_info(name, doc, maxwidth)
@@ -95,7 +95,7 @@
self._write(message.strip())
def _write_separator(self, sep_char):
- self._write(sep_char * self._width)
+ self._write(sep_char * self.width)
def _highlight(self, text):
color = self._get_highlight_color(text)
@@ -103,7 +103,7 @@
return color + text + reset
def _get_highlight_color(self, text):
- if self._colors:
+ if self.colors:
if text in ['FAIL','ERROR']:
return ANSI_RED
elif text == 'WARN':
Modified: trunk/src/robot/output/output.py
==============================================================================
--- trunk/src/robot/output/output.py (original)
+++ trunk/src/robot/output/output.py Tue Mar 24 07:04:16 2009
@@ -30,9 +30,8 @@
class Output(AbstractLogger):
- def __init__(self, monitor, settings):
+ def __init__(self, settings):
AbstractLogger.__init__(self, settings['LogLevel'])
- self.monitor = monitor
self.logger = None
self.listeners = Listeners(settings['Listeners'])
self._execution_errors = _ExecutionErrorLogger()
@@ -75,7 +74,7 @@
if self._namegen is not None:
suite.namespace.variables.set_global('${LOG_FILE}',
self._namegen.get_name())
- self.monitor.start_suite(suite)
+ SYSLOG.monitor.start_suite(suite)
self.listeners.start_suite(suite)
if self._debugfile is not None:
self._debugfile.start_suite(suite)
@@ -88,7 +87,7 @@
orig_outpath = self._settings['Output']
suite.namespace.variables.set_global('${OUTPUT_FILE}',
orig_outpath)
self._create_split_log(outpath, suite)
- self.monitor.end_suite(suite)
+ SYSLOG.monitor.end_suite(suite)
self.listeners.end_suite(suite)
if self._debugfile is not None:
self._debugfile.end_suite(suite)
@@ -106,14 +105,14 @@
def start_test(self, test):
SYSLOG.info("Running test case '%s'" % test.name)
self.logger.start_test(test)
- self.monitor.start_test(test)
+ SYSLOG.monitor.start_test(test)
self.listeners.start_test(test)
if self._debugfile is not None:
self._debugfile.start_test(test)
def end_test(self, test):
self.logger.end_test(test)
- self.monitor.end_test(test)
+ SYSLOG.monitor.end_test(test)
self.listeners.end_test(test)
if self._debugfile is not None:
self._debugfile.end_test(test)
Modified: trunk/src/robot/output/systemlogger.py
==============================================================================
--- trunk/src/robot/output/systemlogger.py (original)
+++ trunk/src/robot/output/systemlogger.py Tue Mar 24 07:04:16 2009
@@ -18,6 +18,7 @@
from robot import utils
from abstractlogger import AbstractLogger, Message
+from monitor import CommandLineMonitor
class SystemLogger(AbstractLogger):
@@ -26,6 +27,7 @@
self._writers = []
self._output_filers = []
self._closers = []
+ self.monitor = None
def register_logger(self, *loggers):
for logger in loggers:
@@ -36,12 +38,27 @@
if hasattr(logger, 'close'):
self._closers.append(logger.close)
+ def register_command_line_monitor(self, width=78, colors=True):
+ if not self.monitor:
+ self.monitor = CommandLineMonitor(width, colors)
+ self.register_logger(self.monitor)
+ else:
+ self.monitor.width = width
+ self.monitor.colors = colors
+
def register_file_logger(self, path=None, level='INFO'):
if not path:
path = os.environ.get('ROBOT_SYSLOG_FILE', None)
level = os.environ.get('ROBOT_SYSLOG_LEVEL', level)
- if path:
- self.register_logger(_FileLogger(path, level))
+ if not path:
+ return
+ try:
+ logger = _FileLogger(path, level)
+ except:
+ self.error("Opening syslog file '%s' failed: %s"
+ % (path, utils.get_error_message()))
+ else:
+ self.register_logger(logger)
def write(self, message, level='INFO'):
msg = Message(message, level)
@@ -58,63 +75,6 @@
self.__init__()
-class _SystemLogger(AbstractLogger):
-
- def __init__(self, settings=None, monitor=None):
- AbstractLogger.__init__(self, 'WARN')
- self.messages = []
- self.listeners = None
- if settings is None:
- settings = RobotSettings()
- if monitor is None:
- self.monitor = CommandLineMonitor(settings['MonitorWidth'],
- settings['MonitorColors'])
- else:
- self.monitor = monitor
- try:
- self._file_logger =
self._get_file_logger(settings['SyslogFile'],
-
settings['SyslogLevel'])
- except:
- self._file_logger = None
- self.error("Opening syslog file '%s' failed: %s"
- % (settings['SyslogFile'],
utils.get_error_message()))
- robot.output.SYSLOG = self
-
- def register_listeners(self, listeners):
- self.listeners = listeners
-
- def _get_file_logger(self, path, level):
- if utils.eq(path, 'NONE'):
- return None
- return _FileLogger(path, level)
-
- def write(self, msg, level='INFO'):
- if self._file_logger is not None:
- self._file_logger.write(msg, level)
- AbstractLogger.write(self, msg, level)
-
- def _write(self, message):
- self.monitor.error_message(message.message, message.level)
- self.messages.append(message)
-
- def close(self):
- if self._file_logger is not None:
- self._file_logger.close()
- self._file_logger = None
-
- def serialize(self, serializer):
- serializer.start_syslog(self)
- for msg in self.messages:
- serializer.message(msg)
- serializer.end_syslog(self)
-
- def output_file(self, name, path):
- self.write('%s: %s' % (name, path))
- self.monitor.output_file(name, path)
- if self.listeners is not None:
- self.listeners.output_file(name, path)
-
-
class _FileLogger(AbstractLogger):
def __init__(self, path, level):
@@ -130,6 +90,9 @@
message.message)
self._writer.write(utils.unic(entry).encode('UTF-8'))
+ def output_file(self, name, path):
+ self.info('%s: %s' % (name, path))
+
def close(self):
self._writer.close()