xrpld
Loading...
Searching...
No Matches
LogLevel.cpp
1#include <xrpld/app/main/Application.h>
2#include <xrpld/rpc/Context.h>
3
4#include <xrpl/basics/Log.h>
5#include <xrpl/json/json_value.h>
6#include <xrpl/protocol/ErrorCodes.h>
7#include <xrpl/protocol/RPCErr.h>
8#include <xrpl/protocol/jss.h>
9
10#include <boost/algorithm/string/predicate.hpp>
11
12#include <string>
13#include <utility>
14#include <vector>
15
16namespace xrpl {
17
18json::Value
20{
21 // log_level
22 if (not context.params.isMember(jss::severity))
23 {
24 // get log severities
27
28 lev[jss::base] = Logs::toString(context.app.getLogs().threshold());
30 context.app.getLogs().partitionSeverities());
31 for (auto const& [k, v] : logTable)
32 lev[k] = v;
33
34 ret[jss::levels] = lev;
35 return ret;
36 }
37
38 auto const severity = Logs::fromString(context.params[jss::severity].asString());
39
40 if (not severity.has_value())
42
43 // log_level severity
44 if (not context.params.isMember(jss::partition))
45 {
46 // set base log threshold
47 context.app.getLogs().threshold(*severity);
49 }
50
51 // log_level partition severity base?
52 if (context.params.isMember(jss::partition))
53 {
54 // set partition threshold
55 std::string const partition(context.params[jss::partition].asString());
56
57 if (boost::iequals(partition, "base"))
58 {
59 context.app.getLogs().threshold(*severity);
60 }
61 else
62 {
63 context.app.getLogs().get(partition).threshold(*severity);
64 }
65
67 }
68
70}
71
72} // namespace xrpl
virtual Severity threshold() const
Returns the minimum severity level this sink will report.
Represents a JSON value.
Definition json_value.h:130
std::string asString() const
Returns the unquoted string value.
bool isMember(char const *key) const
Return true if the object has a member named key.
std::vector< std::pair< std::string, std::string > > partitionSeverities() const
Definition Log.cpp:158
static std::string toString(beast::Severity s)
Definition Log.cpp:203
beast::Journal::Sink & get(std::string const &name)
Definition Log.cpp:123
beast::Severity threshold() const
Definition Log.cpp:143
static std::optional< beast::Severity > fromString(std::string const &s)
Definition Log.cpp:228
virtual Logs & getLogs()=0
@ Object
object value (collection of name/value pairs).
Definition json_value.h:26
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ RpcInvalidParams
Definition ErrorCodes.h:66
json::Value doLogLevel(RPC::JsonContext &context)
Definition LogLevel.cpp:19
json::Value rpcError(ErrorCodeI iError)
Definition RPCErr.cpp:13
Application & app
Definition Context.h:21
json::Value params
Definition Context.h:43