1#include <xrpl/basics/Log.h>
3#include <xrpl/basics/chrono.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/beast/utility/instrumentation.h>
7#include <boost/algorithm/string/predicate.hpp>
8#include <boost/filesystem/path.hpp>
61 bool wasOpened =
false;
119 return file_.open(pathToLogFile);
127 return *result.first->second;
154 sink.second->threshold(thresh);
163 for (
auto const& [name, sink] :
sinks_)
176 format(s, text, level, partition);
190 bool const wasOpened =
file_.closeAndReopen();
192 return "The log file was closed and reopened.";
193 return "The log file could not be closed and reopened.";
221 UNREACHABLE(
"xrpl::Logs::toString : invalid severity");
230 if (boost::iequals(s,
"trace"))
233 if (boost::iequals(s,
"debug"))
236 if (boost::iequals(s,
"info") || boost::iequals(s,
"information"))
239 if (boost::iequals(s,
"warn") || boost::iequals(s,
"warning") || boost::iequals(s,
"warnings"))
242 if (boost::iequals(s,
"error") || boost::iequals(s,
"errors"))
245 if (boost::iequals(s,
"fatal") || boost::iequals(s,
"fatals"))
258 output.
reserve(message.
size() + partition.size() + 100);
263 if (!partition.empty())
264 output += partition +
":";
269 case Severity::Trace:
272 case Severity::Debug:
278 case Severity::Warning:
281 case Severity::Error:
286 UNREACHABLE(
"xrpl::Logs::format : invalid severity");
289 case Severity::Fatal:
305 auto scrubber = [&output](
char const* token) {
306 auto first = output.
find(token);
310 if (first != std::string::npos)
314 if (first != std::string::npos)
316 auto last = output.
find(
'\"', ++first);
318 if (last == std::string::npos)
319 last = output.
size();
321 output.
replace(first, last - first, last - first,
'*');
326 scrubber(
"\"seed\"");
327 scrubber(
"\"seed_hex\"");
328 scrubber(
"\"secret\"");
329 scrubber(
"\"master_key\"");
330 scrubber(
"\"master_seed\"");
331 scrubber(
"\"master_seed_hex\"");
332 scrubber(
"\"passphrase\"");
Abstraction for the underlying message destination.
virtual bool console() const
Returns true if a message is also written to the Output Window (MSVC).
A generic endpoint for log messages.
static Sink & getNullSink()
Returns a Sink which does nothing.
std::unique_ptr< beast::Journal::Sink > set(std::unique_ptr< beast::Journal::Sink > sink)
DebugSink(DebugSink &&)=delete
beast::Journal::Sink & get()
DebugSink & operator=(DebugSink const &)=delete
DebugSink & operator=(DebugSink &&)=delete
std::reference_wrapper< beast::Journal::Sink > sink_
DebugSink(DebugSink const &)=delete
std::unique_ptr< beast::Journal::Sink > holder_
void writeln(char const *text)
write to the log file and append an end of line marker.
bool open(boost::filesystem::path const &path)
Associate a system file with the log.
bool closeAndReopen()
Close and re-open the system file associated with the log This assists in interoperating with externa...
boost::filesystem::path path_
void write(char const *text)
write to the log file.
bool isOpen() const noexcept
Determine if a system file is associated with the log.
void close()
Close the system file if it is open.
std::unique_ptr< std::ofstream > stream_
File()
Construct with no associated system file.
void writeAlways(beast::Severity level, std::string const &text) override
Bypass filter and write text to the sink at the specified severity.
void write(beast::Severity level, std::string const &text) override
Write text to the sink at the specified severity.
Sink(std::string partition, beast::Severity thresh, Logs &logs)
std::vector< std::pair< std::string, std::string > > partitionSeverities() const
bool open(boost::filesystem::path const &pathToLogFile)
beast::Journal journal(std::string const &name)
static std::string toString(beast::Severity s)
beast::Journal::Sink & get(std::string const &name)
beast::Severity threshold() const
void write(beast::Severity level, std::string const &partition, std::string const &text, bool console)
static void format(std::string &output, std::string const &message, beast::Severity severity, std::string const &partition)
static std::optional< beast::Severity > fromString(std::string const &s)
std::map< std::string, std::unique_ptr< beast::Journal::Sink >, boost::beast::iless > sinks_
static constexpr auto kMaximumMessageCharacters
Logs(beast::Severity level)
virtual std::unique_ptr< beast::Journal::Sink > makeSink(std::string const &partition, beast::Severity startingLevel)
beast::Journal::Sink & operator[](std::string const &name)
T emplace_back(T... args)
Severity
Severity level / threshold of a Journal message.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
beast::Journal debugLog()
Returns a debug journal.
std::unique_ptr< beast::Journal::Sink > setDebugLogSink(std::unique_ptr< beast::Journal::Sink > sink)
Set the sink for the debug journal.
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
static DebugSink & debugSink()
std::string to_string(BaseUInt< Bits, Tag > const &a)