mirror of
https://github.com/akuker/RASCSI.git
synced 2026-04-21 02:17:25 +00:00
Issues 1179 and 1182 (#1232)
* Update logging * Remove duplicate code * Update unit tests * Clean up includes * Merge ProtobufSerializer into protobuf_util namespace * Precompile regex * Add const * Add Split() convenience method, update log level/ID parsing * Move log.h to legacy folder * Elimininate gotos * Fixes for gcc 13 * Update compiler flags * Update default folder handling * Use references instead of pointers * Move code for better encapsulation * Move code * Remove unused method argument * Move device logger * Remove redundant to_string * Rename for consistency * Update handling of protobuf pointers * Simplify protobuf usage * Memory handling update * Add hasher
This commit is contained in:
@@ -3,63 +3,52 @@
|
||||
// SCSI Target Emulator PiSCSI
|
||||
// for Raspberry Pi
|
||||
//
|
||||
// Copyright (C) 2022 Uwe Seimet
|
||||
// Copyright (C) 2022-2023 Uwe Seimet
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include "shared/log.h"
|
||||
#include "device_logger.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace spdlog;
|
||||
|
||||
void DeviceLogger::Trace(const string& message) const
|
||||
{
|
||||
if (const string m = GetLogMessage(message); !m.empty()) {
|
||||
LOGTRACE("%s", m.c_str())
|
||||
}
|
||||
Log(level::trace, message);
|
||||
}
|
||||
|
||||
void DeviceLogger::Debug(const string& message) const
|
||||
{
|
||||
if (const string m = GetLogMessage(message); !m.empty()) {
|
||||
LOGDEBUG("%s", m.c_str())
|
||||
}
|
||||
Log(level::debug, message);
|
||||
}
|
||||
|
||||
void DeviceLogger::Info(const string& message) const
|
||||
{
|
||||
if (const string m = GetLogMessage(message); !m.empty()) {
|
||||
LOGINFO("%s", m.c_str())
|
||||
}
|
||||
Log(level::info, message);
|
||||
}
|
||||
|
||||
void DeviceLogger::Warn(const string& message) const
|
||||
{
|
||||
if (const string m = GetLogMessage(message); !m.empty()) {
|
||||
LOGWARN("%s", m.c_str())
|
||||
}
|
||||
Log(level::warn, message);
|
||||
}
|
||||
|
||||
void DeviceLogger::Error(const string& message) const
|
||||
{
|
||||
if (const string m = GetLogMessage(message); !m.empty()) {
|
||||
LOGERROR("%s", m.c_str())
|
||||
}
|
||||
Log(level::err, message);
|
||||
}
|
||||
|
||||
string DeviceLogger::GetLogMessage(const string& message) const
|
||||
void DeviceLogger::Log(level::level_enum level, const string& message) const
|
||||
{
|
||||
if (log_device_id == -1 || (log_device_id == id && (log_device_lun == -1 || log_device_lun == lun)))
|
||||
{
|
||||
if (!message.empty() &&
|
||||
(log_device_id == -1 ||
|
||||
(log_device_id == id && (log_device_lun == -1 || log_device_lun == lun)))) {
|
||||
if (lun == -1) {
|
||||
return "(ID " + to_string(id) + ") - " + message;
|
||||
log(level, "(ID " + to_string(id) + ") - " + message);
|
||||
}
|
||||
else {
|
||||
return "(ID:LUN " + to_string(id) + ":" + to_string(lun) + ") - " + message;
|
||||
log(level, "(ID:LUN " + to_string(id) + ":" + to_string(lun) + ") - " + message);
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
void DeviceLogger::SetIdAndLun(int i, int l)
|
||||
|
||||
Reference in New Issue
Block a user