NCBI C++ ToolKit
syslog.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef CORELIB___SYSLOG__HPP
2 #define CORELIB___SYSLOG__HPP
3 
4 /* $Id: syslog.hpp 77596 2017-04-26 14:16:05Z ivanov $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author: Aaron Ucko
30  *
31  */
32 
33 /// @file syslog.hpp
34 /// Portable system-logging API.
35 ///
36 /// This interface encapsulates the syslog() facility on Unix.
37 
38 #include <corelib/ncbidiag.hpp>
39 #include <corelib/ncbimtx.hpp>
40 #include <corelib/ncbistr.hpp>
41 
42 /** @addtogroup Diagnostics
43  *
44  * @{
45  */
46 
48 
49 class IRegistry;
50 
52 public:
53  enum EFlags {
54  fNoOverride = 0x40000000, ///< never call openlog() ourselves
55  fCopyToStderr = 0x20000000, ///< maps to LOG_PERROR if available
56  fFallBackToConsole = 0x10000000, ///< LOG_CONS
57  fIncludePID = 0x08000000, ///< LOG_PID
58  fConnectNow = 0x04000000, ///< LOG_NDELAY
59  fNoChildWait = 0x02000000, ///< LOG_NOWAIT
60  fAllFlags = 0x7e000000
61  };
62  typedef int TFlags; // binary OR of EFlags
63 
64  enum EPriority {
72  eDebug
73  };
74 
75  enum EFacility {
96  eLocal7
97  };
98 
99  CSysLog(const string& ident = kEmptyStr, TFlags flags = fNoOverride,
100  EFacility default_facility = eDefaultFacility);
101  CSysLog(const string& ident, TFlags flags, int default_facility);
102  ~CSysLog();
103 
104  void Post(const SDiagMessage& mess);
105  void Post(const string& message, EPriority priority,
106  EFacility facility = eDefaultFacility);
107  void Post(const string& message, EPriority priority, int facility);
108 
109  void HonorRegistrySettings(const IRegistry* reg = 0);
110 
111  static const char* kLogName_Syslog;
112  string GetLogName(void) { return kLogName_Syslog; }
113 
114 private:
115  static int x_TranslateFlags (TFlags flags);
116  int x_TranslateFacility(EFacility facility);
117 
118  void x_Connect(void);
119 
120  DECLARE_CLASS_STATIC_MUTEX(sm_Mutex);
122  string m_Ident;
123  TFlags m_Flags;
125 };
126 
128 
130 
131 /* @} */
132 
133 #endif /* CORELIB___SYSLOG__HPP */
virtual void Post(const SDiagMessage &mess)=0
Post message to handler.
int TFlags
Definition: syslog.hpp:62
IRegistry –.
Definition: ncbireg.hpp:74
#define DECLARE_CLASS_STATIC_MUTEX(id)
Declare static mutex.
Definition: ncbimtx.hpp:501
#define NCBI_XNCBI_EXPORT
Definition: ncbi_export.h:1266
#define kEmptyStr
Definition: ncbistr.hpp:120
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
TFlags m_Flags
Definition: syslog.hpp:123
static CSysLog * sm_Current
Definition: syslog.hpp:121
static const char * kLogName_Syslog
Definition: syslog.hpp:111
SDiagMessage –.
Definition: ncbidiag.hpp:1572
int m_DefaultFacility
Definition: syslog.hpp:124
string GetLogName(void)
Get current diag posts destination.
Definition: syslog.hpp:112
Defines NCBI C++ diagnostic APIs, classes, and macros.
Multi-threading – mutexes; rw-locks; semaphore.
static uch flags
EPriority
Definition: syslog.hpp:64
string m_Ident
Definition: syslog.hpp:122
EFacility
Definition: syslog.hpp:75
CSysLog CSysLogDiagHandler
Definition: syslog.hpp:127
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
Modified on Sun Dec 17 15:53:06 2017 by modify_doxy.py rev. 546573