-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLogger
More file actions
158 lines (156 loc) · 4.97 KB
/
Copy pathLogger
File metadata and controls
158 lines (156 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* -*- c++ -*- */
///////////////////////////////////////////
// Logger
// -------------------------------------
// file : Logger
// author : Ben Kietzman
// begin : 2023-05-18
// copyright : Ben Kietzman
// email : ben@kietzman.org
///////////////////////////////////////////
/*! \file Logger
* \brief Logger Class
*/
#ifndef _COMMON_LOGGER_
#define _COMMON_LOGGER_
// {{{ includes
#include <fcntl.h>
#include <fstream>
#include <iostream>
#include <list>
#include <mutex>
#include <netdb.h>
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <poll.h>
#include <pthread.h>
#ifdef COMMON_LINUX
#include <semaphore.h>
#endif
#include <string>
#ifdef COMMON_SOLARIS
#include <synch.h>
#endif
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <thread>
#include <vector>
using namespace std;
#include "Json"
#include "StringManip"
#include "Utility"
// }}}
extern "C++"
{
namespace common
{
// {{{ loggerreqdata
struct loggerreqdata
{
bool bSent;
int fdSocket;
string strBuffer[2];
};
// }}}
// {{{ Logger
//! Interfaces with Logger.
/*!
* Provides an interface to Logger.
*/
class Logger
{
protected:
bool m_bUseSingleSocket;
map<int, loggerreqdata *> m_requests;
size_t m_unThrottle;
size_t m_unUniqueID;
std::mutex m_mutexGetAddrInfo;
std::mutex m_mutexRequests;
std::mutex m_mutexUnique;
string m_strApplication;
string m_strPassword;
string m_strServer;
string m_strTimeout;
string m_strUser;
thread *m_pThreadRequest;
time_t m_ulModifyTime;
StringManip m_manip;
Utility *m_pUtility;
public:
Logger(string &strError);
~Logger();
/*! \fn bool log(map<string, string> label, const string strMessage, string &strError)
* \brief Sends a log request.
* \param label Contains the labels.
* \param strMessage Contains the message.
* \param strError Contains the error message.
* \return Returns a boolean true/false value.
*/
bool log(map<string, string> label, const string strMessage, string &strError);
/*! \fn bool message(map<string, string> label, const string strMessage, string &strError)
* \brief Sends a message request.
* \param label Contains the labels.
* \param strMessage Contains the message.
* \param strError Contains the error message.
* \return Returns a boolean true/false value.
*/
bool message(map<string, string> label, const string strMessage, string &strError);
/*! \fn bool request(Json *ptRequest, Json *ptResponse, string &strError)
* \brief Submits a Logger request.
* \param ptRequest Contains request.
* \param ptResponse Contains response.
* \param strError Contains the error message.
* \return Returns a boolean true/false value.
*/
bool request(Json *ptRequest, Json *ptResponse, string &strError);
/*! \fn bool request(Json *ptRequest, Json *ptResponse, time_t CTimeout, string &strError)
* \brief Submits a Logger request.
* \param ptRequest Contains request.
* \param ptResponse Contains response.
* \param CTimeout Contains the timeout.
* \param strError Contains the error message.
* \return Returns a boolean true/false value.
*/
bool request(Json *ptRequest, Json *ptResponse, time_t CTimeout, string &strError);
/*! \fn void requestThread()
* \brief Request thread.
*/
void requestThread();
/*! \fn void setCredentials(const string strApplication, const string strUser, const string strPassword)
* \brief Set the credentials.
* \param strApplication Contains the application.
* \param strUser Contains the user.
* \param strPassword Contains the password.
*/
void setCredentials(const string strApplication, const string strUser, const string strPassword);
/*! \fn void setServer(const string strServer)
* \brief Set the server.
* \param strServer Contains the server.
*/
void setServer(const string strServer);
/*! \fn void setThrottle(const size_t unThrottle)
* \brief Set the throttle.
* \param unThrottle Contains the throttle.
*/
void setThrottle(const size_t unThrottle);
/*! \fn void setTimeout(const string strTimeout)
* \brief Set the timeout.
* \param strTimeout Contains the timeout.
*/
void setTimeout(const string strTimeout);
/*! \fn void useSingleSocket(const bool bUseSingleSocket = true)
* \brief Use single socket. This should only be enabled within non-forking environments.
* \param bUseSingleSocket Contains the single socket value.
*/
void useSingleSocket(const bool bUseSingleSocket = true);
/*! \fn Utility *utility()
* \brief Interfaces with the Utility class.
* \return Returns a pointer to the Utility class.
*/
Utility *utility();
};
// }}}
}
}
#endif