mirror of
https://github.com/TomHarte/CLK.git
synced 2025-11-03 09:16:11 +00:00
Allow logging of errors but not info.
This commit is contained in:
@@ -71,7 +71,7 @@ bool MultiMachine::would_collapse(const std::vector<std::unique_ptr<DynamicMachi
|
|||||||
void MultiMachine::did_run_machines(MultiTimedMachine &) {
|
void MultiMachine::did_run_machines(MultiTimedMachine &) {
|
||||||
std::lock_guard machines_lock(machines_mutex_);
|
std::lock_guard machines_lock(machines_mutex_);
|
||||||
|
|
||||||
if constexpr (logger.enabled) {
|
if constexpr (logger.InfoEnabled) {
|
||||||
auto line = logger.info();
|
auto line = logger.info();
|
||||||
for(const auto &machine: machines_) {
|
for(const auto &machine: machines_) {
|
||||||
auto timed_machine = machine->timed_machine();
|
auto timed_machine = machine->timed_machine();
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
namespace Log {
|
namespace Log {
|
||||||
// TODO: if adopting C++20, std::format would be a better model to apply below.
|
// TODO: if adopting C++20, std::format would be a better model to apply below.
|
||||||
// But I prefer C files to C++ streams, so here it is for now.
|
// But I prefer C files to C++ streams, so here it is for now.
|
||||||
|
// Also noting: Apple's std::format support seems to require macOS 13.3, so
|
||||||
|
// that'd be a bitter pill to swallow.
|
||||||
|
|
||||||
enum class Source {
|
enum class Source {
|
||||||
ADBDevice,
|
ADBDevice,
|
||||||
@@ -66,14 +68,21 @@ enum class Source {
|
|||||||
WDFDC,
|
WDFDC,
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr bool is_enabled(const Source source) {
|
enum class EnabledLevel {
|
||||||
|
None, // No logged statements are presented.
|
||||||
|
Errors, // The error stream is presented, but not the info stream.
|
||||||
|
ErrorsAndInfo, // All streams are presented.
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr EnabledLevel enabled_level(const Source source) {
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Allow for compile-time source-level enabling and disabling of different sources.
|
// Allow for compile-time source-level enabling and disabling of different sources.
|
||||||
switch(source) {
|
switch(source) {
|
||||||
default: return true;
|
default:
|
||||||
|
return EnabledLevel::ErrorsAndInfo;
|
||||||
|
|
||||||
// The following are all things I'm not actively working on.
|
// The following are all things I'm not actively working on.
|
||||||
case Source::AmigaBlitter:
|
case Source::AmigaBlitter:
|
||||||
@@ -87,8 +96,10 @@ constexpr bool is_enabled(const Source source) {
|
|||||||
case Source::SCC:
|
case Source::SCC:
|
||||||
case Source::SCSI:
|
case Source::SCSI:
|
||||||
case Source::I2C:
|
case Source::I2C:
|
||||||
// case Source::Keyboard:
|
return EnabledLevel::None;
|
||||||
return false;
|
|
||||||
|
case Source::Floppy:
|
||||||
|
return EnabledLevel::Errors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,12 +161,9 @@ template <Source source>
|
|||||||
struct LogLine<source, true> {
|
struct LogLine<source, true> {
|
||||||
public:
|
public:
|
||||||
explicit LogLine(FILE *const stream) noexcept : stream_(stream) {
|
explicit LogLine(FILE *const stream) noexcept : stream_(stream) {
|
||||||
const auto source_prefix = prefix(source);
|
static constexpr auto source_prefix = prefix(source);
|
||||||
if(!source_prefix) return;
|
if(!source_prefix) return;
|
||||||
|
append("[%s] ", source_prefix);
|
||||||
output_.resize(strlen(source_prefix) + 4);
|
|
||||||
std::snprintf(output_.data(), output_.size(), "[%s] ", source_prefix);
|
|
||||||
output_.pop_back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~LogLine() {
|
~LogLine() {
|
||||||
@@ -200,9 +208,11 @@ struct LogLine<source, false> {
|
|||||||
template <Source source>
|
template <Source source>
|
||||||
class Logger {
|
class Logger {
|
||||||
public:
|
public:
|
||||||
static constexpr bool enabled = is_enabled(source);
|
static constexpr bool InfoEnabled = enabled_level(source) == EnabledLevel::ErrorsAndInfo;
|
||||||
static LogLine<source, enabled> info() { return LogLine<source, enabled>(stdout); }
|
static constexpr bool ErrorsEnabled = enabled_level(source) >= EnabledLevel::Errors;
|
||||||
static LogLine<source, enabled> error() { return LogLine<source, enabled>(stderr); }
|
|
||||||
|
static auto info() { return LogLine<source, InfoEnabled>(stdout); }
|
||||||
|
static auto error() { return LogLine<source, ErrorsEnabled>(stderr); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user