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 87681 2019-09-23 03:58:14Z lavr $
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 
41 /** @addtogroup Diagnostics
42  *
43  * @{
44  */
45 
47 
48 class IRegistry;
49 
51 public:
52  enum EFlags {
53  fNoOverride = 0x40000000, ///< never call openlog() ourselves
54  fCopyToStderr = 0x20000000, ///< maps to LOG_PERROR if available
55  fFallBackToConsole = 0x10000000, ///< LOG_CONS
56  fIncludePID = 0x08000000, ///< LOG_PID
57  fConnectNow = 0x04000000, ///< LOG_NDELAY
58  fNoChildWait = 0x02000000, ///< LOG_NOWAIT
59  fAllFlags = 0x7e000000
60  };
61  typedef int TFlags; // binary OR of EFlags
62 
63  enum EPriority {
71  eDebug
72  };
73 
74  enum EFacility {
95  eLocal7
96  };
97 
98  CSysLog(const string& ident = kEmptyStr, TFlags flags = fNoOverride,
99  EFacility default_facility = eDefaultFacility);
100  CSysLog(const string& ident, TFlags flags, int default_facility);
101  ~CSysLog();
102 
103  void Post(const SDiagMessage& mess);
104  void Post(const string& message, EPriority priority,
105  EFacility facility = eDefaultFacility);
106  void Post(const string& message, EPriority priority, int facility);
107 
108  void HonorRegistrySettings(const IRegistry* reg = 0);
109 
110  static const char* kLogName_Syslog;
111  string GetLogName(void) { return kLogName_Syslog; }
112 
113 private:
114  static int x_TranslateFlags (TFlags flags);
115  int x_TranslateFacility(EFacility facility);
116 
117  void x_Connect(void);
118 
121  string m_Ident;
124 };
125 
127 
129 
130 /* @} */
131 
132 #endif /* CORELIB___SYSLOG__HPP */
IRegistry –.
Definition: ncbireg.hpp:73
static uch flags
EFacility
Definition: syslog.hpp:74
string m_Ident
Definition: syslog.hpp:121
int m_DefaultFacility
Definition: syslog.hpp:123
virtual void Post(const SDiagMessage &mess)=0
Post message to handler.
int TFlags
Definition: syslog.hpp:61
EPriority
Definition: syslog.hpp:63
static CSysLog * sm_Current
Definition: syslog.hpp:120
static const char * kLogName_Syslog
Definition: syslog.hpp:110
string GetLogName(void)
Get current diag posts destination.
Definition: syslog.hpp:111
CSysLog CSysLogDiagHandler
Definition: syslog.hpp:126
DECLARE_CLASS_STATIC_MUTEX(sm_Mutex)
TFlags m_Flags
Definition: syslog.hpp:122
@ eAuthPriv
Definition: syslog.hpp:86
@ eLocal2
Definition: syslog.hpp:90
@ eLocal6
Definition: syslog.hpp:94
@ eCron
Definition: syslog.hpp:85
@ eDefaultFacility
Definition: syslog.hpp:75
@ eUUCP
Definition: syslog.hpp:84
@ eKernel
Definition: syslog.hpp:76
@ eMail
Definition: syslog.hpp:78
@ eLocal1
Definition: syslog.hpp:89
@ eLocal3
Definition: syslog.hpp:91
@ eSysLog
Definition: syslog.hpp:81
@ eLocal5
Definition: syslog.hpp:93
@ eNews
Definition: syslog.hpp:83
@ eDaemon
Definition: syslog.hpp:79
@ eLocal0
Definition: syslog.hpp:88
@ eFTP
Definition: syslog.hpp:87
@ eUser
Definition: syslog.hpp:77
@ eAuth
Definition: syslog.hpp:80
@ eLocal4
Definition: syslog.hpp:92
@ eLPR
Definition: syslog.hpp:82
@ eNotice
Definition: syslog.hpp:69
@ eCritical
Definition: syslog.hpp:66
@ eWarning
Definition: syslog.hpp:68
@ eAlert
Definition: syslog.hpp:65
@ eInfo
Definition: syslog.hpp:70
@ eEmergency
Definition: syslog.hpp:64
@ eError
Definition: syslog.hpp:67
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
#define NCBI_XNCBI_EXPORT
Definition: ncbi_export.h:1283
Defines NCBI C++ diagnostic APIs, classes, and macros.
Multi-threading – mutexes; rw-locks; semaphore.
SDiagMessage –.
Definition: ncbidiag.hpp:1599
Modified on Mon Mar 04 05:11:33 2024 by modify_doxy.py rev. 669887