libDwm-0.6.0
DwmSysLogger.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $DwmPath: dwm/libDwm/tags/libDwm-0.6.0/include/DwmSysLogger.hh 8401 $
3 // @(#) $Id: DwmSysLogger.hh 8401 2016-04-17 06:44:31Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2007, 2016
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // 1. Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // 2. Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // 3. The names of the authors and copyright holders may not be used to
18 // endorse or promote products derived from this software without
19 // specific prior written permission.
20 //
21 // IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
22 // DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
23 // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
24 // EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
25 // DAMAGE.
26 //
27 // THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
28 // DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
29 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
30 // REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
31 // IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
33 // OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
34 // TRADEMARK OR OTHER RIGHTS.
35 //===========================================================================
36 
37 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 
42 #ifndef _DWMSYSLOGGER_HH_
43 #define _DWMSYSLOGGER_HH_
44 
45 extern "C" {
46 #include <errno.h>
47 #include <stdarg.h>
48 #include <syslog.h>
49 }
50 
51 #include <cstdio>
52 #include <map>
53 #include <mutex>
54 #include <string>
55 
56 namespace Dwm {
57 
58  //--------------------------------------------------------------------------
61  //--------------------------------------------------------------------------
62  class SysLogger
63  {
64  public:
65  //--------------------------------------------------------------------
82  //--------------------------------------------------------------------
83  static bool Open(const char *ident, int logopt, int facility);
84 
85  //------------------------------------------------------------------------
90  //------------------------------------------------------------------------
91  static bool Open(const char *ident, int logopt,
92  const std::string & facility);
93 
94  //--------------------------------------------------------------------
99  //--------------------------------------------------------------------
100  static bool Close();
101 
102  //--------------------------------------------------------------------
106  //--------------------------------------------------------------------
107  static bool Log(int priority, const char *message, ...);
108 
109  //--------------------------------------------------------------------
113  //--------------------------------------------------------------------
114  static bool Log(const std::string & filename, int lineno,
115  const std::string & function, int priority,
116  const char *message, ...);
117 
118  //--------------------------------------------------------------------
121  //--------------------------------------------------------------------
122  static bool VaLog(int priority, const std::string & message,
123  va_list & vaList);
124 
125  //--------------------------------------------------------------------
130  //--------------------------------------------------------------------
131  static bool VaLog(const std::string & filename, int lineno,
132  const std::string & function, int priority,
133  const std::string & message, va_list & vaList);
134 
135  //--------------------------------------------------------------------
138  //--------------------------------------------------------------------
139  static bool ShowPriorities();
140 
141  //--------------------------------------------------------------------
149  //--------------------------------------------------------------------
150  static bool ShowPriorities(bool showPriorities);
151 
152  //--------------------------------------------------------------------
156  //--------------------------------------------------------------------
157  static bool ShowFileLocation();
158 
159  //--------------------------------------------------------------------
163  //1 \c showFileLocation is false, the logger will not show file
165  //--------------------------------------------------------------------
166  static bool ShowFileLocation(bool showFileLocation);
167 
168  //--------------------------------------------------------------------
172  //--------------------------------------------------------------------
173  static bool ShowFunction();
174 
175  //--------------------------------------------------------------------
181  //--------------------------------------------------------------------
182  static bool ShowFunction(bool showFunction);
183 
184  //--------------------------------------------------------------------
186  //--------------------------------------------------------------------
187  static int MinimumPriority();
188 
189  //--------------------------------------------------------------------
193  //--------------------------------------------------------------------
194  static int MinimumPriority(int minimumPriority);
195 
196  //--------------------------------------------------------------------
200  //--------------------------------------------------------------------
201  static int MinimumPriority(const std::string & minimumPriority);
202 
203  //------------------------------------------------------------------------
206  //------------------------------------------------------------------------
207  static std::string PriorityTag(int priority);
208 
209  //------------------------------------------------------------------------
211  //------------------------------------------------------------------------
212  static int PriorityValue(const std::string & name);
213 
214  private:
215  static std::mutex _mutex;
216  static bool _isOpen;
217  static int _logOptions;
218  static std::string _ident;
219  static int _logFacility;
220  static bool _showPriorities;
221  static bool _showFunction;
222  static bool _showFileLocation;
223  static int _minimumPriority;
224  static std::map<int,std::string> _priorityTags;
225  static std::map<std::string,int> _priorityNames;
226  };
227 
228 } // namespace Dwm
229 
230 //----------------------------------------------------------------------------
235 //----------------------------------------------------------------------------
236 #define Syslog(...) \
237  Dwm::SysLogger::Log(__FILE__,__LINE__,__PRETTY_FUNCTION__,__VA_ARGS__)
238 
239 
240 #endif // _DWMSYSLOGGER_HH_
241 
242 //---------------------------- emacs settings -----------------------------
243 // Local Variables:
244 // mode: C++/la
245 // tab-width: 2
246 // indent-tabs-mode: nil
247 // c-basic-offset: 2
248 // End:
249 //-------------------------------------------------------------------------
static bool Close()
Closes the logger.
static bool ShowFileLocation()
If the logger is set to show file location information in Log(const std::string &, int, int, const char *, ...), returns true.
static int PriorityValue(const std::string &name)
Returns the priority value for the given priority name.
This class encapsulates syslog logging in global scope (all members are static).
Definition: DwmSysLogger.hh:62
static bool ShowFunction()
If the logger is set to show function information in Log(const string &, int, const string &...
static bool VaLog(int priority, const std::string &message, va_list &vaList)
Just like vsyslog(), takes a priority and a format string and a va_list.
static bool Log(int priority, const char *message,...)
Just like syslog(), takes a priority and a format string and variable list of arguments.
Definition: DwmBZ2IO.hh:67
static bool ShowPriorities()
If the logger is set to show priorities in each log message, returns true.
static bool Open(const char *ident, int logopt, int facility)
Opens the logger for syslog logging.
static std::string PriorityTag(int priority)
Returns the priority tag ("[F]", "[W]", et.
static int MinimumPriority()
Returns the lowest message priority that the logger will log.