Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #10677 from Pokechu22/no-printf-log
Remove printf-style logging
  • Loading branch information
lioncash committed May 19, 2022
2 parents 2aa0ae0 + 5f9212d commit a98d036
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 134 deletions.
50 changes: 0 additions & 50 deletions Source/Core/Common/Logging/Log.h
Expand Up @@ -96,58 +96,8 @@ void GenericLogFmt(LogLevel level, LogType type, const char* file, int line, con
"too many arguments?");
GenericLogFmtImpl(level, type, file, line, format, fmt::make_format_args(args...));
}

void GenericLog(LogLevel level, LogType type, const char* file, int line, const char* fmt, ...)
#ifdef __GNUC__
__attribute__((format(printf, 5, 6)))
#endif
;

void GenericLogV(LogLevel level, LogType type, const char* file, int line, const char* fmt,
va_list args);
} // namespace Common::Log

// Let the compiler optimize this out
#define GENERIC_LOG(t, v, ...) \
do \
{ \
if (v <= Common::Log::MAX_LOGLEVEL) \
Common::Log::GenericLog(v, t, __FILE__, __LINE__, __VA_ARGS__); \
} while (0)

#define ERROR_LOG(t, ...) \
do \
{ \
GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LERROR, __VA_ARGS__); \
} while (0)
#define WARN_LOG(t, ...) \
do \
{ \
GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LWARNING, __VA_ARGS__); \
} while (0)
#define NOTICE_LOG(t, ...) \
do \
{ \
GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LNOTICE, __VA_ARGS__); \
} while (0)
#define INFO_LOG(t, ...) \
do \
{ \
GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LINFO, __VA_ARGS__); \
} while (0)
#define DEBUG_LOG(t, ...) \
do \
{ \
GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LDEBUG, __VA_ARGS__); \
} while (0)

#define GENERIC_LOG_V(t, v, fmt, args) \
do \
{ \
if (v <= Common::Log::MAX_LOGLEVEL) \
Common::Log::GenericLogV(v, t, __FILE__, __LINE__, fmt, args); \
} while (0)

// fmtlib capable API

#define GENERIC_LOG_FMT(t, v, format, ...) \
Expand Down
34 changes: 0 additions & 34 deletions Source/Core/Common/Logging/LogManager.cpp
Expand Up @@ -62,40 +62,6 @@ class FileLogListener : public LogListener
bool m_enable;
};

void GenericLog(LogLevel level, LogType type, const char* file, int line, const char* fmt, ...)
{
auto* instance = LogManager::GetInstance();
if (instance == nullptr)
return;

if (!instance->IsEnabled(type, level))
return;

va_list args;
va_start(args, fmt);
char message[MAX_MSGLEN];
CharArrayFromFormatV(message, MAX_MSGLEN, fmt, args);
va_end(args);

instance->Log(level, type, file, line, message);
}

void GenericLogV(LogLevel level, LogType type, const char* file, int line, const char* fmt,
va_list args)
{
auto* instance = LogManager::GetInstance();
if (instance == nullptr)
return;

if (!instance->IsEnabled(type, level))
return;

char message[MAX_MSGLEN];
CharArrayFromFormatV(message, MAX_MSGLEN, fmt, args);

instance->Log(level, type, file, line, message);
}

void GenericLogFmtImpl(LogLevel level, LogType type, const char* file, int line,
fmt::string_view format, const fmt::format_args& args)
{
Expand Down
23 changes: 12 additions & 11 deletions Source/Core/Core/HW/EXI/BBA/TAPServer_Apple.cpp
Expand Up @@ -8,6 +8,7 @@
#include <sys/un.h>
#include <unistd.h>

#include "Common/CommonFuncs.h"
#include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
#include "Core/HW/EXI/EXI_Device.h"
Expand All @@ -29,7 +30,7 @@ bool CEXIETHERNET::TAPServerNetworkInterface::Activate()
sockaddr_un sun = {};
if (sizeof(socket_path) > sizeof(sun.sun_path))
{
ERROR_LOG(SP1, "Socket path is too long, unable to init BBA");
ERROR_LOG_FMT(SP1, "Socket path is too long, unable to init BBA");
return false;
}
sun.sun_family = AF_UNIX;
Expand All @@ -38,40 +39,40 @@ bool CEXIETHERNET::TAPServerNetworkInterface::Activate()
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd == -1)
{
ERROR_LOG(SP1, "Couldn't create socket, unable to init BBA");
ERROR_LOG_FMT(SP1, "Couldn't create socket, unable to init BBA");
return false;
}

if (connect(fd, reinterpret_cast<sockaddr*>(&sun), sizeof(sun)) == -1)
{
ERROR_LOG(SP1, "Couldn't connect socket (%d), unable to init BBA", errno);
ERROR_LOG_FMT(SP1, "Couldn't connect socket ({}), unable to init BBA", LastStrerrorString());
close(fd);
fd = -1;
return false;
}

INFO_LOG(SP1, "BBA initialized.\n");
INFO_LOG_FMT(SP1, "BBA initialized.");
return RecvInit();
}

bool CEXIETHERNET::TAPServerNetworkInterface::SendFrame(const u8* frame, u32 size)
{
{
const std::string s = ArrayToString(frame, size, 0x10);
INFO_LOG(SP1, "SendFrame %x\n%s\n", size, s.c_str());
INFO_LOG_FMT(SP1, "SendFrame {}\n{}", size, s);
}

auto size16 = u16(size);
if (write(fd, &size16, 2) != 2)
{
ERROR_LOG(SP1, "SendFrame(): could not write size field\n");
ERROR_LOG_FMT(SP1, "SendFrame(): could not write size field");
return false;
}
int written_bytes = write(fd, frame, size);
if (u32(written_bytes) != size)
{
ERROR_LOG(SP1, "SendFrame(): expected to write %d bytes, instead wrote %d", size,
written_bytes);
ERROR_LOG_FMT(SP1, "SendFrame(): expected to write {} bytes, instead wrote {}", size,
written_bytes);
return false;
}
else
Expand All @@ -98,19 +99,19 @@ void CEXIETHERNET::TAPServerNetworkInterface::ReadThreadHandler()
u16 size;
if (read(fd, &size, 2) != 2)
{
ERROR_LOG(SP1, "Failed to read size field from BBA, err=%d", errno);
ERROR_LOG_FMT(SP1, "Failed to read size field from BBA: {}", LastStrerrorString());
}
else
{
int read_bytes = read(fd, m_eth_ref->mRecvBuffer.get(), size);
if (read_bytes < 0)
{
ERROR_LOG(SP1, "Failed to read packet data from BBA, err=%d", errno);
ERROR_LOG_FMT(SP1, "Failed to read packet data from BBA: {}", LastStrerrorString());
}
else if (readEnabled.IsSet())
{
std::string data_string = ArrayToString(m_eth_ref->mRecvBuffer.get(), read_bytes, 0x10);
INFO_LOG(SP1, "Read data: %s", data_string.c_str());
INFO_LOG_FMT(SP1, "Read data: {}", data_string);
m_eth_ref->mRecvBufferLength = read_bytes;
m_eth_ref->RecvHandlePacket();
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/EXI/EXI_DeviceEthernet.cpp
Expand Up @@ -50,7 +50,7 @@ CEXIETHERNET::CEXIETHERNET(BBADeviceType type)
#if defined(__APPLE__)
case BBADeviceType::TAPSERVER:
m_network_interface = std::make_unique<TAPServerNetworkInterface>(this);
INFO_LOG(SP1, "Created tapserver physical network interface.");
INFO_LOG_FMT(SP1, "Created tapserver physical network interface.");
break;
#endif
case BBADeviceType::XLINK:
Expand Down
10 changes: 5 additions & 5 deletions Source/Core/Core/PowerPC/JitArm64/Jit.cpp
Expand Up @@ -709,7 +709,7 @@ void JitArm64::Jit(u32 em_address, bool clear_cache_and_retry_on_failure)
{
// Code generation failed due to not enough free space in either the near or far code regions.
// Clear the entire JIT cache and retry.
WARN_LOG(POWERPC, "flushing code caches, please report if this happens a lot");
WARN_LOG_FMT(POWERPC, "flushing code caches, please report if this happens a lot");
ClearCache();
Jit(em_address, false);
return;
Expand All @@ -728,15 +728,15 @@ bool JitArm64::SetEmitterStateToFreeCodeRegion()
auto free_near = m_free_ranges_near.by_size_begin();
if (free_near == m_free_ranges_near.by_size_end())
{
WARN_LOG(POWERPC, "Failed to find free memory region in near code region.");
WARN_LOG_FMT(POWERPC, "Failed to find free memory region in near code region.");
return false;
}
SetCodePtr(free_near.from(), free_near.to());

auto free_far = m_free_ranges_far.by_size_begin();
if (free_far == m_free_ranges_far.by_size_end())
{
WARN_LOG(POWERPC, "Failed to find free memory region in far code region.");
WARN_LOG_FMT(POWERPC, "Failed to find free memory region in far code region.");
return false;
}
m_far_code.SetCodePtr(free_far.from(), free_far.to());
Expand Down Expand Up @@ -995,9 +995,9 @@ bool JitArm64::DoJit(u32 em_address, JitBlock* b, u32 nextPC)
if (HasWriteFailed() || m_far_code.HasWriteFailed())
{
if (HasWriteFailed())
WARN_LOG(POWERPC, "JIT ran out of space in near code region during code generation.");
WARN_LOG_FMT(POWERPC, "JIT ran out of space in near code region during code generation.");
if (m_far_code.HasWriteFailed())
WARN_LOG(POWERPC, "JIT ran out of space in far code region during code generation.");
WARN_LOG_FMT(POWERPC, "JIT ran out of space in far code region during code generation.");

return false;
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/DolphinQt/MainWindow.cpp
Expand Up @@ -325,9 +325,9 @@ void MainWindow::InitControllers()
if (!g_controller_interface.HasDefaultDevice())
{
// Note that the CI default device could be still temporarily removed at any time
WARN_LOG(CONTROLLERINTERFACE,
"No default device has been added in time. EmulatedController(s) defaulting adds"
" input mappings made for a specific default device depending on the platform");
WARN_LOG_FMT(CONTROLLERINTERFACE,
"No default device has been added in time. EmulatedController(s) defaulting adds"
" input mappings made for a specific default device depending on the platform");
}
GCAdapter::Init();
Pad::Initialize();
Expand Down

0 comments on commit a98d036

Please sign in to comment.