Package Halberd :: Module logger
[hide private]
[frames] | no frames]

Source Code for Module Halberd.logger

 1  # -*- coding: iso-8859-1 -*- 
 2   
 3  """Logger singleton. 
 4   
 5  This module allows halberd to easily log certain events. 
 6  """ 
 7   
 8  # Copyright (C) 2004, 2005, 2006, 2010  Juan M. Bello Rivas <jmbr@superadditive.com> 
 9  # 
10  # This program is free software; you can redistribute it and/or modify 
11  # it under the terms of the GNU General Public License as published by 
12  # the Free Software Foundation; either version 2 of the License, or 
13  # (at your option) any later version. 
14  # 
15  # This program is distributed in the hope that it will be useful, 
16  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
17  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
18  # GNU General Public License for more details. 
19  # 
20  # You should have received a copy of the GNU General Public License 
21  # along with this program; if not, write to the Free Software 
22  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
23   
24   
25  import sys 
26  import logging 
27   
28   
29  _logger = None 
30   
31  #_logfmt = '%(name)s %(thread)d %(asctime)s %(levelname)s %(message)s' 
32  _logfmt = '%(levelname)s %(message)s' 
33   
34   
35 -def getLogger():
36 """Get a reference to an instance of a logger object. 37 38 @return: reference to a logger. 39 @rtype: C{object} 40 """ 41 global _logger 42 43 if _logger is None: 44 _logger = logging.getLogger('Halberd') 45 handler = logging.StreamHandler(sys.stdout) 46 handler.setFormatter(logging.Formatter(_logfmt)) 47 _logger.addHandler(handler) 48 _logger.setLevel(logging.INFO) 49 50 return _logger
51
52 -def setDebug():
53 """Set the logging level to C{debug}. 54 """ 55 logger = getLogger() 56 logger.setLevel(logging.DEBUG)
57
58 -def setError():
59 """Set the logging level to C{error}. 60 """ 61 logger = getLogger() 62 logger.setLevel(logging.ERROR)
63 64 65 # vim: ts=4 sw=4 et 66