Orocos Real-Time Toolkit  2.9.0
Logger.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jan 10 15:59:16 CET 2005 Logger.hpp
3 
4  Logger.hpp - description
5  -------------------
6  begin : Mon January 10 2005
7  copyright : (C) 2005 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 #ifndef ORO_CORELIB_lOGGER_HPP
40 #define ORO_CORELIB_lOGGER_HPP
41 
42 #include "rtt-config.h"
43 #ifndef OROBLD_DISABLE_LOGGING
44 #include <ostream>
45 #include <sstream>
46 #else
47 #include <iosfwd>
48 #endif
49 #include <string>
50 #ifndef OROSEM_PRINTF_LOGGING
51 #include <iostream> // for std::cerr
52 #endif
53 
54 #include "os/TimeService.hpp"
55 #include "os/Mutex.hpp"
56 #include "os/MutexLock.hpp"
57 
58 namespace RTT
59 {
96  {
97  struct D;
98  D* d;
104  os::Mutex& inpguard;
105  std::ostream& logline;
106  std::ostream& fileline;
107  public:
108 
112  os::TimeService::ticks getReferenceTime()const;
113 
122 
126  void allowRealTime();
127 
131  void disallowRealTime();
132 
137  void mayLogStdOut(bool tf);
138 
143  void mayLogFile(bool tf);
144 
159  struct RTT_API In {
160  In(const std::string& module);
161  ~In();
162  std::string oldmod;
163  };
164 
169  Logger& in(const std::string& modname);
170 
175  Logger& out(const std::string& modname);
176 
180  std::string getLogModule() const;
181 
186  typedef std::ostream& (*LogFunction)(std::ostream&);
187 
191  static std::ostream& nl(std::ostream& __os);
192 
193  /*
194  * Insert a newline '\n' in the ostream and flush. (Copy of the standard)
195  */
196  static std::ostream& endl(std::ostream& __os);
197 
201  static std::ostream& flush(std::ostream& __os);
202 
210  static Logger* Instance(std::ostream& str=std::cerr);
211 
215  static void Release();
216 
220  static Logger& log();
221 
225  static Logger& log(LogLevel ll);
226 
230  void startup();
231 
235  void shutdown();
236 
242  std::string getLogLine();
243 
247  void setStdStream( std::ostream& stdos );
248 
255  template< class T>
256  Logger& operator<<( const T &t );
257 
262 
268  Logger& operator<<(const std::string&);
269 
275  Logger& operator<<(const char*);
276 
280  Logger& operator<<(std::ostream& (*pf)(std::ostream&));
281 
289  void setLogLevel( LogLevel ll );
290 
294  LogLevel getLogLevel() const;
295 
299  void logflush();
300 
305  void logendl();
306 
312  void lognl();
313 
314 #ifdef OROSEM_LOG4CPP_LOGGING
315 
318  static const std::string log4cppCategoryName;
319 #endif
320 
321  private:
328  bool mayLog() const;
329  bool mayLogStdOut() const;
330  bool mayLogFile() const;
331 
332  Logger(std::ostream& str=std::cerr);
333  ~Logger();
334 
335  static Logger* _instance;
336  };
337 
345  enum LoggerLevel { Never = 0, Fatal, Critical, Error, Warning, Info, Debug, RealTime };
346 
350  static inline Logger& log() { return Logger::log(); }
351 
356  static inline Logger& log(LoggerLevel ll) { return Logger::log(Logger::LogLevel(ll)); }
357 
362  static inline Logger::LogFunction endlog() {return Logger::endl; }
363 
369  static inline Logger::LogFunction endlog(LoggerLevel ll) { log(ll); return Logger::endl; }
370 
375  static inline Logger::LogFunction nlog() {return Logger::nl; }
376 
381  static inline Logger::LogFunction flushlog() {return Logger::flush; }
382 }
383 
384 #include "Logger.inl"
385 
386 #endif
LoggerLevel
Enumerate all log-levels from absolute silence to everything.
Definition: Logger.hpp:345
long long ticks
The type for the systems clock tick.
Definition: TimeService.hpp:66
static std::ostream & nl(std::ostream &__os)
Insert a newline &#39; &#39; in the ostream.
Definition: Logger.cpp:373
This hidden struct stores all data structures required for logging.
Definition: Logger.cpp:128
A simple logging class to debug/ analyse what is going on in the Orocos system.
Definition: Logger.hpp:95
#define RTT_API
Definition: rtt-config.h:97
basic_ostreams & endl(basic_ostreams &s)
Flush and newline.
Definition: rtstreams.cpp:110
std::string oldmod
Definition: Logger.hpp:162
Provides empty inlines when no logging is used, which the compiler can optimize out.
static std::ostream & flush(std::ostream &__os)
Flush the output stream.
Definition: Logger.cpp:393
static std::ostream & endl(std::ostream &__os)
Definition: Logger.cpp:383
std::ostream &(* LogFunction)(std::ostream &)
Function signature of the functions that influence the log stream.
Definition: Logger.hpp:186
std::ostream & operator<<(std::ostream &os, const BufferPolicy &bp)
LogLevel
Enumerate all log-levels from absolute silence to everything.
Definition: Logger.hpp:121
Notify the Logger in which &#39;module&#39; the message occured.
Definition: Logger.hpp:159
static Logger & log()
As Instance(), but more userfriendly.
Definition: Logger.cpp:117
An object oriented wrapper around a non recursive mutex.
Definition: Mutex.hpp:92
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52