20#include <xrpl/basics/Log.h>
21#include <xrpl/basics/chrono.h>
22#include <xrpl/basics/contract.h>
23#include <xrpl/beast/utility/instrumentation.h>
24#include <boost/algorithm/string.hpp>
37 :
beast::Journal::
Sink(thresh, false), logs_(logs), partition_(partition)
47 logs_.write(level, partition_, text, console());
59 return m_stream !=
nullptr;
67 bool wasOpened =
false;
77 m_stream = std::move(stream);
102 if (m_stream !=
nullptr)
109 if (m_stream !=
nullptr)
134 return *result.first->second;
161 sink.second->threshold(thresh);
170 for (
auto const& [name, sink] :
sinks_)
183 format(s, text, level, partition);
199 return "The log file was closed and reopened.";
200 return "The log file could not be closed and reopened.";
206 return std::make_unique<Sink>(name,
threshold, *
this);
227 UNREACHABLE(
"ripple::Logs::fromSeverity : invalid severity");
253 UNREACHABLE(
"ripple::Logs::toSeverity : invalid severity");
280 UNREACHABLE(
"ripple::Logs::toString : invalid severity");
288 if (boost::iequals(s,
"trace"))
291 if (boost::iequals(s,
"debug"))
294 if (boost::iequals(s,
"info") || boost::iequals(s,
"information"))
297 if (boost::iequals(s,
"warn") || boost::iequals(s,
"warning") ||
298 boost::iequals(s,
"warnings"))
301 if (boost::iequals(s,
"error") || boost::iequals(s,
"errors"))
304 if (boost::iequals(s,
"fatal") || boost::iequals(s,
"fatals"))
317 output.
reserve(message.
size() + partition.size() + 100);
322 if (!partition.empty())
323 output += partition +
":";
344 UNREACHABLE(
"ripple::Logs::format : invalid severity");
362 auto scrubber = [&output](
char const* token) {
363 auto first = output.
find(token);
367 if (first != std::string::npos)
371 if (first != std::string::npos)
373 auto last = output.
find(
'\"', ++first);
375 if (last == std::string::npos)
376 last = output.
size();
378 output.
replace(first, last - first, last - first,
'*');
383 scrubber(
"\"seed\"");
384 scrubber(
"\"seed_hex\"");
385 scrubber(
"\"secret\"");
386 scrubber(
"\"master_key\"");
387 scrubber(
"\"master_seed\"");
388 scrubber(
"\"master_seed_hex\"");
389 scrubber(
"\"passphrase\"");
Abstraction for the underlying message destination.
A generic endpoint for log messages.
static Sink & getNullSink()
Returns a Sink which does nothing.
beast::Journal::Sink & get()
DebugSink(DebugSink &&)=delete
DebugSink(DebugSink const &)=delete
std::unique_ptr< beast::Journal::Sink > holder_
std::reference_wrapper< beast::Journal::Sink > sink_
DebugSink & operator=(DebugSink &&)=delete
DebugSink & operator=(DebugSink const &)=delete
std::unique_ptr< beast::Journal::Sink > set(std::unique_ptr< beast::Journal::Sink > sink)
bool isOpen() const noexcept
Determine if a system file is associated with the log.
bool closeAndReopen()
Close and re-open the system file associated with the log This assists in interoperating with externa...
void close()
Close the system file if it is open.
void write(char const *text)
write to the log file.
void writeln(char const *text)
write to the log file and append an end of line marker.
File()
Construct with no associated system file.
bool open(boost::filesystem::path const &path)
Associate a system file with the log.
void write(beast::severities::Severity level, std::string const &text) override
Write text to the sink at the specified severity.
Manages partitions for logging.
beast::Journal::Sink & get(std::string const &name)
beast::severities::Severity thresh_
static LogSeverity fromString(std::string const &s)
void write(beast::severities::Severity level, std::string const &partition, std::string const &text, bool console)
std::map< std::string, std::unique_ptr< beast::Journal::Sink >, boost::beast::iless > sinks_
beast::severities::Severity threshold() const
static std::string toString(LogSeverity s)
beast::Journal journal(std::string const &name)
virtual std::unique_ptr< beast::Journal::Sink > makeSink(std::string const &partition, beast::severities::Severity startingLevel)
static beast::severities::Severity toSeverity(LogSeverity level)
static void format(std::string &output, std::string const &message, beast::severities::Severity severity, std::string const &partition)
bool open(boost::filesystem::path const &pathToLogFile)
std::vector< std::pair< std::string, std::string > > partition_severities() const
beast::Journal::Sink & operator[](std::string const &name)
Logs(beast::severities::Severity level)
@ maximumMessageCharacters
static LogSeverity fromSeverity(beast::severities::Severity level)
T emplace_back(T... args)
A namespace for easy access to logging severity values.
Severity
Severity level / threshold of a Journal message.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
@ open
We haven't closed our ledger yet, but others might have.
beast::Journal debugLog()
Returns a debug journal.
std::string to_string(base_uint< Bits, Tag > const &a)
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
std::unique_ptr< beast::Journal::Sink > setDebugLogSink(std::unique_ptr< beast::Journal::Sink > sink)
Set the sink for the debug journal.
static DebugSink & debugSink()