Revision: | 1.3 |
Committed: | Wed May 26 19:46:12 2010 UTC (14 years, 11 months ago) by ewv |
Content type: | text/x-python |
Branch: | MAIN |
CVS Tags: | CRAB_2_9_1, CRAB_2_9_1_pre2, CRAB_2_9_1_pre1, CRAB_2_9_0, CRAB_2_9_0_pre2, CRAB_2_9_0_pre1, CRAB_2_8_8, CRAB_2_8_8_pre1, CRAB_2_8_7_patch3, CRAB_2_8_7_patch2, CRAB_2_8_7_patch1, CRAB_2_8_7, CRAB_2_8_7_pre2, CRAB_2_8_7_pre1, CRAB_2_8_6, CRAB_2_8_6_pre1, CRAB_2_8_5_patch3, CRAB_2_8_5_patch2, CRAB_2_8_5_patch1, CRAB_2_8_5, CRAB_2_8_5_pre5, CRAB_2_8_5_pre4, CRAB_2_8_5_pre3, CRAB_2_8_4_patch3, CRAB_2_8_5_pre2, CRAB_2_8_4_patch2, CRAB_2_8_5_pre1, CRAB_2_8_4_patch1, CRAB_2_8_4, CRAB_2_8_4_pre5, CRAB_2_8_4_pre4, CRAB_2_8_4_pre3, CRAB_2_8_4_pre2, CRAB_2_8_4_pre1, CRAB_2_8_3, CRAB_2_8_3_pre4, CRAB_2_8_3_pre3, CRAB_2_8_3_pre2, CRAB_2_8_3_pre1, CRAB_2_8_2_patch1, CRAB_2_8_2, CRAB_2_8_2_pre5, CRAB_2_8_2_pre4, CRAB_2_8_2_pre3, CRAB_2_8_2_pre2, CRAB_2_8_2_pre1, CRAB_2_8_1, CRAB_2_8_0, CRAB_2_8_0_pre1, CRAB_2_7_10_pre3, CRAB_2_7_9_patch2_pre1, CRAB_2_7_10_pre2, CRAB_2_7_10_pre1, CRAB_2_7_9_patch1, CRAB_2_7_9, CRAB_2_7_9_pre5, CRAB_2_7_9_pre4, CRAB_2_7_9_pre3, CRAB_2_7_9_pre2, CRAB_2_7_8_patch2, CRAB_2_7_9_pre1, CRAB_2_7_8_patch2_pre1, CRAB_2_7_8_patch1, CRAB_2_7_8_patch1_pre1, CRAB_2_7_8, CRAB_2_7_8_pre3, CRAB_2_7_8_pre2, CRAB_2_7_8_dash3, CRAB_2_7_8_dash2, CRAB_2_7_8_dash, CRAB_2_7_7_patch1, CRAB_2_7_7_patch1_pre1, CRAB_2_7_8_pre1, CRAB_2_7_7, CRAB_2_7_7_pre2, CRAB_2_7_7_pre1, CRAB_2_7_6_patch1, CRAB_2_7_6, CRAB_2_7_6_pre1, CRAB_2_7_5_patch1, CRAB_2_7_5, CRAB_2_7_5_pre3, CRAB_2_7_5_pre2, CRAB_2_7_5_pre1, CRAB_2_7_4_patch1, CRAB_2_7_4, CRAB_2_7_4_pre6, CRAB_2_7_4_pre5, CRAB_2_7_4_pre4, CRAB_2_7_4_pre3, CRAB_2_7_4_pre2, CRAB_2_7_4_pre1, CRAB_2_7_3, CRAB_2_7_3_pre3, CRAB_2_7_3_pre3_beta, CRAB_2_7_3_pre2, CRAB_2_7_3_pre2_beta, CRAB_2_7_3_pre1, CRAB_2_7_3_beta3, CRAB_2_7_3_beta2, CRAB_2_7_3_beta1, CRAB_2_7_3_beta, HEAD |
Changes since 1.2: | +2 -3 lines |
Log Message: | Add runselection along with lumi_mask. Needs Splitter, LumiList, and DataDiscovery |
# | Content |
---|---|
1 | import logging,time,sys |
2 | import common |
3 | |
4 | class CrabLogger: |
5 | def __init__(self, args): |
6 | |
7 | # print 'Creating LOGGER',logging._handlers |
8 | logging.DEBUG_VERBOSE = logging.DEBUG - 1 |
9 | logging.addLevelName(logging.DEBUG_VERBOSE,'debug_verbose') |
10 | logging.root.setLevel(logging.CRITICAL) |
11 | |
12 | self.logger = logging.getLogger("crab:") |
13 | self.logger.setLevel(logging.DEBUG_VERBOSE) |
14 | |
15 | # FileHandler |
16 | log_fname =common.work_space.logDir()+common.prog_name+'.log' |
17 | self.fh=logging.FileHandler(log_fname) |
18 | fh_formatter = logging.Formatter("%(asctime)s [%(levelname)s] \t%(message)s") |
19 | fh_level=logging.DEBUG |
20 | self.fh.setLevel(fh_level) |
21 | self.fh.setFormatter(fh_formatter) |
22 | self.logger.addHandler(self.fh) |
23 | |
24 | # StreamerHandler: to be dded _only_ if not already present: otherwise duplicated |
25 | streamenPresent=False |
26 | for x in self.logger.handlers: |
27 | if x.__class__==logging.StreamHandler: streamenPresent=True |
28 | if not streamenPresent: |
29 | self.ch=logging.StreamHandler(sys.stdout) |
30 | ch_formatter = logging.Formatter("%(name)s %(message)s") |
31 | ch_level=logging.INFO |
32 | if common.debugLevel > 0:ch_level=logging.DEBUG |
33 | if common.debugLevel > 2: |
34 | fh_level=logging.DEBUG_VERBOSE |
35 | ch_level=logging.DEBUG_VERBOSE |
36 | |
37 | self.ch.setLevel(ch_level) |
38 | self.ch.setFormatter(ch_formatter) |
39 | |
40 | # add StreamerHandler only if is not yet there |
41 | self.logger.addHandler(self.ch) |
42 | |
43 | self.debug('%s\n'%args) |
44 | # print 'LOGGER',logging._handlers |
45 | return |
46 | |
47 | def __call__(self): |
48 | return self.logger |
49 | |
50 | def delete(self): |
51 | # The trick her is to flush, close, remove from handler list and finally delete _only_ the FileHandler, |
52 | # NOT the StreamerHandler as well, since it is apparently used asynchrounously and will give error in emit(...) |
53 | if self.fh in logging._handlers : |
54 | self.fh.flush() |
55 | self.fh.close() |
56 | self.logger.removeHandler(self.fh) |
57 | del self.fh |
58 | common.logger=None |
59 | |
60 | def info(self, msg): |
61 | #print msg |
62 | self.logger.info(msg) |
63 | |
64 | def debug(self, msg): |
65 | #print msg |
66 | self.logger.debug(msg) |
67 | |
68 | def log(self,i, msg): |
69 | #print msg |
70 | self.logger.log(i,msg) |
71 |