Skip to content

Commit

Permalink
Update logger initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Jan 2, 2025
1 parent 1fa0763 commit db2948f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
12 changes: 6 additions & 6 deletions cpp/base/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void Device::SetParams(const param_map &set_params)
params[key] = value;
}
else {
GetLogger().warn("{0} ignored unknown parameter '{1}={2}'", PbDeviceType_Name(type), key, value);
device_logger->warn("{0} ignored unknown parameter '{1}={2}'", PbDeviceType_Name(type), key, value);
}
}
}
Expand Down Expand Up @@ -81,13 +81,13 @@ bool Device::Eject(bool force)
return true;
}

logger& Device::GetLogger()
void Device::CreateLogger()
{
if (!logger_initialized) {
device_logger = s2p_util::CreateLogger(fmt::format("[s2p] (ID:LUN {0}:{1})", GetId(), GetLun()));
logger_initialized = true;
}
device_logger = s2p_util::CreateLogger(fmt::format("[s2p] (ID:LUN {0}:{1})", GetId(), GetLun()));
}

logger& Device::GetLogger() const
{
return *device_logger;
}

Expand Down
7 changes: 3 additions & 4 deletions cpp/base/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Device // NOSONAR The number of fields and methods is justified, the compl
void Stop();
virtual bool Eject(bool);

logger& GetLogger();
logger& GetLogger() const;

protected:

Expand Down Expand Up @@ -162,6 +162,7 @@ class Device // NOSONAR The number of fields and methods is justified, the compl

string GetParam(const string&) const;

void CreateLogger();
void LogTrace(const string&) const;
void LogDebug(const string&) const;
void LogWarn(const string&) const;
Expand Down Expand Up @@ -193,11 +194,9 @@ class Device // NOSONAR The number of fields and methods is justified, the compl

bool supports_params = false;

bool logger_initialized = false;

// The parameters the device was created with
param_map params;

// Use the default logger until the device-specific logger has been initialized
// Use the default logger until the device-specific logger has been created
shared_ptr<logger> device_logger = default_logger();
};
2 changes: 2 additions & 0 deletions cpp/base/primary_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ bool PrimaryDevice::SetResponseDataFormat(ScsiLevel l)
void PrimaryDevice::SetController(AbstractController *c)
{
controller = c;

CreateLogger();
}

void PrimaryDevice::StatusPhase() const
Expand Down

0 comments on commit db2948f

Please sign in to comment.