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());
47 for (auto const& [k, v] : logTable)
48 lev[k] = v;
49
50 ret[jss::levels] = lev;
51 return ret;
52 }
53
54 LogSeverity const sv(
55 Logs::fromString(context.params[jss::severity].asString()));
56
57 if (sv == lsINVALID)
59
60 auto severity = Logs::toSeverity(sv);
61 // log_level severity
62 if (!context.params.isMember(jss::partition))
63 {
64 // set base log threshold
65 context.app.logs().threshold(severity);
66 return Json::objectValue;
67 }
68
69 // log_level partition severity base?
70 if (context.params.isMember(jss::partition))
71 {
72 // set partition threshold
73 std::string partition(context.params[jss::partition].asString());
74
75 if (boost::iequals(partition, "base"))
76 context.app.logs().threshold(severity);
77 else
78 context.app.logs().get(partition).threshold(severity);
79
80 return Json::objectValue;
81 }
82
84}
85
86} // namespace ripple
Represents a JSON value.
Definition json_value.h:149
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.
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:308
beast::severities::Severity threshold() const
Definition Log.cpp:166
static std::string toString(LogSeverity s)
Definition Log.cpp:283
static beast::severities::Severity toSeverity(LogSeverity level)
Definition Log.cpp:255
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:38
@ lsINVALID
Definition Log.h:39
Application & app
Definition Context.h:41