20 #include <ripple/basics/chrono.h>
21 #include <ripple/basics/Log.h>
22 #include <ripple/basics/contract.h>
23 #include <boost/algorithm/string.hpp>
37 , partition_(partition)
47 logs_.write (level, partition_, text, console());
59 return m_stream !=
nullptr;
66 bool wasOpened =
false;
76 m_stream = std::move (stream);
98 if (m_stream !=
nullptr)
104 if (m_stream !=
nullptr)
130 return *result.first->second;
157 sink.second->threshold (thresh);
166 for (
auto const& [name, sink] :
sinks_)
176 format (s, text, level, partition);
192 return "The log file was closed and reopened.";
193 return "The log file could not be closed and reopened.";
200 return std::make_unique<Sink>(
254 case lsINFO:
return "Info";
267 if (boost::iequals (s,
"trace"))
270 if (boost::iequals (s,
"debug"))
273 if (boost::iequals (s,
"info") || boost::iequals (s,
"information"))
276 if (boost::iequals (s,
"warn") || boost::iequals (s,
"warning") || boost::iequals (s,
"warnings"))
279 if (boost::iequals (s,
"error") || boost::iequals (s,
"errors"))
282 if (boost::iequals (s,
"fatal") || boost::iequals (s,
"fatals"))
292 output.
reserve (message.
size() + partition.size() + 100);
297 if (! partition.empty ())
298 output += partition +
":";
303 case kTrace: output +=
"TRC ";
break;
304 case kDebug: output +=
"DBG ";
break;
305 case kInfo: output +=
"NFO ";
break;
306 case kWarning: output +=
"WRN ";
break;
307 case kError: output +=
"ERR ";
break;
311 case kFatal: output +=
"FTL ";
break;
325 auto scrubber = [&output](
char const* token)
327 auto first = output.
find(token);
331 if (first != std::string::npos)
335 if (first != std::string::npos)
337 auto last = output.
find(
'\"', ++first);
339 if (last == std::string::npos)
340 last = output.
size();
342 output.
replace (first, last - first, last - first,
'*');
347 scrubber (
"\"seed\"");
348 scrubber (
"\"seed_hex\"");
349 scrubber (
"\"secret\"");
350 scrubber (
"\"master_key\"");
351 scrubber (
"\"master_seed\"");
352 scrubber (
"\"master_seed_hex\"");
353 scrubber (
"\"passphrase\"");
367 : sink_ (
beast::Journal::getNullSink())
383 swap (holder_, sink);
Abstraction for the underlying message destination.
std::vector< std::pair< std::string, std::string > > partition_severities() const
beast::severities::Severity thresh_
void close()
Close the system file if it is open.
Manages partitions for logging.
void writeln(char const *text)
write to the log file and append an end of line marker.
void write(char const *text)
write to the log file.
static DebugSink & debugSink()
std::map< std::string, std::unique_ptr< beast::Journal::Sink >, boost::beast::iless > sinks_
A namespace for easy access to logging severity values.
std::string to_string(ListDisposition disposition)
File()
Construct with no associated system file.
beast::Journal::Sink & operator[](std::string const &name)
static Sink & getNullSink()
Returns a Sink which does nothing.
void write(beast::severities::Severity level, std::string const &text) override
Write text to the sink at the specified severity.
bool closeAndReopen()
Close and re-open the system file associated with the log This assists in interoperating with externa...
beast::Journal debugLog()
Returns a debug journal.
std::unique_ptr< beast::Journal::Sink > set(std::unique_ptr< beast::Journal::Sink > sink)
static std::string toString(LogSeverity s)
static LogSeverity fromSeverity(beast::severities::Severity level)
Logs & operator=(Logs const &)=delete
std::unique_ptr< beast::Journal::Sink > setDebugLogSink(std::unique_ptr< beast::Journal::Sink > sink)
Set the sink for the debug journal.
bool isOpen() const noexcept
Determine if a system file is associated with the log.
bool open(boost::filesystem::path const &path)
Associate a system file with the log.
static LogSeverity fromString(std::string const &s)
A generic endpoint for log messages.
Logs(beast::severities::Severity level)
beast::severities::Severity threshold() const
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
beast::Journal journal(std::string const &name)
virtual std::unique_ptr< beast::Journal::Sink > makeSink(std::string const &partition, beast::severities::Severity startingLevel)
@ maximumMessageCharacters
Severity
Severity level / threshold of a Journal message.
beast::Journal::Sink & get()
std::reference_wrapper< beast::Journal::Sink > sink_
static beast::severities::Severity toSeverity(LogSeverity level)
std::unique_ptr< beast::Journal::Sink > holder_
void write(beast::severities::Severity level, std::string const &partition, std::string const &text, bool console)
beast::Journal::Sink & get(std::string const &name)
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)