1 '''
2 Defines the abstract base class for all L{AEMonitor} subclasses.
3
4 @author: Peter Parente
5 @organization: IBM Corporation
6 @copyright: Copyright (c) 2005, 2007 IBM Corporation
7
8 @author: Frank Zenker
9 @organization: IT Science Center Ruegen gGmbH, Germany
10 @copyright: Copyright (c) 2007, 2008 ITSC Ruegen
11
12 @license: I{The BSD License}
13 All rights reserved. This program and the accompanying materials are made
14 available under the terms of the BSD license which accompanies
15 this distribution, and is available at
16 U{http://www.opensource.org/licenses/bsd-license.php}
17 '''
18 import logging
19 from AccessEngine.AEMonitor import AEMonitor
20 from AccessEngine.AEConstants import LAYER_NAMES, SEMANTIC_NAMES
21 from AccessEngine import InputEvent, OutputEvent, AEDeviceEvent
22 from Tools.i18n import _
23 from AccessEngine import AEOutput
24
25 __uie__ = dict(kind='monitor')
26
27
28 log = logging.getLogger('TestLogMonitor')
29
31 '''
32 Logs information sent to output devices to using the SUE logging system. The
33 format of the output is intended to be used in automated regression testing.
34
35 @ivar last_dev: Name of the last device to which output was sent
36 @type last_dev: string
37 '''
39 '''
40 Initialize the monitor instance variables.
41 '''
42 super(TestLogMonitor, self).init()
43 self.last_dev = None
44
46 '''
47 Gets the localized name of this monitor.
48
49 @return: Monitor name
50 @rtype: string
51 '''
52 return _('Test logging monitor')
53
55 '''
56 Gets the event categories to be logged.
57
58 @return: Event categories
59 @rtype: list of string
60 '''
61 return AEOutput.getNames()
62
64 '''
65 Gets the default event categories to log.
66
67 @return: Event categories
68 @rtype: list of string
69 '''
70 return AEOutput.getDefaults()
71
73 '''
74 Gets the L{AEDevice.AEDeviceEvent} base class to indicate the type
75 of events this monitor wants to buffer.
76
77 @return: Base type of the event this monitor should buffer
78 @rtype: L{AEDevice.AEDeviceEvent} class
79 '''
80 return OutputEvent
81
82 - def show(self, event, value=None, dev=None, sem=None, layer=None):
83 '''
84 Buffers additional details about how the L{AEEvent} was handled by various
85 L{AEScript}s and tasks. The event is only provided as a means of filtering
86 information.
87
88 @param event: Wrapper giving the direction of a command (input/output) and
89 the command name
90 @type event: L{AEDevice.AEDeviceEvent}
91 @param value: Value of the command sent to/from a device
92 @type value: object
93 @param sem: Semantic constant indicating the kind of output
94 @type sem: integer
95 @param layer: Layer constant indicating from where the event came
96 @type layer: integer
97 @param dev: Device on which the event occurred
98 @type dev: L{AEInput} or L{AEOutput}
99 @raise IOError: When the monitor is no longer accepting data to buffer
100 '''
101 if not self.isInitialized():
102 raise IOError
103
104 if dev and dev.getName() != self.last_dev:
105
106 name = dev.getName()
107 self.last_dev = name
108 log.info('\n{device: %s}' % name)
109
110
111 sem = SEMANTIC_NAMES.get(sem)
112 try:
113 layer = LAYER_NAMES[layer]
114 except TypeError:
115 layer = 'None'
116 log.info('{%s: %s %s} %s', event.getName(), sem, layer, str(value))
117