Skip to content

Commit

Permalink
OrcLib: update some log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
fabienfl-orc committed Dec 1, 2020
1 parent 245004f commit d30d2db
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 36 deletions.
10 changes: 7 additions & 3 deletions src/OrcCommand/WolfExecution_Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,11 +808,15 @@ HRESULT WolfExecution::SetRepeatBehaviour(const Repeat behavior)
return S_OK;
}

HRESULT WolfExecution::SetCompressionLevel(const std::wstring& strCompressionLevel)
HRESULT WolfExecution::SetCompressionLevel(const std::wstring& level)
{
if (strCompressionLevel.empty())
if (level.empty())
{
Log::Debug(L"Specified compression level is empty");
return S_OK;
}

m_strCompressionLevel = strCompressionLevel;
Log::Debug(L"Set compression level to {}", level);
m_strCompressionLevel = level;
return S_OK;
}
2 changes: 2 additions & 0 deletions src/OrcCommand/WolfLauncher_Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,8 @@ HRESULT Main::CheckConfiguration()

if (!config.strCompressionLevel.empty())
{
Log::Debug(
L"Command has no compression level, using main compression level: {}", config.strCompressionLevel);
wolfexec->SetCompressionLevel(config.strCompressionLevel);
}

Expand Down
19 changes: 11 additions & 8 deletions src/OrcLib/Archive/7z/Archive7z.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ Lib7zCompressionLevel ToLib7zLevel(CompressionLevel level)

void SetCompressionLevel(const CComPtr<IOutArchive>& archiver, CompressionLevel level, std::error_code& ec)
{
Log::Debug("Archive7z: SetCompressionLevel to {}", level);

CMyComPtr<ISetProperties> setProperties;
HRESULT hr = archiver->QueryInterface(IID_ISetProperties, (void**)&setProperties);
if (setProperties == nullptr)
{
ec.assign(hr, std::system_category());
// TODO: spdlog::warn("Failed retrieve IID_ISetProperties: {}", ec.message());
Log::Error("Failed to set compresion level on IID_ISetProperties [{}]", ec);
return;
}

Expand All @@ -124,7 +126,7 @@ void SetCompressionLevel(const CComPtr<IOutArchive>& archiver, CompressionLevel
if (FAILED(hr))
{
ec.assign(hr, std::system_category());
// TODO: spdlog::warn("Failed to set property: {}", ec.message());
Log::Error("Failed to change compresion level while setting property [{}]", ec);
return;
}
}
Expand Down Expand Up @@ -168,14 +170,14 @@ void Archive7z::Compress(
if (FAILED(hr))
{
ec.assign(hr, std::system_category());
// TODO: spdlog::debug("Failed to get IID_IOutArchive: {}", ec.message());
Log::Error(L"Failed to retrieve IID_IOutArchive [{}]", ec);
return;
}

::SetCompressionLevel(archiver, m_compressionLevel, ec);
if (ec)
{
// TODO: spdlog::debug("Failed to update compression level");
Log::Error(L"Failed to update compression level to {} [{}]", m_compressionLevel, ec);
return;
}

Expand All @@ -186,15 +188,15 @@ void Archive7z::Compress(
if (FAILED(hr))
{
ec.assign(hr, std::system_category());
// TODO: log::Error(_L_, hr, L"Temp archive stream cannot be read\r\n");
Log::Error(L"Failed to read 'inputArchive' [{}]", ec);
return;
}

hr = inputArchive->SetFilePointer(0LL, FILE_BEGIN, NULL);
if (FAILED(hr))
{
ec.assign(hr, std::system_category());
// TODO: log::Error(_L_, hr, L"Failed to rewind Temp stream\r\n");
Log::Error(L"Failed to seek input archive to the begining [{}]", ec);
return;
}

Expand All @@ -205,14 +207,15 @@ void Archive7z::Compress(
if (FAILED(hr))
{
ec.assign(hr, std::system_category());
// TODO: log::Error(_L_, hr, L"Failed to open archive stream\r\n");
Log::Error(L"Failed to open input archive [{}]", ec);
return;
}

hr = archiverIn->GetNumberOfItems(&numberOfArchivedItems);
if (FAILED(hr))
{
ec.assign(hr, std::system_category());
Log::Error(L"Failed to retrieve number of items [{}]", ec);
return;
}
}
Expand All @@ -229,7 +232,7 @@ void Archive7z::Compress(
if (FAILED(hr))
{
ec.assign(hr, std::system_category());
// TODO: spdlog::debug("Failed to compress: {}", ec.message());
Log::Error("Failed to update archive [{}]", ec);
return;
}

Expand Down
12 changes: 10 additions & 2 deletions src/OrcLib/Archive/7z/ArchiveUpdateCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#include "Archive/7z/ArchiveUpdateCallback.h"

#include "Archive/7z/InStreamAdapter.h"
#include "Utils/Result.h"

using namespace Orc::Archive;
using namespace Orc;

namespace {

Expand All @@ -25,7 +27,7 @@ FILETIME NowTimestamp()
BOOL ret = SystemTimeToFileTime(&st, &ft);
if (ret == FALSE)
{
// TODO: add log
Log::Error("Failed to convert SystemTime to FileTime [{}]", LastWin32Error());
return {0};
}

Expand All @@ -34,6 +36,9 @@ FILETIME NowTimestamp()

} // namespace

namespace Orc {
namespace Archive {

ArchiveUpdateCallback::ArchiveUpdateCallback(Items items, std::wstring password, uint64_t numberOfInputArchiveItems)
: m_newItems(std::move(items))
, m_password(std::move(password))
Expand Down Expand Up @@ -235,7 +240,7 @@ STDMETHODIMP ArchiveUpdateCallback::SetOperationResult(Int32 operationResult)

if (operationResult != NArchive::NUpdate::NOperationResult::kOK)
{
// TODO: add log
Log::Error("Failure code for operation result");
m_ec.assign(E_FAIL, std::system_category());
}

Expand Down Expand Up @@ -280,3 +285,6 @@ STDMETHODIMP ArchiveUpdateCallback::CryptoGetTextPassword2(Int32* pPasswordIsDef

return S_OK;
}

} // namespace Archive
} // namespace Orc
8 changes: 7 additions & 1 deletion src/OrcLib/Archive/Appender.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ class Appender
const auto tempPath = GetTempPathApi(ec);
if (ec)
{
Log::Error("Failed to get temporary path [{}]", ec);
return {};
}

HRESULT hr = tempStreams[i]->Open(tempPath.c_str(), L"", bufferSize, kDontReleaseOnClose);
if (FAILED(hr))
{
ec.assign(hr, std::system_category());
Log::Error(L"Failed to open temporary path {} [{}]", tempPath, ec);
return {};
}
}
Expand Down Expand Up @@ -106,20 +108,23 @@ class Appender
m_archiver.Compress(dstStream, srcStream, ec);
if (ec)
{
Log::Error("Failed to compress stream [{}]", ec);
return;
}

HRESULT hr = srcStream->SetFilePointer(0, FILE_BEGIN, nullptr);
if (FAILED(hr))
{
ec.assign(hr, std::system_category());
Log::Error("Failed to seek source stream [{}]", ec);
return;
}

hr = srcStream->SetSize(0);
if (FAILED(hr))
{
ec.assign(hr, std::system_category());
Log::Error("Failed to resize source stream [{}]", ec);
return;
}

Expand All @@ -137,15 +142,16 @@ class Appender
Flush(ec);
if (ec)
{
Log::Error("Failed to flush stream [{}]", ec);
return;
}

auto& tempStream = m_tempStreams[m_srcStreamIndex];
HRESULT hr = tempStream->MoveTo(m_output.c_str());
if (FAILED(hr))
{
// TODO: add log
ec.assign(hr, std::system_category());
Log::Error(L"Failed to move stream to {} [{}]", m_output, ec);
return;
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/OrcLib/FileStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ __data_entrypoint(File) HRESULT FileStream::Read(
return hr;
}

Log::Trace(L"ReadFile read {} bytes (hFile: {:p})", dwBytesRead, m_hFile);

*pcbBytesRead = dwBytesRead;
return S_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion src/OrcLib/PipeStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ __data_entrypoint(File) HRESULT PipeStream::Read(
return hr;
}
}
Log::Debug("ReadFile read {} bytes (hFile={:p})", dwBytesRead, m_hReadPipe);

*pcbBytesRead = dwBytesRead;
return S_OK;
}
Expand Down
4 changes: 2 additions & 2 deletions src/OrcLib/ProfileList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ ProfileResult ProfileList::GetProfiles()
auto rSID = Registry::Read<ByteBuffer>(hKey, keyName.get(), L"Sid");
if (rSID.has_error())
{
Log::Debug(L"Failed to read SID for profile {}, using key name", keyName.get());
Log::Warn(L"Failed to read SID for profile using key name: '{}'", keyName.get());
PSID pSID = NULL;
if (!ConvertStringSidToSidW(keyName.get(), &pSID))
{
Log::Debug(L"Failed profile key name {} is not a valid sid", keyName.get());
Log::Error(L"Failed to convert to SID the key '{}'", keyName.get());
continue;
}
sid.assign((LPBYTE)pSID, GetLengthSid(pSID));
Expand Down
31 changes: 16 additions & 15 deletions src/OrcLib/Registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Result<ULONG32> Orc::Registry::Read<ULONG32>(HKEY hParentKey, LPWSTR szKeyName,
status != ERROR_SUCCESS)
{
const auto ec = Win32Error(status);
Log::Error(L"Failed to registry key {} [{}]", szKeyName, ec);
Log::Debug(L"Failed to open registry key {} [{}]", szKeyName, ec);
return ec;
}
}
Expand Down Expand Up @@ -53,12 +53,12 @@ Result<ULONG32> Orc::Registry::Read<ULONG32>(HKEY hParentKey, LPWSTR szKeyName,

if (status == ERROR_MORE_DATA)
{
Log::Error(L"Unexepected registry value '{}' is bigger than expected (ULONG32)", szValueName);
Log::Error(L"Unexpected registry value '{}' is bigger than expected (ULONG32)", szValueName);
return ec;
}
else
{
Log::Error(L"Failed to open registry '{}' value [{}]", szValueName, ec);
Log::Debug(L"Failed to open registry value '{}' [{}]", szValueName, ec);
return ec;
}
}
Expand All @@ -69,7 +69,7 @@ Result<ULONG32> Orc::Registry::Read<ULONG32>(HKEY hParentKey, LPWSTR szKeyName,

if (dwValueType != REG_DWORD || (dwValueType != REG_BINARY && cbBytes != sizeof(ULONG32)))
{
Log::Error(L"Unexpected value \"{}\" type (not ULONG32 compatible)", szValueName);
Log::Error(L"Unexpected value '{}' type (not ULONG32 compatible)", szValueName);
return Win32Error(ERROR_DATATYPE_MISMATCH);
}

Expand All @@ -87,7 +87,7 @@ Result<ULONG64> Orc::Registry::Read<ULONG64>(HKEY hParentKey, LPWSTR szKeyName,
status != ERROR_SUCCESS)
{
const auto ec = Win32Error(status);
Log::Error(L"Failed to registry key {} [{}]", szKeyName, ec);
Log::Error(L"Failed to open registry key {} [{}]", szKeyName, ec);
return ec;
}
}
Expand All @@ -114,12 +114,12 @@ Result<ULONG64> Orc::Registry::Read<ULONG64>(HKEY hParentKey, LPWSTR szKeyName,
const auto ec = Win32Error(status);
if (status == ERROR_MORE_DATA)
{
Log::Error(L"Unexepected registry value '{}' is bigger than expected (ULONG32)", szValueName);
Log::Error(L"Unexpected registry value '{}' is bigger than expected (ULONG32)", szValueName);
return ec;
}
else
{
Log::Error(L"Failed to open registry '{}' value [{}]", szValueName, ec);
Log::Debug(L"Failed to query registry '{}' value [{}]", szValueName, ec);
return ec;
}
}
Expand All @@ -129,7 +129,7 @@ Result<ULONG64> Orc::Registry::Read<ULONG64>(HKEY hParentKey, LPWSTR szKeyName,
}
if (dwValueType != REG_QWORD || (dwValueType != REG_BINARY && cbBytes != sizeof(ULONG64)))
{
Log::Error(L"Unexpected value \"{}\" type (not ULONG32 compatible)", szValueName);
Log::Error(L"Unexpected value '{}' type (not ULONG32 compatible)", szValueName);
return Win32Error(ERROR_DATATYPE_MISMATCH);
}

Expand All @@ -147,7 +147,7 @@ Result<Orc::ByteBuffer> Orc::Registry::Read<Orc::ByteBuffer>(HKEY hParentKey, LP
status != ERROR_SUCCESS)
{
const auto ec = Win32Error(status);
Log::Error(L"Failed to registry key {} [{}]", szKeyName, ec);
Log::Debug(L"Failed to open registry key {} [{}]", szKeyName, ec);
return ec;
}
}
Expand Down Expand Up @@ -178,14 +178,15 @@ Result<Orc::ByteBuffer> Orc::Registry::Read<Orc::ByteBuffer>(HKEY hParentKey, LP
if (auto status = RegQueryValueExW(hKey, szValueName, NULL, NULL, (LPBYTE)valueBuffer.get(), &cbBytes);
status != ERROR_SUCCESS)
{
Log::Error(L"Failed to reg value '{}:{}' value [{}]", szKeyName ? szKeyName : L"", szValueName, ec);
Log::Debug(
L"Failed to query registry value '{}:{}' value [{}]", szKeyName ? szKeyName : L"", szValueName, ec);
return ec;
}
}
else
{
Log::Error(
L"Failed to query registry value \"{}:{}\" value [{}]", szKeyName ? szKeyName : L"", szValueName, ec);
Log::Debug(
L"Failed to query registry value '{}:{}' value [{}]", szKeyName ? szKeyName : L"", szValueName, ec);
return ec;
}
}
Expand All @@ -207,7 +208,7 @@ Result<std::wstring> Orc::Registry::Read<std::wstring>(HKEY hParentKey, LPWSTR s
status != ERROR_SUCCESS)
{
const auto result = Win32Error(status);
Log::Error(L"Failed to registry key '{}' [{}]", szKeyName, result);
Log::Error(L"Failed to open registry key '{}' [{}]", szKeyName, result);
return result;
}
}
Expand Down Expand Up @@ -238,13 +239,13 @@ Result<std::wstring> Orc::Registry::Read<std::wstring>(HKEY hParentKey, LPWSTR s
if (auto status = RegQueryValueExW(hKey, szValueName, NULL, NULL, (LPBYTE)valueBuffer.get(), &cbBytes);
status != ERROR_SUCCESS)
{
Log::Error(L"Failed to reg value '{}' value [{}])", szValueName, ec);
Log::Debug(L"Failed to query registry value '{}' value [{}])", szValueName, ec);
return ec;
}
}
else
{
Log::Error(L"Failed to open profile list '{}' value [{}]", szValueName, ec);
Log::Debug(L"Failed to query registry value '{}' [{}]", szValueName, ec);
return ec;
}
}
Expand Down
Loading

0 comments on commit d30d2db

Please sign in to comment.