Cambridge SMT System
logger.boost_log.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use these files except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 // Copyright 2012 - Gonzalo Iglesias, Adrià de Gispert, William Byrne
14 
22 #ifndef LOGGER_BOOST_LOG_HPP
23 #define LOGGER_BOOST_LOG_HPP
24 
25 #include <iostream>
26 
27 #include <boost/log/common.hpp>
28 #include <boost/log/expressions.hpp>
29 
30 #include <boost/log/utility/setup/file.hpp>
31 #include <boost/log/utility/setup/console.hpp>
32 #include <boost/log/utility/setup/common_attributes.hpp>
33 
34 #include <boost/log/attributes/timer.hpp>
35 #include <boost/log/attributes/named_scope.hpp>
36 
37 #include <boost/log/sources/logger.hpp>
38 #include <boost/log/support/date_time.hpp>
39 
40 namespace ucam {
41 namespace util {
42 
43 namespace logging = boost::log;
44 
45 namespace sinks = boost::log::sinks;
46 namespace attrs = boost::log::attributes;
47 namespace src = boost::log::sources;
48 namespace keywords = boost::log::keywords;
49 
55 inline void initLogger ( int argc, const char *argv[] ) {
56  bool verbose = false;
57  const std::string lv = "--" + HifstConstants::kLoggerVerbose;
58  for ( uint k = 0; k < argc; ++k ) {
59  if ( !strcmp ( argv[k], lv.c_str() ) ) {
60  verbose = true;
61  break;
62  }
63  }
64  silent::set ( !verbose );
65  logging::add_console_log (
66  std::clog,
67  keywords::format = "[%TimeStamp%] %_%"
68  );
69 };
70 
71 }
72 } // end namespaces
73 
74 #ifdef PRINTINFO
75 #define LINFO(msg) if (!silent::get()) BOOST_LOG_TRIVIAL(info) << ::ucam::util::filteredHeader(::ucam::util::detailed?__PRETTY_FUNCTION__:__func__)<< ".INF:" << msg ;
76 #define FORCELINFO(msg) BOOST_LOG_TRIVIAL(info) << ::ucam::util::filteredHeader(::ucam::util::detailed?__PRETTY_FUNCTION__:__func__) << ".INF:" << msg ;
77 #else
78 #define LINFO(msg)
79 #define FORCELINFO(msg)
80 #endif
81 
82 #ifdef PRINTDEBUG3
83 #ifndef PRINTDEBUG2
84 #define PRINTDEBUG2
85 #endif
86 #define LDEBUG3(msg) BOOST_LOG_TRIVIAL(debug) << ::ucam::util::filteredHeader(::ucam::util::detailed?__PRETTY_FUNCTION__:__func__)<< ".DBG3:" << msg ;
87 #else
88 #define LDEBUG3(msg)
89 #endif
90 
91 #ifdef PRINTDEBUG2
92 #ifndef PRINTDEBUG1
93 #define PRINTDEBUG1
94 #endif
95 #define LDEBUG2(msg) BOOST_LOG_TRIVIAL(debug) << ::ucam::util::filteredHeader(::ucam::util::detailed?__PRETTY_FUNCTION__:__func__)<< ".DBG2:" << msg ;
96 #else
97 #define LDEBUG2(msg)
98 #endif
99 
100 #ifdef PRINTDEBUG1
101 #ifndef PRINTDEBUG
102 #define PRINTDEBUG
103 #endif
104 #define LDEBUG1(msg) BOOST_LOG_TRIVIAL(debug) << ::ucam::util::filteredHeader(::ucam::util::detailed?__PRETTY_FUNCTION__:__func__)<< ".DBG1:" << msg ;
105 #define LDEBUG(msg) BOOST_LOG_TRIVIAL(debug) << ::ucam::util::filteredHeader(::ucam::util::detailed?__PRETTY_FUNCTION__:__func__)<< ".DBG1:" << msg ;
106 #else
107 #define LDEBUG(msg)
108 #endif
109 
110 #ifdef PRINTDEBUG
111 #define LDBG_EXECUTE(order) {order;}
112 #else
113 #define LDBG_EXECUTE(order)
114 #endif
115 
116 #ifdef PRINTERROR
117 #define LERROR(msg) BOOST_LOG_TRIVIAL(error) << ::ucam::util::filteredHeader(::ucam::util::detailed?__PRETTY_FUNCTION__:__func__)<< ".ERR:" << msg ;
118 #else
119 #define LERROR(msg)
120 #endif
121 
122 #ifdef PRINTWARNING
123 #define LWARN(msg) BOOST_LOG_TRIVIAL(warning) << ::ucam::util::filteredHeader(::ucam::util::detailed?__PRETTY_FUNCTION__:__func__)<< ".WRN:" << msg ;
124 #else
125 #define LWARN(msg)
126 #endif
127 
128 #endif
void initLogger(int argc, const char *argv[])
Inits logger, parses param options checking for –logger.verbose.
static void set(bool silent)
Set silent mode or viceversa.
Definition: logger.hpp:44
const std::string kLoggerVerbose
Definition: logger.hpp:25
Definition: bleu.hpp:14