3 ## Copyright 2007, Red Hat, Inc
6 ## This software may be freely redistributed under the terms of the GNU
7 ## general public license.
9 ## You should have received a copy of the GNU General Public License
10 ## along with this program; if not, write to the Free Software
11 ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 from config
import read_config
18 from commonconfig
import CMConfig
21 # from the comments in http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531
22 class Singleton(object):
23 def __new__(type, *args
, **kwargs
):
24 if not '_the_instance' in type.__dict
__:
25 type._the
_instance
= object.__new
__(type, *args
, **kwargs
)
26 return type._the
_instance
28 # logging is weird, we don't want to setup multiple handlers
29 # so make sure we do that mess only once
31 class Logger(Singleton
):
34 def __init__(self
, logfilepath
="/var/log/certmaster/certmaster.log"):
35 config_file
= '/etc/certmaster/minion.conf'
36 self
.config
= read_config(config_file
, CMConfig
)
37 self
.loglevel
= logging
._levelNames
[self
.config
.log_level
]
40 self
._setup
_handlers
(logfilepath
=logfilepath
)
42 def _setup_logging(self
):
43 self
.logger
= logging
.getLogger("svc")
45 def _setup_handlers(self
, logfilepath
="/var/log/certmaster/certmaster.log"):
46 handler
= logging
.FileHandler(logfilepath
, "a")
47 self
.logger
.setLevel(self
.loglevel
)
48 formatter
= logging
.Formatter("%(asctime)s - %(levelname)s - %(message)s")
49 handler
.setFormatter(formatter
)
50 self
.logger
.addHandler(handler
)
51 self
._no
_handlers
= False
54 class AuditLogger(Singleton
):
56 def __init__(self
, logfilepath
= "/var/log/certmaster/audit.log"):
57 self
.loglevel
= logging
.INFO
60 self
._setup
_handlers
(logfilepath
=logfilepath
)
62 def log_call(self
, ip
, CN
, cert_hash
, method
, params
):
63 # square away a good parseable format at some point -akl
64 self
.logger
.info("%s %s %s %s called with %s" % (ip
, CN
, cert_hash
, method
, params
))
67 def _setup_logging(self
):
68 self
.logger
= logging
.getLogger("audit")
70 def _setup_handlers(self
, logfilepath
="/var/log/certmaster/audit.log"):
71 handler
= logging
.FileHandler(logfilepath
, "a")
72 self
.logger
.setLevel(self
.loglevel
)
73 formatter
= logging
.Formatter("%(asctime)s - %(message)s")
74 handler
.setFormatter(formatter
)
75 self
.logger
.addHandler(handler
)
76 self
._no
_handlers
= False