source: src/logger.py@ 9:3dac12e8914d

Last change on this file since 9:3dac12e8914d was 9:3dac12e8914d, checked in by István Váradi <ivaradi@…>, 12 years ago

Flare calculations are handled and added some other printouts

File size: 2.2 KB
Line 
1# Module for the logging.
2
3#--------------------------------------------------------------------------------------
4
5import const
6
7import sys
8import time
9
10#--------------------------------------------------------------------------------------
11
12class Logger(object):
13 """The class with the interface to log the various events."""
14 _stages = { const.STAGE_BOARDING : "Boarding",
15 const.STAGE_PUSHANDTAXI : "Pushback and Taxi",
16 const.STAGE_TAKEOFF : "Takeoff",
17 const.STAGE_RTO : "RTO",
18 const.STAGE_CLIMB : "Climb",
19 const.STAGE_CRUISE : "Cruise",
20 const.STAGE_DESCENT : "Descent",
21 const.STAGE_LANDING : "Landing",
22 const.STAGE_TAXIAFTERLAND : "Taxi",
23 const.STAGE_PARKING : "Parking",
24 const.STAGE_GOAROUND : "Go-Around",
25 const.STAGE_END : "End" }
26
27 def __init__(self, output = sys.stdout):
28 """Construct the logger."""
29 self._score = 100.0
30 self._output = output
31
32 @staticmethod
33 def _getTimeStr(timestamp):
34 """Get the string representation of the given timestamp."""
35 return time.strftime("%H:%M:%S", time.gmtime(timestamp))
36
37 def message(self, timestamp, msg):
38 """Put a simple textual message into the log with the given timestamp."""
39 timeStr = Logger._getTimeStr(timestamp)
40 print >> self._output, timeStr + ":", msg
41 print timeStr + ":", msg
42
43 def debug(self, msg):
44 """Log a debug message."""
45 print >> self._output, "[DEBUG] ", msg
46 print "[DEBUG]", msg
47
48 def stage(self, timestamp, stage):
49 """Report a change in the flight stage."""
50 s = Logger._stages[stage] if stage in Logger._stages else "<Unknown>"
51 self.message(timestamp, "--- %s ---" % (s,))
52
53 def fault(self, timestamp, what, score):
54 """Report a fault."""
55 self._score -= score
56 self.message(timestamp, "%s (%f)" % (what, score))
57
58 def noGo(self, timestamp, what):
59 """Report a No-Go fault."""
60 self._score = -1
61 self.message(timestamp, "%s (NO GO)" % (what,))
62
63#--------------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.