Package pulp :: Package client :: Module logutil
[hide private]
[frames] | no frames]

Source Code for Module pulp.client.logutil

 1  # 
 2  # Copyright (c) 2010 Red Hat, Inc. 
 3  # 
 4  # This software is licensed to you under the GNU General Public License, 
 5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
 6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
 8  # along with this software; if not, see 
 9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
10  # 
11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
12  # granted to use or replicate Red Hat trademarks that are incorporated 
13  # in this software or its documentation. 
14  # 
15   
16  import os 
17  import logging 
18  from logging import root, Formatter 
19  from logging.handlers import RotatingFileHandler 
20   
21  LOGDIR = '/var/log/pulp' 
22  LOGFILE = 'client.log' 
23   
24  handler = None 
25   
26 -def getLogger(name):
27 global handler 28 if not os.path.exists(LOGDIR): 29 os.mkdir(LOGDIR) 30 if handler is None: 31 path = os.path.join(LOGDIR, LOGFILE) 32 fmt = '%(asctime)s [%(levelname)s][%(threadName)s] %(funcName)s() @ %(filename)s:%(lineno)d - %(message)s' 33 handler = RotatingFileHandler(path, maxBytes=0x100000, backupCount=5) 34 handler.setFormatter(Formatter(fmt)) 35 root.setLevel(logging.INFO) 36 root.addHandler(handler) 37 log = logging.getLogger(name) 38 return log
39