mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
feat(logs): add -DBEAST_ENHANCED_LOGGING with file:line numbers for JLOG macro (#552)
This commit is contained in:
@@ -17,11 +17,19 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <date/date.h>
|
||||
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <ripple/basics/chrono.h>
|
||||
#include <ripple/basics/contract.h>
|
||||
#ifdef BEAST_ENHANCED_LOGGING
|
||||
#include <ripple/beast/utility/EnhancedLogging.h>
|
||||
#include <date/tz.h>
|
||||
#endif
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
@@ -316,11 +324,46 @@ Logs::format(
|
||||
{
|
||||
output.reserve(message.size() + partition.size() + 100);
|
||||
|
||||
output = to_string(std::chrono::system_clock::now());
|
||||
#ifdef BEAST_ENHANCED_LOGGING
|
||||
// Environment variables are used instead of config file because:
|
||||
// 1. Logging starts before config parsing (needed to debug config issues)
|
||||
// 2. This is a developer feature - devs can easily set env vars
|
||||
// 3. Allows per-run overrides without editing config files
|
||||
static const char* fmt = []() {
|
||||
const char* env = std::getenv("LOG_DATE_FORMAT");
|
||||
return env ? env : "%Y-%b-%d %T %Z"; // Default format
|
||||
}();
|
||||
|
||||
// Check if we should use local time
|
||||
static const bool useLocalTime = []() {
|
||||
const char* env = std::getenv("LOG_DATE_LOCAL");
|
||||
return env && std::strcmp(env, "1") == 0;
|
||||
}();
|
||||
|
||||
if (useLocalTime)
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto local = date::make_zoned(date::current_zone(), now);
|
||||
output = date::format(fmt, local);
|
||||
}
|
||||
else
|
||||
{
|
||||
output = date::format(fmt, std::chrono::system_clock::now());
|
||||
}
|
||||
#else
|
||||
output = to_string(std::chrono::system_clock::now());
|
||||
#endif
|
||||
|
||||
if (!output.empty()) // Allow setting date format to an empty string
|
||||
output += " ";
|
||||
|
||||
output += " ";
|
||||
if (!partition.empty())
|
||||
{
|
||||
#ifdef BEAST_ENHANCED_LOGGING
|
||||
output += beast::detail::get_log_highlight_color();
|
||||
#endif
|
||||
output += partition + ":";
|
||||
}
|
||||
|
||||
using namespace beast::severities;
|
||||
switch (severity)
|
||||
@@ -348,6 +391,10 @@ Logs::format(
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef BEAST_ENHANCED_LOGGING
|
||||
output += "\033[0m";
|
||||
#endif
|
||||
|
||||
output += message;
|
||||
|
||||
// Limit the maximum length of the output
|
||||
|
||||
Reference in New Issue
Block a user