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
23#include <xrpl/basics/Log.h>
24#include <xrpl/json/json_value.h>
25#include <xrpl/protocol/ErrorCodes.h>
26#include <xrpl/protocol/RPCErr.h>
27#include <xrpl/protocol/jss.h>
28
29#include <boost/algorithm/string/predicate.hpp>
30
31namespace ripple {
32
35{
36 // log_level
37 if (!context.params.isMember(jss::severity))
38 {
39 // get log severities
42
43 lev[jss::base] =
46 context.app.logs().partition_severities());
48 for (auto const& [k, v] : logTable)
49 lev[k] = v;
50
51 ret[jss::levels] = lev;
52 return ret;
53 }
54
55 LogSeverity const sv(
56 Logs::fromString(context.params[jss::severity].asString()));
57
58 if (sv == lsINVALID)
60
61 auto severity = Logs::toSeverity(sv);
62 // log_level severity
63 if (!context.params.isMember(jss::partition))
64 {
65 // set base log threshold
66 context.app.logs().threshold(severity);
67 return Json::objectValue;
68 }
69
70 // log_level partition severity base?
71 if (context.params.isMember(jss::partition))
72 {
73 // set partition threshold
74 std::string partition(context.params[jss::partition].asString());
75
76 if (boost::iequals(partition, "base"))
77 context.app.logs().threshold(severity);
78 else
79 context.app.logs().get(partition).threshold(severity);
80
81 return Json::objectValue;
82 }
83
85}
86
87} // namespace ripple
Represents a JSON value.
Definition: json_value.h:149
std::string asString() const
Returns the unquoted string value.
Definition: json_value.cpp:482
bool isMember(char const *key) const
Return true if the object has a member named key.
Definition: json_value.cpp:962
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:146
static LogSeverity fromString(std::string const &s)
Definition: Log.cpp:302
beast::severities::Severity threshold() const
Definition: Log.cpp:166
static std::string toString(LogSeverity s)
Definition: Log.cpp:279
static beast::severities::Severity toSeverity(LogSeverity level)
Definition: Log.cpp:253
std::vector< std::pair< std::string, std::string > > partition_severities() const
Definition: Log.cpp:181
static LogSeverity fromSeverity(beast::severities::Severity level)
Definition: Log.cpp:226
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:45
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:25
@ rpcINVALID_PARAMS
Definition: ErrorCodes.h:84
Json::Value rpcError(int iError)
Definition: RPCErr.cpp:31
Json::Value doLogLevel(RPC::JsonContext &)
Definition: LogLevel.cpp:34
LogSeverity
Definition: Log.h:37
@ lsINVALID
Definition: Log.h:38
Application & app
Definition: Context.h:41
Json::Value params
Definition: Context.h:63