1 /* Copyright (C) 2014 InfiniDB, Inc.
2 
3    This program is free software; you can redistribute it and/or
4    modify it under the terms of the GNU General Public License
5    as published by the Free Software Foundation; version 2 of
6    the License.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16    MA 02110-1301, USA. */
17 
18 /*
19  * $Id: logger.cpp 686 2008-08-21 22:08:33Z rdempsey $
20  */
21 
22 #include <boost/thread.hpp>
23 using namespace boost;
24 
25 #include "messageobj.h"
26 #include "messageids.h"
27 #include "loggingid.h"
28 using namespace logging;
29 
30 #include "logger.h"
31 
32 namespace primitiveprocessor
33 {
34 
Logger()35 Logger::Logger() :
36     fMl1(LoggingID(28))
37 {
38     fMsgMap[logging::M0000] = Message(logging::M0000);
39     fMsgMap[logging::M0016] = Message(logging::M0016);
40     fMsgMap[logging::M0045] = Message(logging::M0045);
41     fMsgMap[logging::M0053] = Message(logging::M0053);
42 }
43 
logMessage(const Message::MessageID mid,const Message::Args & args,bool critical)44 void Logger::logMessage(const Message::MessageID mid,
45                         const Message::Args& args,
46                         bool  critical)
47 {
48     mutex::scoped_lock lk(fLogLock);
49     MsgMap::iterator msgIter = fMsgMap.find(mid);
50 
51     if (msgIter == fMsgMap.end())
52         msgIter = fMsgMap.find(logging::M0000);
53 
54     msgIter->second.reset();
55     msgIter->second.format(args);
56 
57     if (critical)
58     {
59         fMl1.logCriticalMessage(msgIter->second);
60     }
61     else
62     {
63         fMl1.logWarningMessage(msgIter->second);
64     }
65 }
66 
67 }
68 
69