-
Notifications
You must be signed in to change notification settings - Fork 34
/
configurator.cpp
173 lines (161 loc) · 5.29 KB
/
configurator.cpp
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/
#include "log/configurator.hpp"
#include <boost/program_options.hpp>
namespace kagome::log {
namespace {
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
std::string embedded_config(R"(
# ----------------
sinks:
- name: console
type: console
stream: stderr
thread: name
color: false
latency: 0
groups:
- name: main
sink: console
level: info
is_fallback: true
children:
- name: libp2p
level: off
- name: kagome
children:
- name: profile
- name: injector
- name: application
- name: rpc
children:
- name: rpc_transport
- name: api
children:
- name: author_api
- name: authorship
- name: blockchain
children:
- name: block_tree
- name: block_storage
- name: digest_tracker
- name: offchain
- name: authority
- name: crypto
children:
- name: bip39
- name: key_store
- name: ed25519
- name: ecdsa
- name: consensus
children:
- name: timeline
- name: babe
children:
- name: babe_lottery
- name: block_appender
- name: block_executor
- name: block_validator
- name: babe_config_repo
- name: grandpa
children:
- name: voting_round
- name: parachain
children:
- name: pvf_executor
- name: fragment_chain
- name: dispute
- name: runtime
children:
- name: runtime_api
- name: host_api
children:
- name: elliptic_curves_extension
- name: memory_extension
- name: io_extension
- name: crypto_extension
- name: storage_extension
- name: child_storage_extension
- name: offchain_extension
- name: misc_extension
- name: runtime_cache
- name: binaryen
- name: wavm
- name: wasmedge
- name: metrics
- name: telemetry
- name: network
children:
- name: reputation
- name: synchronizer
- name: authority_discovery
- name: kagome_protocols
children:
- name: block_announce_protocol
- name: grandpa_protocol
- name: propagate_transactions_protocol
- name: sync_protocol
- name: state_protocol
- name: warp_sync_protocol
- name: parachain_protocols
children:
- name: collation_protocol_vstaging
- name: validation_protocol_vstaging
- name: req_collation_protocol
- name: req_chunk_protocol
- name: req_available_data_protocol
- name: req_statement_protocol
- name: req_pov_protocol
- name: dispute_protocol
- name: req_attested_candidate_protocol
- name: changes_trie
- name: storage
children:
- name: trie
- name: trie_pruner
- name: transactions
- name: pubsub
- name: threads
- name: others
children:
- name: testing
- name: debug
# ----------------
)");
} // namespace
Configurator::Configurator(std::shared_ptr<PrevConfigurator> previous)
: ConfiguratorFromYAML(std::move(previous), embedded_config) {}
Configurator::Configurator(std::shared_ptr<PrevConfigurator> previous,
std::string config)
: ConfiguratorFromYAML(std::move(previous), std::move(config)) {}
Configurator::Configurator(std::shared_ptr<PrevConfigurator> previous,
filesystem::path path)
: ConfiguratorFromYAML(std::move(previous), std::move(path)) {}
std::optional<filesystem::path> Configurator::getLogConfigFile(
int argc, const char **argv) {
namespace po = boost::program_options;
po::options_description desc("General options");
desc.add_options()
// clang-format off
("logcfg", po::value<std::string>())
("log", po::value<std::string>()) // needed to avoid mix `--logcfg` and `--log`
// clang-format on
;
po::variables_map vm;
po::parsed_options parsed = po::command_line_parser(argc, argv)
.options(desc)
.allow_unregistered()
.run();
po::store(parsed, vm);
po::notify(vm);
if (auto it = vm.find("logcfg"); it != vm.end()) {
if (not it->second.defaulted()) {
return it->second.as<std::string>();
}
}
return std::nullopt;
}
} // namespace kagome::log