*Code cleanup in livestatus.
[shinken.git] / shinken / log.py
blobd62c25644f870eadfa2e15e3150ad8a135e854ce
1 #!/usr/bin/env python
2 #Copyright (C) 2009-2010 :
3 # Gabes Jean, naparuba@gmail.com
4 # Gerhard Lausser, Gerhard.Lausser@consol.de
6 #This file is part of Shinken.
8 #Shinken is free software: you can redistribute it and/or modify
9 #it under the terms of the GNU Affero General Public License as published by
10 #the Free Software Foundation, either version 3 of the License, or
11 #(at your option) any later version.
13 #Shinken is distributed in the hope that it will be useful,
14 #but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 #GNU Affero General Public License for more details.
18 #You should have received a copy of the GNU Affero General Public License
19 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
21 import time
23 from borg import Borg
24 from brok import Brok
26 class Log(Borg):
28 #We load the object where we will put log broks
29 #with the 'add' method
30 def load_obj(self, obj, name = None):
31 self.obj = obj
32 self.name = name
34 #We enter a log message, we format it, and we add the log brok
35 def log(self, message, format = None):
36 print message
37 if format == None:
38 if self.name == None:
39 #We format the log in UTF-8
40 s = u'[%d] %s\n' % (int(time.time()), message.decode('UTF-8', 'replace'))
41 else:
42 s = u'[%d] [%s] %s\n' % (int(time.time()), self.name, message.decode('UTF-8', 'replace'))
43 else:
44 s = format % message
46 #Wecreate and add the brok
47 b = Brok('log', {'log' : s})
48 self.obj.add(b)