ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/CrabLogger.py
Revision: 1.2
Committed: Thu Sep 24 18:03:15 2009 UTC (15 years, 7 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_7_2_p1, CRAB_2_7_1_branch_firstMERGE, CRAB_2_7_2, CRAB_2_7_2_pre4, CRAB_2_7_2_pre3, CRAB_2_7_2_pre2, CRAB_2_7_2_pre1, CRAB_2_7_1, fede_170310, CRAB_2_7_1_pre12, CRAB_2_7_1_pre11, CRAB_2_7_1_pre10, CRAB_2_7_1_pre9, CRAB_LumiMask, CRAB_2_7_lumi, from_LimiMask, CRAB_2_7_1_pre8, CRAB_2_7_1_pre6, CRAB_2_7_1_pre5, CRAB_2_7_1_wmbs_pre4, CRAB_2_7_1_pre4, CRAB_2_7_1_pre3, CRAB_2_7_1_pre2, CRAB_2_7_1_pre1, CRAB_2_7_0, CRAB_2_7_0_pre8, CRAB_2_7_0_pre7, CRAB_2_7_0_pre6, CRAB_2_7_0_pre5, CRAB_2_7_0_pre4, CRAB_2_7_0_pre3
Branch point for: CRAB_multiout, CRAB_2_7_1_branch, Lumi2_8
Changes since 1.1: +2 -2 lines
Log Message:
log stream to stdout

File Contents

# User Rev Content
1 slacapra 1.2 import logging,time,sys
2 slacapra 1.1 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.DEBUG_VERBOSE, logging.DEBUG, logging.INFO, \
11     logging.WARNING,logging.ERROR, logging.CRITICAL])
12    
13     self.logger = logging.getLogger("crab:")
14     self.logger.setLevel(logging.DEBUG_VERBOSE)
15    
16     # FileHandler
17     log_fname =common.work_space.logDir()+common.prog_name+'.log'
18     self.fh=logging.FileHandler(log_fname)
19     fh_formatter = logging.Formatter("%(asctime)s [%(levelname)s] \t%(message)s")
20     fh_level=logging.DEBUG
21     self.fh.setLevel(fh_level)
22     self.fh.setFormatter(fh_formatter)
23     self.logger.addHandler(self.fh)
24    
25     # StreamerHandler: to be dded _only_ if not already present: otherwise duplicated
26     streamenPresent=False
27     for x in self.logger.handlers:
28     if x.__class__==logging.StreamHandler: streamenPresent=True
29     if not streamenPresent:
30 slacapra 1.2 self.ch=logging.StreamHandler(sys.stdout)
31 slacapra 1.1 ch_formatter = logging.Formatter("%(name)s %(message)s")
32     ch_level=logging.INFO
33     if common.debugLevel > 0:ch_level=logging.DEBUG
34     if common.debugLevel > 2:
35     fh_level=logging.DEBUG_VERBOSE
36     ch_level=logging.DEBUG_VERBOSE
37    
38     self.ch.setLevel(ch_level)
39     self.ch.setFormatter(ch_formatter)
40    
41     # add StreamerHandler only if is not yet there
42     self.logger.addHandler(self.ch)
43    
44     self.debug('%s\n'%args)
45     # print 'LOGGER',logging._handlers
46     return
47    
48     def __call__(self):
49     return self.logger
50    
51     def delete(self):
52     # The trick her is to flush, close, remove from handler list and finally delete _only_ the FileHandler,
53     # NOT the StreamerHandler as well, since it is apparently used asynchrounously and will give error in emit(...)
54     if self.fh in logging._handlers :
55     self.fh.flush()
56     self.fh.close()
57     self.logger.removeHandler(self.fh)
58     del self.fh
59     common.logger=None
60    
61     def info(self, msg):
62     #print msg
63     self.logger.info(msg)
64    
65     def debug(self, msg):
66     #print msg
67     self.logger.debug(msg)
68    
69     def log(self,i, msg):
70     #print msg
71     self.logger.log(i,msg)
72