Revision: | 1.7 |
Committed: | Tue May 15 09:09:14 2007 UTC (17 years, 11 months ago) by slacapra |
Content type: | text/x-python |
Branch: | MAIN |
CVS Tags: | CRAB_2_6_0_pre2, CRAB_2_6_0_pre1, CRAB_2_5_1, CRAB_2_5_1_pre4, CRAB_2_5_1_pre3, CRAB_2_5_1_pre2, CRAB_2_5_1_pre1, CRAB_2_5_0, CRAB_2_5_0_pre7, CRAB_2_5_0_pre6, CRAB_2_5_0_pre5, CRAB_2_5_0_pre4, CRAB_2_5_0_pre3, CRAB_2_5_0_pre2, CRAB_2_5_0_pre1, CRAB_2_4_4, CRAB_2_4_4_pre6, CRAB_2_4_4_pre5, CRAB_2_4_4_pre4, CRAB_2_4_4_pre3, CRAB_2_4_4_pre2, CRAB_2_4_4_pre1, CRAB_2_4_3, CRAB_2_4_3_pre8, CRAB_2_4_3_pre7, CRAB_2_4_3_pre6, CRAB_2_4_3_pre5, CRAB_2_4_3_pre3, CRAB_2_4_3_pre2, CRAB_2_4_3_pre1, CRAB_2_4_2, CRAB_2_4_2_pre3, CRAB_2_4_2_pre2, CRAB_2_4_2_pre1, CRAB_2_4_1, CRAB_2_4_1_pre4, CRAB_2_4_1_pre3, CRAB_2_4_1_pre2, CRAB_2_4_1_pre1, CRAB_2_4_0_Tutorial, CRAB_2_4_0_Tutorial_pre1, CRAB_2_4_0, CRAB_2_4_0_pre9, CRAB_2_4_0_pre8, CRAB_2_4_0_pre7, CRAB_2_4_0_pre6, CRAB_2_4_0_pre5, CRAB_2_4_0_pre4, CRAB_2_4_0_pre3, CRAB_2_4_0_pre2, CRAB_2_4_0_pre1, CRAB_DLS_PHED1, CRAB_DLS_PHED, CRAB_2_3_2_Fnal, CRAB_2_3_2, CRAB_2_3_2_pre7, CRAB_2_3_2_pre5, CRAB_2_3_2_pre4, CRAB_2_3_2_pre3, CRAB_2_3_2_pre2, CRAB_2_3_2_pre1, CRAB_2_4_0_test, CRAB_2_3_1, CRAB_2_3_1_pre6, CRAB_2_3_1_pre5, CRAB_2_3_1_pre4, CRAB_2_3_1_pre3, CRAB_2_3_1_pre2, CRAB_2_3_1_pre1, CRAB_2_3_0, CRAB_2_3_0_pre6, CRAB_2_3_0_pre1, CRAB_2_2_2_pre5, CRAB_2_2_2_pre4, CRAB_2_2_2_pre3, CRAB_2_2_2_pre2, CRAB_2_2_2_pre1, CRAB_2_2_1, CRAB_2_2_1_pre6, CRAB_2_2_1_pre5, CRAB_2_2_1_pre4, PRODCOMMON_0_10_7_testCS2, CRAB_2_2_1_pre3, CRAB_2_2_1_pre2, CRAB_2_2_1_pre1, CRAB_2_2_0, CRAB_2_2_0_pre21, CRAB_2_2_0_pre19, CRAB_2_2_0_pre18, CRAB_2_2_0_pre17, CRAB_2_2_0_pre16, CRAB_2_2_0_pre15, CRAB_2_2_0_pre13, CRAB_2_2_0_pre12, CRAB_2_2_0_pre11, CRAB_2_2_0_pre10, bp_osg_bdii, CRAB_2_2_0_pre9, CRAB_2_2_0_pre8, CRAB_2_2_0_pre7, CRAB_2_1_2, CRAB_2_2_0_pre5, CRAB_2_1_2_pre2, CRAB_2_1_2_pre1, CRAB_2_2_0_pre4, CRAB_2_2_0_pre2, CRAB_2_1_1, CRAB_2_1_1_pre3, CRAB_2_2_0_pre1, CRAB_2_1_1_pre1, CRAB_2_1_0, CRAB_2_1_0_pre6, CRAB_2_1_0_pre5, CRAB_2_1_0_pre4, CRAB_2_1_0_pre3, CRAB_2_1_0_pre2, CRAB_2_1_0_pre1, CRAB_2_0_4, CRAB_2_0_4_pre2, CRAB_2_0_4_pre1, CRAB_2_0_3, CRAB_2_0_3_pre1, CRAB_2_0_2, CRAB_2_0_2_pre6, CRAB_2_0_2_pre5, CRAB_2_0_2_pre4, CRAB_2_0_2_pre3, CRAB_1_5_4_SLC3, CRAB_1_5_4_SLC3_pre4, CRAB_2_0_2_pre2, CRAB_2_0_2_pre1, CRAB_1_5_4_SLC3_pre3, CRAB_2_0_1, CRAB_1_5_4_SLC3_pre2, CRAB_2_0_1_pre1, CRAB_1_5_4_SLC3_pre1, CRAB_2_0_0, CRAB_2_0_0_pre10, CRAB_2_0_0_pre9, CRAB_1_5_4, CRAB_1_5_4_pre2, CRAB_1_5_4_pre1, CRAB_2_0_0_pre7, CRAB_2_0_0_pre6, CRAB_1_5_3, CRAB_1_5_3_pre5, CRAB_1_5_3_pre4, CRAB_2_0_0_pre5, CRAB_1_5_3_pre3, configure, CRAB_2_0_0_pre4, CRAB_1_5_3_pre2, CRAB_1_5_3_pre1, CRAB_2_0_0_pre3, CRAB_1_5_2, CRAB_2_0_0_pre2, CRAB_2_0_0_pre1, CRAB_1_5_1, CRAB_1_5_1_pre4, CRAB_1_5_1_pre3, CRAB_1_5_1_pre2 |
Branch point for: | AnaDataSet, CRAB_2_3_0_br, osg_bdii, CRAB_2_1_2_br, CRAB_2_1_1_pre2, CRAB_1_5_4_SLC3_pre4_br, CRAB_1_5_4_SLC3_start |
Changes since 1.6: | +0 -1 lines |
Log Message: | fix double free problem in -clean: need boss >= BOSS_4_3_3-sl3-sl4-pre2. Cleaner is now an Actor |
# | User | Rev | Content |
---|---|---|---|
1 | nsmirnov | 1.1 | import string |
2 | from crab_exceptions import * | ||
3 | from WorkSpace import WorkSpace | ||
4 | from threading import RLock | ||
5 | import common | ||
6 | |||
7 | class Logger : | ||
8 | |||
9 | #_instance = None | ||
10 | |||
11 | #def getInstance(): | ||
12 | # if not Logger._instance : | ||
13 | # Logger._instance = Logger() | ||
14 | # return Logger._instance | ||
15 | |||
16 | #getInstance = staticmethod(getInstance) | ||
17 | |||
18 | #def hasInstance(): | ||
19 | # return Logger._instance | ||
20 | |||
21 | #hasInstance = staticmethod(hasInstance) | ||
22 | |||
23 | def __init__(self): | ||
24 | #if Logger._instance: | ||
25 | # raise CrabException, 'Logger already exists.' | ||
26 | |||
27 | self.lock = RLock() | ||
28 | self.debug_level = 0 | ||
29 | self.flag_quiet = 0 | ||
30 | self.prog_name = common.prog_name | ||
31 | log_dir = common.work_space.logDir() | ||
32 | self.log_fname = log_dir+self.prog_name+'.log' | ||
33 | self.log_file = open(self.log_fname, 'a') | ||
34 | self.log_file.write('\n-------------------------------------------\n') | ||
35 | |||
36 | #Logger._instance = self | ||
37 | return | ||
38 | |||
39 | def __del__(self): | ||
40 | if not self.flag_quiet: | ||
41 | print self.prog_name+'. Log-file is '+self.log_fname | ||
42 | return | ||
43 | |||
44 | slacapra | 1.4 | def close(self): |
45 | self.log_file.close() | ||
46 | return | ||
47 | |||
48 | nsmirnov | 1.1 | def get(self): |
49 | """ | ||
50 | Returns list of lines in the log-file. | ||
51 | """ | ||
52 | logf = open(self.log_fname, 'r') | ||
53 | lines = logf.readlines() | ||
54 | logf.close() | ||
55 | return lines | ||
56 | |||
57 | def quiet(self, flag): | ||
58 | self.flag_quiet = flag | ||
59 | return | ||
60 | |||
61 | def flush(self): | ||
62 | self.log_file.flush() | ||
63 | return | ||
64 | |||
65 | def write(self, msg): | ||
66 | """ | ||
67 | Stores the given message into log-file. | ||
68 | """ | ||
69 | self.lock.acquire() | ||
70 | slacapra | 1.6 | self.log_file.write(msg+'\n') |
71 | nsmirnov | 1.1 | self.lock.release() |
72 | return | ||
73 | |||
74 | def message(self, msg): | ||
75 | """ | ||
76 | Prints the given message on a screen and stores it into log-file. | ||
77 | """ | ||
78 | if len(msg) == 0: return | ||
79 | self.lock.acquire() | ||
80 | nsmirnov | 1.2 | |
81 | # print whitespace first | ||
82 | nsmirnov | 1.1 | for i in range(len(msg)): |
83 | if msg[i] in string.whitespace: | ||
84 | if not self.flag_quiet: print msg[i], | ||
85 | self.log_file.write(msg[i]) | ||
86 | else: break | ||
87 | pass | ||
88 | |||
89 | nsmirnov | 1.2 | # print the rest of the message prefixing with the program name |
90 | nsmirnov | 1.1 | msg0 = msg[i:] |
91 | if not self.flag_quiet: print self.prog_name+'. '+msg0 | ||
92 | self.log_file.write(msg0+'\n') | ||
93 | self.log_file.flush() | ||
94 | self.lock.release() | ||
95 | return | ||
96 | |||
97 | nsmirnov | 1.3 | def debugLevel(self): |
98 | return self.debug_level | ||
99 | |||
100 | nsmirnov | 1.1 | def setDebugLevel(self, level): |
101 | self.debug_level = level | ||
102 | return | ||
103 | |||
104 | def debug(self, level, msg): | ||
105 | self.lock.acquire() | ||
106 | if level <= self.debug_level: self.message(msg) | ||
107 | self.lock.release() | ||
108 | return | ||
109 |