-
-
Notifications
You must be signed in to change notification settings - Fork 226
/
Copy pathtaccesslog.h
83 lines (68 loc) · 1.82 KB
/
taccesslog.h
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
#pragma once
#include <QByteArray>
#include <QDateTime>
#include <QElapsedTimer>
#include <TGlobal>
class T_CORE_EXPORT TAccessLog {
public:
TAccessLog();
TAccessLog(const QByteArray &remoteHost, const QByteArray &request, int dur);
QByteArray toByteArray(const QByteArray &layout, const QByteArray &dateTimeFormat) const;
QDateTime timestamp;
QByteArray remoteHost;
QByteArray request;
int statusCode {0};
int responseBytes {0};
int duration {0};
};
class T_CORE_EXPORT TAccessLogger {
public:
TAccessLogger();
TAccessLogger(const TAccessLogger &other) = delete;
TAccessLogger(TAccessLogger &&other);
~TAccessLogger();
TAccessLogger &operator=(const TAccessLogger &other) = delete;
TAccessLogger &operator=(TAccessLogger &&other);
void open();
void write();
void close();
void setTimestamp(const QDateTime ×tamp)
{
if (_accessLog) {
_accessLog->timestamp = timestamp;
}
}
void setRemoteHost(const QByteArray &host)
{
if (_accessLog) {
_accessLog->remoteHost = host;
}
}
void setRequest(const QByteArray &request)
{
if (_accessLog) {
_accessLog->request = request;
}
}
int statusCode() const { return (_accessLog) ? _accessLog->statusCode : -1; }
void setStatusCode(int statusCode)
{
if (_accessLog) {
_accessLog->statusCode = statusCode;
}
}
int responseBytes() const { return (_accessLog) ? _accessLog->responseBytes : -1; }
void setResponseBytes(int bytes)
{
if (_accessLog) {
_accessLog->responseBytes = bytes;
}
}
void startElapsedTimer()
{
_timer.start();
}
private:
TAccessLog *_accessLog {nullptr};
QElapsedTimer _timer;
};