fix: Potential crash when log file is unavailable
This commit is contained in:
parent
0f4504476a
commit
5aa1046541
@ -42,13 +42,15 @@ namespace hex::log {
|
|||||||
std::scoped_lock lock(getLoggerMutex());
|
std::scoped_lock lock(getLoggerMutex());
|
||||||
|
|
||||||
auto dest = getDestination();
|
auto dest = getDestination();
|
||||||
printPrefix(dest, ts, level, IMHEX_PROJECT_NAME);
|
try {
|
||||||
|
printPrefix(dest, ts, level, IMHEX_PROJECT_NAME);
|
||||||
|
|
||||||
auto message = fmt::format(fmt::runtime(fmt), args...);
|
auto message = fmt::format(fmt::runtime(fmt), args...);
|
||||||
fmt::print(dest, "{}\n", message);
|
fmt::print(dest, "{}\n", message);
|
||||||
fflush(dest);
|
fflush(dest);
|
||||||
|
|
||||||
addLogEntry(IMHEX_PROJECT_NAME, level, std::move(message));
|
addLogEntry(IMHEX_PROJECT_NAME, level, std::move(message));
|
||||||
|
} catch (const std::exception&) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace color {
|
namespace color {
|
||||||
@ -94,19 +96,23 @@ namespace hex::log {
|
|||||||
[[maybe_unused]] void print(const std::string &fmt, auto && ... args) {
|
[[maybe_unused]] void print(const std::string &fmt, auto && ... args) {
|
||||||
std::scoped_lock lock(impl::getLoggerMutex());
|
std::scoped_lock lock(impl::getLoggerMutex());
|
||||||
|
|
||||||
auto dest = impl::getDestination();
|
try {
|
||||||
auto message = fmt::format(fmt::runtime(fmt), args...);
|
auto dest = impl::getDestination();
|
||||||
fmt::print(dest, "{}", message);
|
auto message = fmt::format(fmt::runtime(fmt), args...);
|
||||||
fflush(dest);
|
fmt::print(dest, "{}", message);
|
||||||
|
fflush(dest);
|
||||||
|
} catch (const std::exception&) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
[[maybe_unused]] void println(const std::string &fmt, auto && ... args) {
|
[[maybe_unused]] void println(const std::string &fmt, auto && ... args) {
|
||||||
std::scoped_lock lock(impl::getLoggerMutex());
|
std::scoped_lock lock(impl::getLoggerMutex());
|
||||||
|
|
||||||
auto dest = impl::getDestination();
|
try {
|
||||||
auto message = fmt::format(fmt::runtime(fmt), args...);
|
auto dest = impl::getDestination();
|
||||||
fmt::print(dest, "{}\n", message);
|
auto message = fmt::format(fmt::runtime(fmt), args...);
|
||||||
fflush(dest);
|
fmt::print(dest, "{}\n", message);
|
||||||
|
fflush(dest);
|
||||||
|
} catch (const std::exception&) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user