mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-28 00:10:21 +08:00
Support custom environment variables for load_env_levels (#3327)
Some checks failed
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[asan:ON build_type:Debug … (push) Failing after 3s
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Debug compiler… (push) Failing after 2s
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Release compil… (push) Failing after 3s
linux / OS X Clang (C++11, Release) (push) Has been cancelled
macos / macOS Clang (C++11, Release) (map[BUILD_EXAMPLE:OFF USE_STD_FORMAT:ON]) (push) Has been cancelled
macos / macOS Clang (C++11, Release) (map[BUILD_EXAMPLE:ON USE_STD_FORMAT:OFF]) (push) Has been cancelled
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022 USE_STD_FORMAT:ON WCHAR:OFF WCHAR_FILES:OFF]) (push) Has been cancelled
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022 USE_STD_FORMAT:ON WCHAR:ON WCHAR_FILES:ON]) (push) Has been cancelled
windows / build (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022 USE_STD_FORMAT:OFF WCHAR:OFF WCHAR_FILES:OFF]) (push) Has been cancelled
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:11 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019 USE_STD_FORMAT:OFF WCHAR:OFF WCHAR_FILES:OFF]) (push) Has been cancelled
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:14 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019 USE_STD_FORMAT:OFF WCHAR:OFF WCHAR_FILES:OFF]) (push) Has been cancelled
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019 USE_STD_FORMAT:OFF WCHAR:OFF WCHAR_FILES:OFF]) (push) Has been cancelled
Some checks failed
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[asan:ON build_type:Debug … (push) Failing after 3s
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Debug compiler… (push) Failing after 2s
linux / ${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }}) (map[build_type:Release compil… (push) Failing after 3s
linux / OS X Clang (C++11, Release) (push) Has been cancelled
macos / macOS Clang (C++11, Release) (map[BUILD_EXAMPLE:OFF USE_STD_FORMAT:ON]) (push) Has been cancelled
macos / macOS Clang (C++11, Release) (map[BUILD_EXAMPLE:ON USE_STD_FORMAT:OFF]) (push) Has been cancelled
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022 USE_STD_FORMAT:ON WCHAR:OFF WCHAR_FILES:OFF]) (push) Has been cancelled
windows / build (map[BUILD_EXAMPLE:OFF BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:20 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022 USE_STD_FORMAT:ON WCHAR:ON WCHAR_FILES:ON]) (push) Has been cancelled
windows / build (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 17 2022 USE_STD_FORMAT:OFF WCHAR:OFF WCHAR_FILES:OFF]) (push) Has been cancelled
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:11 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019 USE_STD_FORMAT:OFF WCHAR:OFF WCHAR_FILES:OFF]) (push) Has been cancelled
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:14 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019 USE_STD_FORMAT:OFF WCHAR:OFF WCHAR_FILES:OFF]) (push) Has been cancelled
windows / build_2019 (map[BUILD_EXAMPLE:ON BUILD_SHARED:ON BUILD_TYPE:Release CXX_STANDARD:17 FATAL_ERRORS:ON GENERATOR:Visual Studio 16 2019 USE_STD_FORMAT:OFF WCHAR:OFF WCHAR_FILES:OFF]) (push) Has been cancelled
SPDLOG_LEVEL is currently supported to control log levels via load_env_levels. This patch adds support for other environment variable names, such as MYAPP_LEVEL, for load_env_levels.
This commit is contained in:
parent
7cbf2a6967
commit
ae1de0dc8c
@ -387,6 +387,9 @@ void android_example()
|
|||||||
int main (int argc, char *argv[])
|
int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
spdlog::cfg::load_env_levels();
|
spdlog::cfg::load_env_levels();
|
||||||
|
// or specify the env variable name:
|
||||||
|
// MYAPP_LEVEL=info,mylogger=trace && ./example
|
||||||
|
// spdlog::cfg::load_env_levels("MYAPP_LEVEL");
|
||||||
// or from the command line:
|
// or from the command line:
|
||||||
// ./example SPDLOG_LEVEL=info,mylogger=trace
|
// ./example SPDLOG_LEVEL=info,mylogger=trace
|
||||||
// #include "spdlog/cfg/argv.h" // for loading levels from argv
|
// #include "spdlog/cfg/argv.h" // for loading levels from argv
|
||||||
|
@ -148,6 +148,9 @@ void load_levels_example() {
|
|||||||
// Set the log level to "info" and mylogger to "trace":
|
// Set the log level to "info" and mylogger to "trace":
|
||||||
// SPDLOG_LEVEL=info,mylogger=trace && ./example
|
// SPDLOG_LEVEL=info,mylogger=trace && ./example
|
||||||
spdlog::cfg::load_env_levels();
|
spdlog::cfg::load_env_levels();
|
||||||
|
// or specify the env variable name:
|
||||||
|
// MYAPP_LEVEL=info,mylogger=trace && ./example
|
||||||
|
// spdlog::cfg::load_env_levels("MYAPP_LEVEL");
|
||||||
// or from command line:
|
// or from command line:
|
||||||
// ./example SPDLOG_LEVEL=info,mylogger=trace
|
// ./example SPDLOG_LEVEL=info,mylogger=trace
|
||||||
// #include "spdlog/cfg/argv.h" // for loading levels from argv
|
// #include "spdlog/cfg/argv.h" // for loading levels from argv
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
namespace cfg {
|
namespace cfg {
|
||||||
inline void load_env_levels() {
|
inline void load_env_levels(const char* var = "SPDLOG_LEVEL") {
|
||||||
auto env_val = details::os::getenv("SPDLOG_LEVEL");
|
auto env_val = details::os::getenv(var);
|
||||||
if (!env_val.empty()) {
|
if (!env_val.empty()) {
|
||||||
helpers::load_levels(env_val);
|
helpers::load_levels(env_val);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,15 @@ TEST_CASE("env", "[cfg]") {
|
|||||||
#endif
|
#endif
|
||||||
load_env_levels();
|
load_env_levels();
|
||||||
REQUIRE(l1->level() == spdlog::level::warn);
|
REQUIRE(l1->level() == spdlog::level::warn);
|
||||||
|
|
||||||
|
#ifdef CATCH_PLATFORM_WINDOWS
|
||||||
|
_putenv_s("MYAPP_LEVEL", "l1=trace");
|
||||||
|
#else
|
||||||
|
setenv("MYAPP_LEVEL", "l1=trace", 1);
|
||||||
|
#endif
|
||||||
|
load_env_levels("MYAPP_LEVEL");
|
||||||
|
REQUIRE(l1->level() == spdlog::level::trace);
|
||||||
|
|
||||||
spdlog::set_default_logger(spdlog::create<test_sink_st>("cfg-default"));
|
spdlog::set_default_logger(spdlog::create<test_sink_st>("cfg-default"));
|
||||||
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info);
|
REQUIRE(spdlog::default_logger()->level() == spdlog::level::info);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user