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 
32 {
33  // log_level
34  if (!context.params.isMember (jss::severity))
35  {
36  // get log severities
39 
40  lev[jss::base] =
43  context.app.logs().partition_severities());
45  for (auto const& [k, v] : logTable)
46  lev[k] = v;
47 
48  ret[jss::levels] = lev;
49  return ret;
50  }
51 
52  LogSeverity const sv (
53  Logs::fromString (context.params[jss::severity].asString ()));
54 
55  if (sv == lsINVALID)
56  return rpcError (rpcINVALID_PARAMS);
57 
58  auto severity = Logs::toSeverity(sv);
59  // log_level severity
60  if (!context.params.isMember (jss::partition))
61  {
62  // set base log threshold
63  context.app.logs().threshold(severity);
64  return Json::objectValue;
65  }
66 
67  // log_level partition severity base?
68  if (context.params.isMember (jss::partition))
69  {
70  // set partition threshold
71  std::string partition (context.params[jss::partition].asString ());
72 
73  if (boost::iequals (partition, "base"))
74  context.app.logs().threshold (severity);
75  else
76  context.app.logs().get(partition).threshold(severity);
77 
78  return Json::objectValue;
79  }
80 
81  return rpcError (rpcINVALID_PARAMS);
82 }
83 
84 } // ripple
ripple::RPC::JsonContext
Definition: Context.h:52
ripple::Logs::partition_severities
std::vector< std::pair< std::string, std::string > > partition_severities() const
Definition: Log.cpp:161
std::string
STL class.
ripple::rpcINVALID_PARAMS
@ rpcINVALID_PARAMS
Definition: ErrorCodes.h:85
std::vector
STL class.
ripple::lsINVALID
@ lsINVALID
Definition: Log.h:37
ripple::Logs::toString
static std::string toString(LogSeverity s)
Definition: Log.cpp:248
ripple::Logs::fromSeverity
static LogSeverity fromSeverity(beast::severities::Severity level)
Definition: Log.cpp:205
ripple::doLogLevel
Json::Value doLogLevel(RPC::JsonContext &)
Definition: LogLevel.cpp:31
Json::objectValue
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:45
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:265
Json::Value::isMember
bool isMember(const char *key) const
Return true if the object has a member named key.
Definition: json_value.cpp:961
std::map
STL class.
ripple::rpcError
Json::Value rpcError(int iError, Json::Value jvResult)
Definition: RPCErr.cpp:28
ripple::Logs::threshold
beast::severities::Severity threshold() const
Definition: Log.cpp:146
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:98
ripple::Logs::toSeverity
static beast::severities::Severity toSeverity(LogSeverity level)
Definition: Log.cpp:227
ripple::LogSeverity
LogSeverity
Definition: Log.h:35
ripple::RPC::JsonContext::params
Json::Value params
Definition: Context.h:63
ripple::Logs::get
beast::Journal::Sink & get(std::string const &name)
Definition: Log.cpp:125
Json::Value
Represents a JSON value.
Definition: json_value.h:141
Json::Value::asString
std::string asString() const
Returns the unquoted string value.
Definition: json_value.cpp:482