Schnek
logger.hpp
Go to the documentation of this file.
1 /*
2  * logger.hpp
3  *
4  * Created on: 20 Sep 2012
5  * Author: Holger Schmitz
6  * Email: holger@notjustphysics.com
7  *
8  * Copyright 2012 Holger Schmitz
9  *
10  * This file is part of Schnek.
11  *
12  * Schnek is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * Schnek is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with Schnek. If not, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef SCHNEK_LOGGER_HPP_
28 #define SCHNEK_LOGGER_HPP_
29 
30 
31 #include <boost/preprocessor/control/iif.hpp>
32 #include <boost/preprocessor/facilities/empty.hpp>
33 #include <boost/preprocessor/comparison/greater_equal.hpp>
34 
35 #include <iostream>
36 #include <string>
37 
38 #include "singleton.hpp"
39 
40 namespace schnek {
41 
54 #define SCHNEK_TRACE_LOG(i,x) \
55  BOOST_PP_IIF( BOOST_PP_GREATER_EQUAL( LOGLEVEL, i ), \
56  schnek::Logger::instance().out() << __LINE__ << " " << __FILE__ << ": "<< x << "\n";, \
57  BOOST_PP_EMPTY() \
58  )
59 
72 #define SCHNEK_TRACE_ERR(i,x) \
73  BOOST_PP_IIF( BOOST_PP_GREATER_EQUAL( LOGLEVEL, i ), \
74  schnek::Logger::instance().err() << __LINE__ << " " << __FILE__ << ": " << x << "\n";, \
75  BOOST_PP_EMPTY() \
76  )
77 
78 #define SCHNEK_TRACE_ENTER_FUNCTION(i) \
79  BOOST_PP_IIF( BOOST_PP_GREATER_EQUAL( LOGLEVEL, i ), \
80  schnek::Logger::instance().out() << "Entering " << BOOST_CURRENT_FUNCTION << std::endl;, \
81  BOOST_PP_EMPTY() \
82  )
83 
84 #define SCHNEK_TRACE_EXIT_FUNCTION(i) \
85  BOOST_PP_IIF( BOOST_PP_GREATER_EQUAL( LOGLEVEL, i ), \
86  schnek::Logger::instance().out() << "Leaving " << BOOST_CURRENT_FUNCTION << std::endl;, \
87  BOOST_PP_EMPTY() \
88  )
89 
97 #ifndef LOGLEVEL
98 #define LOGLEVEL 0
99 #endif
100 
101 #include "singleton.hpp"
110 class Logger : public Singleton<Logger>
111 {
112  public:
117  std::ostream &out() { return std::cout; }
118 
123  std::ostream &err() { return std::cerr; }
124  private:
125  friend class Singleton<Logger>;
126  friend class CreateUsingNew<Logger>;
127 
131  Logger() { }
132 
136  ~Logger() {
137 // std::cerr << "DELETING LOGGER "<< this <<" " <<i<<"\n";
138  }
139 };
140 
164 } // namespace
165 #endif // LOGGER_HPP_
Definition: singleton.hpp:80
Definition: singleton.hpp:42
std::ostream & out()
Definition: logger.hpp:117
Definition: algo.hpp:30
std::ostream & err()
Definition: logger.hpp:123
Definition: logger.hpp:110