mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-22 23:30:14 +00:00
Merge pull request #10 from VPeruS/ranges
Some checks are pending
Build / Build (arm64) (push) Waiting to run
Build / Build (x86-64) (push) Waiting to run
Build / Build (macOS arm64) (push) Waiting to run
Build / Build (windows-arm64) (push) Waiting to run
Build / Build (windows-x86-64) (push) Waiting to run
Security / CodeQL (C/C++) (push) Waiting to run
Security / Semgrep (push) Waiting to run
Security / Sanitizer Build (ASan/UBSan) (push) Waiting to run
Some checks are pending
Build / Build (arm64) (push) Waiting to run
Build / Build (x86-64) (push) Waiting to run
Build / Build (macOS arm64) (push) Waiting to run
Build / Build (windows-arm64) (push) Waiting to run
Build / Build (windows-x86-64) (push) Waiting to run
Security / CodeQL (C/C++) (push) Waiting to run
Security / Semgrep (push) Waiting to run
Security / Sanitizer Build (ASan/UBSan) (push) Waiting to run
Replace heap allocation with view
This commit is contained in:
commit
d6de60e413
1 changed files with 13 additions and 9 deletions
|
|
@ -6,6 +6,9 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <cstring>
|
||||||
|
#include <iterator>
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
namespace wowee {
|
namespace wowee {
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
@ -42,15 +45,16 @@ void Logger::ensureFile() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (const char* level = std::getenv("WOWEE_LOG_LEVEL")) {
|
if (const char* level = std::getenv("WOWEE_LOG_LEVEL")) {
|
||||||
std::string v(level);
|
auto toLower = [] (unsigned char c) { return std::tolower(c); };
|
||||||
std::transform(v.begin(), v.end(), v.begin(), [](unsigned char c) {
|
using namespace std::literals;
|
||||||
return static_cast<char>(std::tolower(c));
|
|
||||||
});
|
auto v = std::string_view{level} | std::views::transform(toLower);
|
||||||
if (v == "debug") setLogLevel(LogLevel::DEBUG);
|
if (std::ranges::equal(v, "debug"sv)) setLogLevel(LogLevel::DEBUG);
|
||||||
else if (v == "info") setLogLevel(LogLevel::INFO);
|
else if (std::ranges::equal(v, "info"sv)) setLogLevel(LogLevel::INFO);
|
||||||
else if (v == "warn" || v == "warning") setLogLevel(LogLevel::WARNING);
|
else if (std::ranges::equal(v, "warn"sv) || std::ranges::equal(v, "warning"sv))
|
||||||
else if (v == "error") setLogLevel(kLogLevelError);
|
setLogLevel(LogLevel::WARNING);
|
||||||
else if (v == "fatal") setLogLevel(LogLevel::FATAL);
|
else if (std::ranges::equal(v, "error"sv)) setLogLevel(kLogLevelError);
|
||||||
|
else if (std::ranges::equal(v, "fatal"sv)) setLogLevel(LogLevel::FATAL);
|
||||||
}
|
}
|
||||||
std::error_code ec;
|
std::error_code ec;
|
||||||
std::filesystem::create_directories("logs", ec);
|
std::filesystem::create_directories("logs", ec);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue