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: jl_logger.h 9210 2013-01-21 14:10:42Z rdempsey $
20  */
21 
22 /** @file */
23 
24 #ifndef JOBLIST_LOGGER_H_
25 #define JOBLIST_LOGGER_H_
26 
27 #include <boost/shared_ptr.hpp>
28 
29 #include "messageids.h"
30 #include "messageobj.h"
31 #include "loggingid.h"
32 #include "errorids.h"
33 #include "logger.h"
34 #include "errorcodes.h"
35 #include "errorinfo.h"
36 #include "exceptclasses.h"
37 
38 namespace joblist
39 {
40 const unsigned LogDefaultMsg = logging::M0000;
41 const unsigned LogSQLTrace = logging::M0036;
42 const unsigned LogNoPrimProcs = logging::M0043;
43 const unsigned LogMakeJobList = logging::M0059;
44 const unsigned LogRDRequest = logging::M0062;
45 const unsigned LogRDRequestWait = logging::M0063;
46 const unsigned LogRDReturn = logging::M0064;
47 const unsigned LogRMResourceChange = logging::M0066;
48 const unsigned LogRMResourceChangeError = logging::M0067;
49 
50 
51 /** @brief message log wrapper class */
52 class Logger
53 {
54 public:
55     Logger();
56 
logMessage(logging::LOG_TYPE logLevel,logging::Message::MessageID mid,const logging::Message::Args & args,const logging::LoggingID & logInfo)57     const std::string logMessage(logging::LOG_TYPE logLevel, logging::Message::MessageID mid,
58                                  const logging::Message::Args& args, const logging::LoggingID& logInfo)
59     {
60         return  fImpl->logMessage(logLevel, mid, args, logInfo);
61     }
62 
63     const std::string logMessage(logging::LOG_TYPE logLevel, const std::string& msg, logging::Message::MessageID mid = LogDefaultMsg )
64     {
65         logging::Message::Args args;
66         args.add(msg);
67         return  fImpl->logMessage(logLevel, mid, args, fLogId);
68     }
69 
70     const std::string logMessage(logging::LOG_TYPE logLevel, unsigned idbErrorCode);
71 
setLoggingSession(unsigned sid)72     void setLoggingSession(unsigned sid)
73     {
74         fLogId.fSessionID = sid;
75     }
setLoggingTxn(unsigned txn)76     void setLoggingTxn(unsigned txn)
77     {
78         fLogId.fTxnID = txn;
79     }
setLoggingThd(unsigned thr)80     void setLoggingThd(unsigned thr)
81     {
82         fLogId.fThdID = thr;
83     }
84 private:
85     // defaults okay
86     //Logger(const Logger& rhs);
87     //Logger& operator=(const Logger& rhs);
88     logging::LoggingID fLogId;
89 
90     logging::SPL fImpl;
91 };
92 
93 typedef boost::shared_ptr<Logger> SPJL;
94 void catchHandler(const std::string& s, int c, SErrorInfo& errorInfo, unsigned sid = 0,
95                   logging::LOG_TYPE = logging::LOG_TYPE_CRITICAL);
96 
97 }
98 
99 #endif
100 
101