rippled
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 <ripple/app/main/Application.h>
21 #include <ripple/basics/Log.h>
22 #include <ripple/json/json_value.h>
23 #include <ripple/net/RPCErr.h>
24 #include <ripple/protocol/ErrorCodes.h>
25 #include <ripple/protocol/jss.h>
26 #include <ripple/rpc/Context.h>
27 #include <boost/algorithm/string/predicate.hpp>
28 
29 namespace 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
ripple::RPC::JsonContext
Definition: Context.h:53
ripple::Logs::partition_severities
std::vector< std::pair< std::string, std::string > > partition_severities() const
Definition: Log.cpp:165
std::string
STL class.
ripple::rpcINVALID_PARAMS
@ rpcINVALID_PARAMS
Definition: ErrorCodes.h:84
ripple::rpcError
Json::Value rpcError(int iError)
Definition: RPCErr.cpp:29
std::vector
STL class.
ripple::lsINVALID
@ lsINVALID
Definition: Log.h:36
ripple::Logs::toString
static std::string toString(LogSeverity s)
Definition: Log.cpp:263
ripple::Logs::fromSeverity
static LogSeverity fromSeverity(beast::severities::Severity level)
Definition: Log.cpp:210
ripple::doLogLevel
Json::Value doLogLevel(RPC::JsonContext &)
Definition: LogLevel.cpp:32
Json::objectValue
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:43
ripple::RPC::Context::app
Application & app
Definition: Context.h:42
ripple::Application::logs
virtual Logs & logs()=0
ripple::Logs::fromString
static LogSeverity fromString(std::string const &s)
Definition: Log.cpp:286
Json::Value::isMember
bool isMember(const char *key) const
Return true if the object has a member named key.
Definition: json_value.cpp:932
std::map
STL class.
ripple::Logs::threshold
beast::severities::Severity threshold() const
Definition: Log.cpp:150
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
beast::Journal::Sink::threshold
virtual Severity threshold() const
Returns the minimum severity level this sink will report.
Definition: beast_Journal.cpp:106
ripple::Logs::toSeverity
static beast::severities::Severity toSeverity(LogSeverity level)
Definition: Log.cpp:237
ripple::LogSeverity
LogSeverity
Definition: Log.h:35
ripple::RPC::JsonContext::params
Json::Value params
Definition: Context.h:64
ripple::Logs::get
beast::Journal::Sink & get(std::string const &name)
Definition: Log.cpp:130
Json::Value
Represents a JSON value.
Definition: json_value.h:145
Json::Value::asString
std::string asString() const
Returns the unquoted string value.
Definition: json_value.cpp:469