Cambridge SMT System
logger.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 
15 #ifndef LOGGER_HPP
16 #define LOGGER_HPP
17 
18 #define PRINTLOG
19 #define PRINTERROR
20 #define PRINTWARNING
21 //#define PRINTDEBUG
22 #define PRINTINFO
23 
24 namespace HifstConstants {
25 const std::string kLoggerVerbose = "logger.verbose";
26 }
27 
28 namespace ucam {
29 namespace util {
30 
31 std::string getTimestamp ( void );
32 
34 class silent {
35  private:
37  static bool silent_;
38  public:
40  inline static bool get () {
41  return silent_;
42  };
44  inline static void set ( bool silent ) {
45  silent_ = silent;
46  };
47 };
48 
50 inline std::string filteredHeader ( const std::string& a ) {
51  size_t pos = a.find_last_of ( '(' );
52  size_t pos2 = a.find_last_of ( ' ', pos );
53  return a.substr ( pos2 + 1, pos - pos2 - 1 );
54 };
55 }
56 }
57 
58 //Choose your favourite logger.
59 //OpenFST has a vanilla GLOG integrated --note that real GLOG has compatibility issues with openfst 1.3.1+
60 //BOOSTLOG is great library, candidate to boost -- but not officially part of the release yet.
61 // should be easy to use it, although it hasn't been tested for a while...
62 #ifdef USE_BOOSTLOG
63 //Uses boost log -- It is candidate to the boost library, but not an official release yet, as of late 2012.
64 #include "logger.boost_log.hpp"
65 #else
66 //By default will take OpenFST's implementation! Need to include openfst headers before logger.hpp
67 #include <fst/fstlib.h>
68 #define TRACER LogMessage(ucam::util::getTimestamp()).stream()
69 #include "logger.openfstglog.hpp"
70 #endif
71 
72 //When in the future Google OpenFST is easy to compile with Google Log, we can cover it easily here.
73 
74 #endif
Logger implementation – init method and macros around actual OpenFST logger – requires including op...
Provides methods to set and get silent logging mode.
Definition: logger.hpp:34
std::string getTimestamp(void)
Generates time stamp.
std::string filteredHeader(const std::string &a)
This function is meant to filter PRETTY_FUNCTION and attempts to simplify it. With the templating it ...
Definition: logger.hpp:50
const std::string kLoggerVerbose
Definition: logger.hpp:25
Logger implementation – init method and macros around actual Boost Logger.
Definition: bleu.hpp:14