Logging_impl.h
Go to the documentation of this file.
1 /*
2  * This file is protected by Copyright. Please refer to the COPYRIGHT file
3  * distributed with this source distribution.
4  *
5  * This file is part of REDHAWK core.
6  *
7  * REDHAWK core is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * REDHAWK core is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program. If not, see http://www.gnu.org/licenses/.
19  */
20 #ifndef LOGGING_IMPL_H
21 #define LOGGING_IMPL_H
22 #include <boost/shared_ptr.hpp>
23 #include <boost/make_shared.hpp>
24 #include <boost/ref.hpp>
25 #include "ossie/CF/LogInterfaces.h"
26 #include "ossie/logging/rh_logger.h"
27 #include "ossie/logging/loghelpers.h"
28 #include "ossie/EventChannelSupport.h"
29 #include "ossie/Autocomplete.h"
30 
32 #ifdef BEGIN_AUTOCOMPLETE_IGNORE
33  : public virtual POA_CF::Logging
34 #endif
35 {
36  public:
37 
38  Logging_impl ();
39 
40  virtual ~Logging_impl() {};
41 
42  // override this method to return the current logging configuration information
43  char * getLogConfig ();
44 
45  // override this method to accept logging configuration information as a string
46  void setLogConfig( const char *config_contents );
47 
48  // override this method to accept a string object that contains a URL.
49  // the contents of the URL will be used as the logging configuration information
50  void setLogConfigURL ( const char *config_url );
51 
52  // returns the current logging level state
53  CF::LogLevel log_level();
54 
55  // sets the current logging level for the resource, if LogLevelCallback is set
56  void log_level( const CF::LogLevel newLevel );
57 
58  // override this method to accept logging configuration information as a string
59  void setLogLevel( const char *logger_id, const CF::LogLevel newLevel ) throw (CF::UnknownIdentifier);
60 
61  // returns the current logger assigned to the resource, by default it is the root logger
62  LOGGER getLogger();
63 
64  // Get a new logger object and if assign to resource if param is true
65  LOGGER getLogger( const std::string &logger_name, const bool assignToResource=false);
66 
67 
68  /*
69  * LogEventConsumer
70  */
71 
72  CF::LogEventSequence *retrieve_records( CORBA::ULong &howMany,
73  CORBA::ULong startingRecord );
74  CF::LogEventSequence *retrieve_records_by_date( CORBA::ULong &howMany,
75  CORBA::ULongLong to_timeStamp );
76  CF::LogEventSequence *retrieve_records_from_date( CORBA::ULong &howMany,
77  CORBA::ULongLong from_timeStamp );
78 
79  /*
80  *
81  *
82  */
83  void setLoggingMacros ( ossie::logging::MacroTable &tbl, bool applyCtx );
84 
85  /*
86  * setResourceContext
87  *
88  *
89  */
90  void setResourceContext( ossie::logging::ResourceCtxPtr ctx );
91 
92  /*
93  * setLoggingContext
94  * Set the logging context for each type of Resource.
95  *
96  */
97  void setLoggingContext( ossie::logging::ResourceCtxPtr ctx );
98 
99  /*
100  * setLoggingContext
101  * Set the logging context for each type of Resource.
102  *
103  */
104  void setLoggingContext( const std::string &url, int loglevel, ossie::logging::ResourceCtxPtr ctx );
105 
106  /*
107  * saveLoggingContext
108  * Save the logging context for each type of Resource, do not apply setting to
109  * underlying logging library
110  *
111  */
112  void saveLoggingContext( const std::string &url, int loglevel, ossie::logging::ResourceCtxPtr ctx );
113 
114 
115  //
116  // RESOLVE: refactor to use boost::function and boost::bind
117  //
118 
119  typedef void (*LogConfigCallbackFn)(const char *config_data);
120 
121  typedef void (*LogLevelCallbackFn)(const char *logid, const CF::LogLevel&);
122 
123 
124  //
125  //
126  //
128 
129  public:
130  virtual void operator() ( const char *logid, const CF::LogLevel &level ) = 0;
131  virtual ~LogLevelListener() {};
132 
133  };
134 
135  /*
136  * Allow for member functions to receive configuration notifications
137  */
138  template <class T>
140  {
141  public:
142  typedef boost::shared_ptr< MemberLogLevelListener< T > > SPtr;
143 
144  typedef void (T::*MemberFn)( const char *logid, const CF::LogLevel &level );
145 
146  static SPtr Create( T &target, MemberFn func ){
147  return SPtr( new MemberLogLevelListener(target, func ) );
148  };
149 
150  virtual void operator() ( const char *logid, const CF::LogLevel &level )
151  {
152  (target_.*func_)(logid, level);
153  }
154 
155  // Only allow PropertySet_impl to instantiate this class.
156  MemberLogLevelListener ( T& target, MemberFn func) :
157  target_(target),
158  func_(func)
159  {
160  }
161  private:
162  T& target_;
163  MemberFn func_;
164  };
165 
166  /*
167  * Wrap Callback functions as LogLevelListener objects
168  */
170  {
171  public:
172  virtual void operator() ( const char *logid, const CF::LogLevel &level )
173  {
174  (*func_)(logid, level);
175  }
176 
178  func_(func)
179  {
180  }
181 
182  private:
183 
184  LogLevelCallbackFn func_;
185  };
186 
187 
188 
189  //
190  //
191  //
193 
194  public:
195  virtual void operator() ( const char *config_data ) = 0;
196  virtual ~LogConfigListener() {};
197 
198  };
199 
200  /*
201  * Allow for member functions to receive configuration notifications
202  */
203  template <class T>
205  {
206  public:
207  typedef boost::shared_ptr< MemberLogConfigListener< T > > SPtr;
208 
209  typedef void (T::*MemberFn)( const char *config_data );
210 
211  static SPtr Create( T &target, MemberFn func ){
212  return SPtr( new MemberLogConfigListener(target, func ) );
213  };
214 
215  virtual void operator() ( const char *config_data )
216  {
217  (target_.*func_)(config_data);
218  }
219 
220  // Only allow PropertySet_impl to instantiate this class.
221  MemberLogConfigListener ( T& target, MemberFn func) :
222  target_(target),
223  func_(func)
224  {
225  }
226  private:
227  T& target_;
228  MemberFn func_;
229  };
230 
231  /*
232  * Wrap Callback functions as LogConfigListener objects
233  */
235  {
236  public:
237  virtual void operator() ( const char *config_data )
238  {
239  (*func_)(config_data);
240  }
241 
243  func_(func)
244  {
245  }
246 
247  private:
248 
249  LogConfigCallbackFn func_;
250  };
251 
252 
253  protected:
254 
255  typedef boost::shared_ptr< LogConfigListener > LogConfigListenerPtr;
256  typedef boost::shared_ptr< LogLevelListener > LogLevelListenerPtr;
257 
258  template< typename T > inline
259  void setLogConfigListener(T &target, void (T::*func)( const char *config_data ) ) {
260  logConfigCallback = boost::make_shared< MemberLogConfigListener< T > >( boost::ref(target), func );
261  };
262 
263  template< typename T > inline
264  void setLogConfigListener(T *target, void (T::*func)( const char *config_data ) ) {
265  logConfigCallback = boost::make_shared< MemberLogConfigListener< T > >( boost::ref(*target), func );
266  };
267 
268  template< typename T > inline
269  void setLogLevelListener(T &target, void (T::*func)( const char *logid, const CF::LogLevel &level ) ) {
270  logLevelCallback = boost::make_shared< MemberLogLevelListener< T > >( boost::ref(target), func );
271  };
272 
273  template< typename T > inline
274  void setLogLevelListener(T *target, void (T::*func)( const char *logid, const CF::LogLevel &level ) ) {
275  logLevelCallback = boost::make_shared< MemberLogLevelListener< T > >( boost::ref(*target), func );
276  };
277 
278 
279  virtual void setLogConfigCallback(LogConfigListener *func);
280  virtual void setLogConfigCallback(LogConfigCallbackFn func);
281  virtual void setLogLevelCallback(LogLevelListener *func);
282  virtual void setLogLevelCallback(LogLevelCallbackFn func);
283 
284  // logger identifier
285  std::string _logName;
286 
287  // current logging level set for this component via execparams, or LogConfiguration API
288  CF::LogLevel _logLevel;
289 
290  // current logging object
291  LOGGER _logger;
292 
293  // logging macro defintion table;
294  ossie::logging::MacroTable _loggingMacros;
295 
296  private:
297 
298  // logging configuration data,
299  std::string _logCfgContents;
300 
301  std::string _logCfgURL;
302 
303  ossie::logging::ResourceCtxPtr _loggingCtx;
304 
305  // Event channel to listen for configuration and log level changes
306  boost::shared_ptr< ossie::events::PushEventConsumer > logConfigChannel;
307 
308  // callback to notify when logging configuration change is requested
309  LogConfigListenerPtr logConfigCallback;
310 
311  // callback to notify when a logging level change is requested
312  LogLevelListenerPtr logLevelCallback;
313 
314 };
315 #endif
CF::LogLevel _logLevel
Definition: Logging_impl.h:288
std::string _logName
Definition: Logging_impl.h:285
virtual void operator()(const char *config_data)
Definition: Logging_impl.h:215
Definition: Logging_impl.h:139
void(* LogConfigCallbackFn)(const char *config_data)
Definition: Logging_impl.h:119
Definition: Logging_impl.h:204
void setLogLevelListener(T *target, void(T::*func)(const char *logid, const CF::LogLevel &level))
Definition: Logging_impl.h:274
void setLogConfig(const char *config_contents)
char * getLogConfig()
ossie::logging::MacroTable _loggingMacros
Definition: Logging_impl.h:294
boost::shared_ptr< LogLevelListener > LogLevelListenerPtr
Definition: Logging_impl.h:256
void setLogLevelListener(T &target, void(T::*func)(const char *logid, const CF::LogLevel &level))
Definition: Logging_impl.h:269
void(T::* MemberFn)(const char *logid, const CF::LogLevel &level)
Definition: Logging_impl.h:144
void setLoggingContext(ossie::logging::ResourceCtxPtr ctx)
void setLogConfigListener(T &target, void(T::*func)(const char *config_data))
Definition: Logging_impl.h:259
MemberLogLevelListener(T &target, MemberFn func)
Definition: Logging_impl.h:156
boost::shared_ptr< MemberLogConfigListener< T > > SPtr
Definition: Logging_impl.h:207
StaticLogConfigListener(LogConfigCallbackFn func)
Definition: Logging_impl.h:242
CF::LogEventSequence * retrieve_records_by_date(CORBA::ULong &howMany, CORBA::ULongLong to_timeStamp)
LOGGER _logger
Definition: Logging_impl.h:291
virtual void setLogConfigCallback(LogConfigListener *func)
CF::LogEventSequence * retrieve_records_from_date(CORBA::ULong &howMany, CORBA::ULongLong from_timeStamp)
void saveLoggingContext(const std::string &url, int loglevel, ossie::logging::ResourceCtxPtr ctx)
LOGGER getLogger()
virtual void operator()(const char *config_data)=0
CF::LogLevel log_level()
Definition: Logging_impl.h:31
virtual void setLogLevelCallback(LogLevelListener *func)
void setResourceContext(ossie::logging::ResourceCtxPtr ctx)
virtual ~LogConfigListener()
Definition: Logging_impl.h:196
void setLogLevel(const char *logger_id, const CF::LogLevel newLevel)
static SPtr Create(T &target, MemberFn func)
Definition: Logging_impl.h:146
void setLogConfigListener(T *target, void(T::*func)(const char *config_data))
Definition: Logging_impl.h:264
void(T::* MemberFn)(const char *config_data)
Definition: Logging_impl.h:209
virtual void operator()(const char *logid, const CF::LogLevel &level)=0
boost::shared_ptr< MemberLogLevelListener< T > > SPtr
Definition: Logging_impl.h:142
StaticLogLevelListener(LogLevelCallbackFn func)
Definition: Logging_impl.h:177
CF::LogEventSequence * retrieve_records(CORBA::ULong &howMany, CORBA::ULong startingRecord)
Definition: Logging_impl.h:169
virtual ~LogLevelListener()
Definition: Logging_impl.h:131
boost::shared_ptr< LogConfigListener > LogConfigListenerPtr
Definition: Logging_impl.h:255
virtual ~Logging_impl()
Definition: Logging_impl.h:40
void setLoggingMacros(ossie::logging::MacroTable &tbl, bool applyCtx)
Definition: Logging_impl.h:192
MemberLogConfigListener(T &target, MemberFn func)
Definition: Logging_impl.h:221
Definition: Logging_impl.h:234
virtual void operator()(const char *config_data)
Definition: Logging_impl.h:237
void setLogConfigURL(const char *config_url)
void(* LogLevelCallbackFn)(const char *logid, const CF::LogLevel &)
Definition: Logging_impl.h:121
Definition: Logging_impl.h:127
virtual void operator()(const char *logid, const CF::LogLevel &level)
Definition: Logging_impl.h:172
static SPtr Create(T &target, MemberFn func)
Definition: Logging_impl.h:211
virtual void operator()(const char *logid, const CF::LogLevel &level)
Definition: Logging_impl.h:150