simplify: replace LOG_LOCATION_POSITION with LOG_DISABLE

Removes the LocationPosition enum and complex position logic. Now
file:line info always appears as a suffix (the most readable option)
and can be disabled with LOG_DISABLE=1. This removes ~20 lines of
code and one environment variable while maintaining functionality.
This commit is contained in:
Nicholas Dudfield
2025-09-08 16:30:08 +07:00
parent 2c11bfd678
commit 87281b2a54
3 changed files with 13 additions and 37 deletions

View File

@@ -71,12 +71,9 @@ strip_source_root(const char* file)
#endif
}
// Location position enum
enum class LocationPosition { PREFIX, SUFFIX, NONE };
// Get configured position - cached at startup
LocationPosition
get_log_location_position();
// Check if location info should be shown - cached at startup
bool
should_show_location();
// Helper to write location string (no leading/trailing space)
void

View File

@@ -83,26 +83,16 @@ get_log_highlight_color()
return escape;
}
// Get configured position - cached at startup
LocationPosition
get_log_location_position()
// Check if location info should be shown - cached at startup
bool
should_show_location()
{
static const LocationPosition position = []() {
const char* env = std::getenv("LOG_LOCATION_POSITION");
if (!env)
return LocationPosition::SUFFIX; // Default to suffix for better
// readability
if (std::strcmp(env, "suffix") == 0 || std::strcmp(env, "end") == 0)
return LocationPosition::SUFFIX;
if (std::strcmp(env, "prefix") == 0 || std::strcmp(env, "start") == 0)
return LocationPosition::PREFIX;
if (std::strcmp(env, "none") == 0)
return LocationPosition::NONE;
return LocationPosition::PREFIX;
static const bool show = []() {
const char* env = std::getenv("LOG_DISABLE");
// Show location by default, hide if LOG_DISABLE=1
return !env || std::strcmp(env, "1") != 0;
}();
return position;
return show;
}
// Helper to write location string (no leading/trailing space)

View File

@@ -146,14 +146,6 @@ Journal::ScopedStream::ScopedStream(
{
// Modifiers applied from all ctors
m_ostream << std::boolalpha << std::showbase;
// Write prefix if configured
if (file_ &&
detail::get_log_location_position() == detail::LocationPosition::PREFIX)
{
detail::log_write_location_string(m_ostream, file_, line_);
m_ostream << " ";
}
}
#endif
@@ -162,11 +154,8 @@ Journal::ScopedStream::~ScopedStream()
std::string s(m_ostream.str());
#ifdef BEAST_ENHANCED_LOGGING
// Add suffix if configured
if (file_ &&
detail::get_log_location_position() ==
detail::LocationPosition::SUFFIX &&
!s.empty() && s != "\n")
// Add suffix if location is enabled
if (file_ && detail::should_show_location() && !s.empty() && s != "\n")
{
std::ostringstream combined;
combined << s;