rippled
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
12namespace xrpl {
13
16{
17 // log_level
18 if (!context.params.isMember(jss::severity))
19 {
20 // get log severities
23
24 lev[jss::base] = Logs::toString(Logs::fromSeverity(context.app.getLogs().threshold()));
26 context.app.getLogs().partition_severities());
27 for (auto const& [k, v] : logTable)
28 lev[k] = v;
29
30 ret[jss::levels] = lev;
31 return ret;
32 }
33
34 LogSeverity const sv(Logs::fromString(context.params[jss::severity].asString()));
35
36 if (sv == lsINVALID)
38
39 auto severity = Logs::toSeverity(sv);
40 // log_level severity
41 if (!context.params.isMember(jss::partition))
42 {
43 // set base log threshold
44 context.app.getLogs().threshold(severity);
45 return Json::objectValue;
46 }
47
48 // log_level partition severity base?
49 if (context.params.isMember(jss::partition))
50 {
51 // set partition threshold
52 std::string const partition(context.params[jss::partition].asString());
53
54 if (boost::iequals(partition, "base"))
55 {
56 context.app.getLogs().threshold(severity);
57 }
58 else
59 {
60 context.app.getLogs().get(partition).threshold(severity);
61 }
62
63 return Json::objectValue;
64 }
65
67}
68
69} // namespace xrpl
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.
virtual Severity threshold() const
Returns the minimum severity level this sink will report.
beast::severities::Severity threshold() const
Definition Log.cpp:140
beast::Journal::Sink & get(std::string const &name)
Definition Log.cpp:120
static LogSeverity fromSeverity(beast::severities::Severity level)
Definition Log.cpp:200
std::vector< std::pair< std::string, std::string > > partition_severities() const
Definition Log.cpp:155
static LogSeverity fromString(std::string const &s)
Definition Log.cpp:282
static std::string toString(LogSeverity s)
Definition Log.cpp:257
static beast::severities::Severity toSeverity(LogSeverity level)
Definition Log.cpp:229
virtual Logs & getLogs()=0
@ objectValue
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
LogSeverity
Definition Log.h:18
@ lsINVALID
Definition Log.h:19
Json::Value rpcError(error_code_i iError)
Definition RPCErr.cpp:12
Json::Value doLogLevel(RPC::JsonContext &context)
Definition LogLevel.cpp:15
@ rpcINVALID_PARAMS
Definition ErrorCodes.h:64
Application & app
Definition Context.h:21
Json::Value params
Definition Context.h:43