-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFixClientLogFactory.h
More file actions
99 lines (72 loc) · 2.61 KB
/
FixClientLogFactory.h
File metadata and controls
99 lines (72 loc) · 2.61 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
#pragma once
#ifndef FIXCLIENTLOGFACTORY_H
#define FIXCLIENTLOGFACTORY_H
#include <quickfix/Log.h>
#include <quickfix/Exceptions.h>
#include <quickfix/SessionSettings.h>
#include <quickfix/FieldConvertors.h>
#include <spdlog/spdlog.h>
#include <spdlog/sinks/rotating_file_sink.h>
#include <string>
#include <utility>
#ifdef _MSC_VER
#pragma warning( disable : 4503 4355 4786 4290 )
#endif
class FixClientLogFactory : public FIX::LogFactory {
public:
explicit FixClientLogFactory(FIX::SessionSettings settings) : m_settings(std::move(settings)) {
auto dict = m_settings.get();
if (dict.has(FIX::FILE_LOG_PATH)) {
this->m_path = dict.getString(FIX::FILE_LOG_PATH);
} else {
throw FIX::ConfigError("Please Set FileLogPath");
}
auto logger = spdlog::rotating_logger_mt("global", this->m_path + "/Logs/RotatingFileLog.txt",
1024 * 1024 * 1024, 5);
spdlog::set_default_logger(logger);
};
explicit FixClientLogFactory(std::string path) : m_path(std::move(path)) {};
~FixClientLogFactory() override = default;
public:
FIX::Log *create() override;
FIX::Log *create(const FIX::SessionID &) override;
void destroy(FIX::Log *log) override;
private:
std::string m_path;
FIX::SessionSettings m_settings;
};
class FixClientLog : public FIX::Log {
public:
explicit FixClientLog(const std::string &path);
FixClientLog(const std::string &path, const FIX::SessionID &sessionID);
~FixClientLog() override = default;
void clear() override {}
void backup() override {}
void onIncoming(const std::string &value) override {
spdlog::info("onIncoming {} : {}", this->m_fullPrefix, FixClientLog::replaceControlChar(value));
}
void onOutgoing(const std::string &value) override {
spdlog::info("onOutgoing {} : {}", this->m_fullPrefix, FixClientLog::replaceControlChar(value));
}
void onEvent(const std::string &value) override {
spdlog::info("onEvent {} : {}", this->m_fullPrefix, FixClientLog::replaceControlChar(value));
}
private:
std::string generatePrefix(const FIX::SessionID &sessionID);
void init(std::string path, const std::string &prefix);
std::string m_path;
std::string m_fileName;
std::string m_fullPrefix;
static std::string replaceControlChar(const std::string &input) {
std::string output;
for (char c : input) {
if (c == '\001') {
output += " | ";
} else {
output += c;
}
}
return output;
}
};
#endif