Enable lg2 log output to stderr in OpenBMC CI test
Similar to printing logs to stderr in a TTY, output to stderr can be
enabled during OpenBMC CI test by setting the `LG2_FORCE_STDERR`
environment variable to any value.
Using meson, this can be done with something like:
test('test_name', executable(...), env: ['LG2_FORCE_STDERR=yes'])
Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
Change-Id: I0323fbb75fe211148ec4dc7e263fe18aabb8ffc6
diff --git a/lib/lg2_logger.cpp b/lib/lg2_logger.cpp
index 3276499..3c61003 100644
--- a/lib/lg2_logger.cpp
+++ b/lib/lg2_logger.cpp
@@ -207,9 +207,12 @@
std::cerr << std::endl;
}
-// Use the cerr output method if we are on a TTY.
+// Use the cerr output method if we are on a TTY or if explicitly set via
+// environment variable.
static auto extra_output_method =
- isatty(fileno(stderr)) ? cerr_extra_output : noop_extra_output;
+ (isatty(fileno(stderr)) || nullptr != getenv("LG2_FORCE_STDERR"))
+ ? cerr_extra_output
+ : noop_extra_output;
// Do_log implementation.
void do_log(level l, const lg2::source_location& s, const char* m, ...)