WIP: The Road to 1.4 #23
2 changed files with 33 additions and 13 deletions
|
@ -82,8 +82,6 @@ initialise() {
|
|||
|
||||
void
|
||||
addEntry(EntryType type, StringView message) {
|
||||
_logMutex.lock();
|
||||
|
||||
auto time = std::time(nullptr);
|
||||
|
||||
static char formatted_time[20] = {'\0'};
|
||||
|
@ -106,20 +104,28 @@ addEntry(EntryType type, StringView message) {
|
|||
} << entry;
|
||||
|
||||
arrayAppend(_entries, std::move(entry));
|
||||
|
||||
_logMutex.unlock();
|
||||
}
|
||||
|
||||
ArrayView<const LogEntry>
|
||||
entries() {
|
||||
if(!_logMutex.try_lock()) {
|
||||
return nullptr;
|
||||
}
|
||||
_logMutex.unlock();
|
||||
|
||||
return _entries;
|
||||
}
|
||||
|
||||
void
|
||||
lockMutex() {
|
||||
_logMutex.lock();
|
||||
}
|
||||
|
||||
void
|
||||
unlockMutex() {
|
||||
_logMutex.unlock();
|
||||
}
|
||||
|
||||
bool
|
||||
tryLockMutex() {
|
||||
return _logMutex.try_lock();
|
||||
}
|
||||
|
||||
} // Logger
|
||||
|
||||
} // MassBuilderSaveTool
|
||||
|
|
|
@ -48,11 +48,25 @@ void addEntry(EntryType type, StringView message);
|
|||
|
||||
auto entries() -> ArrayView<const LogEntry>;
|
||||
|
||||
void lockMutex();
|
||||
|
||||
void unlockMutex();
|
||||
|
||||
bool tryLockMutex();
|
||||
|
||||
} // Logger
|
||||
|
||||
} // MassBuilderSaveTool
|
||||
|
||||
#define LOG_INFO(message) MassBuilderSaveTool::Logger::addEntry(MassBuilderSaveTool::Logger::EntryType::Info, message)
|
||||
#define LOG_SUCCESS(message) MassBuilderSaveTool::Logger::addEntry(MassBuilderSaveTool::Logger::EntryType::Success, message)
|
||||
#define LOG_WARNING(message) MassBuilderSaveTool::Logger::addEntry(MassBuilderSaveTool::Logger::EntryType::Warning, message)
|
||||
#define LOG_ERROR(message) MassBuilderSaveTool::Logger::addEntry(MassBuilderSaveTool::Logger::EntryType::Error, message)
|
||||
#define LOG_INFO(message) MassBuilderSaveTool::Logger::lockMutex(); \
|
||||
MassBuilderSaveTool::Logger::addEntry(MassBuilderSaveTool::Logger::EntryType::Info, message); \
|
||||
MassBuilderSaveTool::Logger::unlockMutex();
|
||||
#define LOG_SUCCESS(message) MassBuilderSaveTool::Logger::lockMutex(); \
|
||||
MassBuilderSaveTool::Logger::addEntry(MassBuilderSaveTool::Logger::EntryType::Success, message); \
|
||||
MassBuilderSaveTool::Logger::unlockMutex();
|
||||
#define LOG_WARNING(message) MassBuilderSaveTool::Logger::lockMutex(); \
|
||||
MassBuilderSaveTool::Logger::addEntry(MassBuilderSaveTool::Logger::EntryType::Warning, message); \
|
||||
MassBuilderSaveTool::Logger::unlockMutex();
|
||||
#define LOG_ERROR(message) MassBuilderSaveTool::Logger::lockMutex(); \
|
||||
MassBuilderSaveTool::Logger::addEntry(MassBuilderSaveTool::Logger::EntryType::Error, message); \
|
||||
MassBuilderSaveTool::Logger::unlockMutex();
|
||||
|
|
Loading…
Reference in a new issue