rippled
Loading...
Searching...
No Matches
LogLevel.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012-2014 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/main/Application.h>
21#include <xrpld/rpc/Context.h>
22#include <xrpl/basics/Log.h>
23#include <xrpl/json/json_value.h>
24#include <xrpl/protocol/ErrorCodes.h>
25#include <xrpl/protocol/RPCErr.h>
26#include <xrpl/protocol/jss.h>
27#include <boost/algorithm/string/predicate.hpp>
28
29namespace ripple {
30
33{
34 // log_level
35 if (!context.params.isMember(jss::severity))
36 {
37 // get log severities
40
41 lev[jss::base] =
44 context.app.logs().partition_severities());
46 for (auto const& [k, v] : logTable)
47 lev[k] = v;
48
49 ret[jss::levels] = lev;
50 return ret;
51 }
52
53 LogSeverity const sv(
54 Logs::fromString(context.params[jss::severity].asString()));
55
56 if (sv == lsINVALID)
58
59 auto severity = Logs::toSeverity(sv);
60 // log_level severity
61 if (!context.params.isMember(jss::partition))
62 {
63 // set base log threshold
64 context.app.logs().threshold(severity);
65 return Json::objectValue;
66 }
67
68 // log_level partition severity base?
69 if (context.params.isMember(jss::partition))
70 {
71 // set partition threshold
72 std::string partition(context.params[jss::partition].asString());
73
74 if (boost::iequals(partition, "base"))
75 context.app.logs().threshold(severity);
76 else
77 context.app.logs().get(partition).threshold(severity);
78
79 return Json::objectValue;
80 }
81
83}
84
85} // namespace ripple
Represents a JSON value.
Definition: json_value.h:147
std::string asString() const
Returns the unquoted string value.
Definition: json_value.cpp:469
bool isMember(const char *key) const
Return true if the object has a member named key.
Definition: json_value.cpp:943
virtual Severity threshold() const
Returns the minimum severity level this sink will report.
virtual Logs & logs()=0
beast::Journal::Sink & get(std::string const &name)
Definition: Log.cpp:138
static LogSeverity fromString(std::string const &s)
Definition: Log.cpp:294
beast::severities::Severity threshold() const
Definition: Log.cpp:158
static std::string toString(LogSeverity s)
Definition: Log.cpp:271
static beast::severities::Severity toSeverity(LogSeverity level)
Definition: Log.cpp:245
std::vector< std::pair< std::string, std::string > > partition_severities() const
Definition: Log.cpp:173
static LogSeverity fromSeverity(beast::severities::Severity level)
Definition: Log.cpp:218
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:43
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
@ rpcINVALID_PARAMS
Definition: ErrorCodes.h:84
Json::Value rpcError(int iError)
Definition: RPCErr.cpp:29
Json::Value doLogLevel(RPC::JsonContext &)
Definition: LogLevel.cpp:32
LogSeverity
Definition: Log.h:35
@ lsINVALID
Definition: Log.h:36
Application & app
Definition: Context.h:42
Json::Value params
Definition: Context.h:64