Nemiver  0.3
nmv-log-stream.h
Go to the documentation of this file.
1 /* -*- Mode: C++; indent-tabs-mode:nil; c-basic-offset: 4-*- */
2 
3 /*Copyright (c) 2005-2006 Dodji Seketeli
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of this
6  * software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute,
9  * sublicense, and/or sell copies of the Software, and to permit
10  * persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies
14  * or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS",
17  * WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18  * INCLUDING BUT NOT LIMITED TO THE
19  * WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE
21  * AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23  * HOLDERS BE LIABLE FOR ANY CLAIM,
24  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25  * CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
27  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28  *
29  */
30 #ifndef __NMV_LOG_STREAM_H__
31 #define __NMV_LOG_STREAM_H__
32 #include <string>
33 #include "nmv-api-macros.h"
34 #include "nmv-ustring.h"
35 #include "nmv-safe-ptr.h"
36 #include "nmv-api-macros.h"
37 
38 #ifndef NMV_DEFAULT_DOMAIN
39 #define NMV_DEFAULT_DOMAIN __extension__ \
40  ({ \
41  const char* path = __FILE__; \
42  Glib::path_get_basename (path); \
43  })
44 #endif
45 
46 #ifndef NMV_GENERAL_DOMAIN
47 #define NMV_GENERAL_DOMAIN "general-domain"
48 #endif
49 
50 using std::string;
51 namespace nemiver {
52 namespace common {
53 
58 {
59  friend LogStream& timestamp (LogStream &);
60  friend LogStream& flush (LogStream &);
61  friend LogStream& endl (LogStream &);
62  struct Priv;
63  SafePtr<Priv> m_priv;
64 
65  //forbid copy/assignation
66  LogStream (LogStream const&);
67  LogStream& operator= (LogStream const&);
68 
69 protected:
70 
71 public:
72 
73  enum StreamType {
74  FILE_STREAM = 1,
75  COUT_STREAM = 1 >> 1,
76  CERR_STREAM = 1 >> 2,
77  RFU0,//reserved for future usage
80  };
81 
82  enum LogLevel {
83  LOG_LEVEL_NORMAL=0,
84  LOG_LEVEL_VERBOSE
85  };
86 
91  static void set_stream_type (enum StreamType a_type);
92 
95  static enum StreamType get_stream_type ();
96 
103  static void set_stream_file_path (const char* a_file_path, long a_len=-1);
104 
108  static const char* get_stream_file_path ();
109 
118  static void set_log_level_filter (enum LogLevel a_level);
119 
126  static void set_log_domain_filter (const char* a_domain, long a_len=-1);
127 
130  static void activate (bool a_activate);
131 
134  static bool is_active ();
135 
140  static LogStream& default_log_stream ();
141 
142 
150  LogStream (enum LogLevel a_level=LOG_LEVEL_NORMAL,
151  const string &a_default_domain=NMV_GENERAL_DOMAIN);
152 
154  virtual ~LogStream ();
155 
160  void enable_domain (const string &a_domain,
161  bool a_do_enable=true);
162 
164  bool is_domain_enabled (const string &a_domain);
165 
171  LogStream& write (const char *a_buf,
172  long a_buflen =-1,
173  const string &a_domain=NMV_GENERAL_DOMAIN);
174 
178  LogStream& write (const Glib::ustring &a_msg,
179  const string &a_domain=NMV_GENERAL_DOMAIN);
180 
181  LogStream& write (int a_msg,
182  const string &a_domain=NMV_GENERAL_DOMAIN);
183 
184  LogStream& write (double a_msg,
185  const string &a_domain=NMV_GENERAL_DOMAIN);
186 
187  LogStream& write (char a_msg,
188  const string &a_domain=NMV_GENERAL_DOMAIN);
189 
195  void push_domain (const string &a_domain);
196 
198  void pop_domain ();
199 
202  LogStream& operator<< (const char* a_c_string);
203 
206  LogStream& operator<< (const std::string &a_string);
207 
210  LogStream& operator<< (const Glib::ustring &a_string);
211 
214  LogStream& operator<< (int an_int);
215 
218  LogStream& operator<< (double a_double);
219 
222  LogStream& operator<< (char a_char);
223 
226  LogStream& operator<< (LogStream& (*a_manipulator) (LogStream&));
227 
228  friend LogStream& level_normal (LogStream &a_stream);
229 
230  friend LogStream& level_verbose (LogStream &a_stream);
231 
232 };//end class LogStream
233 
238 
243 
248 
253 
258 
259 }//end namespace common
260 }//end namespace nemiver
261 
262 #endif //__NMV_LOG_STREAM_H__
263 
nemiver::common::operator<<
Stream & operator<<(Stream &a_os, const Address &a)
Definition: nmv-address.h:61
nemiver
Definition: nmv-address.h:31
nemiver::common::LogStream::RFU0
@ RFU0
Definition: nmv-log-stream.h:77
nmv-ustring.h
nmv-safe-ptr.h
NEMIVER_API
#define NEMIVER_API
Definition: nmv-api-macros.h:53
nmv-api-macros.h
nemiver::common::LogStream::LogLevel
LogLevel
Definition: nmv-log-stream.h:82
nemiver::common::LogStream::RFU2
@ RFU2
Definition: nmv-log-stream.h:79
nemiver::common::flush
LogStream & flush(LogStream &)
flushes the stream Use it like: nemiver::LogStream out; out << "Hello" << nemiver::flush;
nemiver::common::level_normal
LogStream & level_normal(LogStream &)
sets the log level to normal Use it like nemiver::LogStream out; out << nemiver::level_normal << "bla...
nemiver::common::endl
LogStream & endl(LogStream &)
log a '\n' and flushes the stream Use it like: nemiver::LogStream out; out << "hello"<< nemiver::endl...
nemiver::common::LogStream::StreamType
StreamType
Definition: nmv-log-stream.h:73
nemiver::common::LogStream
the log stream class it features logs on cout, cerr, and files. it also features log domains and log ...
Definition: nmv-log-stream.h:57
nemiver::common::LogStream::RFU1
@ RFU1
Definition: nmv-log-stream.h:78
NMV_GENERAL_DOMAIN
#define NMV_GENERAL_DOMAIN
Definition: nmv-log-stream.h:47
nemiver::common::timestamp
LogStream & timestamp(LogStream &)
logs a timestamp. Basically the the current date. You use it like: nemiver::LogStream out; out << nem...
nemiver::common::level_verbose
LogStream & level_verbose(LogStream &)
sets the log level to verbose Use it lik: nemiver::LogStream out; out << nemiver::level_verbose << "b...
nemiver::common::SafePtr< Priv >
common
Definition: nmv-proc-list-dialog.h:32