EMANE  1.2.1
logserviceprovider.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 - Adjacent Link LLC, Bridgewater, New Jersey
3  * Copyright (c) 2008 - DRS CenGen, LLC, Columbia, Maryland
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of DRS CenGen, LLC nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef EMANELOGSERVICEPROVIDER_HEADER_
35 #define EMANELOGSERVICEPROVIDER_HEADER_
36 
37 #include "emane/types.h"
38 
39 #include <cstdarg>
40 
41 namespace EMANE
42 {
43  enum LogLevel
44  {
48  INFO_LEVEL = 3,
50  };
51 
52  class PlatformService;
53 
60  {
61  public:
62  virtual ~LogServiceProvider(){}
63 
71  virtual void log(LogLevel level, const char *fmt, ...)
72  __attribute__ ((format (printf, 3, 4))) = 0;
73 
74 
82  virtual void vlog(LogLevel level, const char *fmt, va_list ap) = 0;
83 
84 
91  virtual void log(LogLevel level, const Strings & strings) = 0;
92 
93 
100  template <typename Function>
101  void logfn(LogLevel level, Function fn);
102 
111  template <typename Function>
112  void logfn(LogLevel level, Function fn,const char *fmt, va_list ap);
113 
121  template <typename Function>
122  void logfn(LogLevel level, Function fn,const char *fmt, ...)
123  __attribute__ ((format (printf, 4, 5)));
124 
125  enum {MAX_LOG_LENGTH = 1024};
126 
127  protected:
129 
130  virtual bool isLogAllowed(LogLevel level) const = 0;
131 
132  virtual void log_i(LogLevel level, const Strings & strings) = 0;
133 
134  };
135 }
136 
137 #ifdef VERBOSE_LOGGING
138 
139 #define LOGGER_VERBOSE_LOGGING(logger,level,fmt,args...) \
140  (logger).log(level,fmt,## args)
141 
142 #define LOGGER_VERBOSE_LOGGING_FN(logger,level,fn) \
143  (logger).logfn(level,fn)
144 
145 #define LOGGER_VERBOSE_LOGGING_FN_VARGS(logger,level,fn,fmt,args...) \
146  (logger).logfn(level,fn,fmt,## args)
147 
148 
149 #else
150 
160 #define LOGGER_VERBOSE_LOGGING(logger,level,fmt,args...)
161 
172 #define LOGGER_VERBOSE_LOGGING_FN(logger,level,fn)
173 
187 #define LOGGER_VERBOSE_LOGGING_FN_VARGS(logger,level,fn,fmt,args...)
188 
189 #endif
190 
199 #define LOGGER_STANDARD_LOGGING(logger,level,fmt,args...) \
200  (logger).log(level,fmt,## args)
201 
211 #define LOGGER_STANDARD_LOGGING_FN(logger,level,fn) \
212  (logger).logfn(level,fn)
213 
227 #define LOGGER_STANDARD_LOGGING_FN_VARGS(logger,level,fn,fmt,args...) \
228  (logger).logfn(level,fn,fmt,## args)
229 
231 
232 #endif //EMANELOGSERVICEPROVIDER_HEADER_
233 
virtual bool isLogAllowed(LogLevel level) const =0
Log service provider interface.
virtual void log(LogLevel level, const char *fmt,...) __attribute__((format(printf
EMANE::NetworkAdapterException __attribute__
platform service
virtual void virtual void vlog(LogLevel level, const char *fmt, va_list ap)=0
std::list< std::string > Strings
Definition: types.h:66
virtual void log_i(LogLevel level, const Strings &strings)=0
void logfn(LogLevel level, Function fn)
Definition: agent.h:43