Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imrpove logger code #40

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/Components/Modules/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,28 @@ namespace Components

va_list va;
va_start(va, message);
vsnprintf_s(buf, _TRUNCATE, message, va);
const auto len = vsnprintf_s(buf, _TRUNCATE, message, va);
va_end(va);

if (len < 0)
{
return;
}

MessagePrint(channel, std::string{ buf });
}

void Logger::MessagePrint(const int channel, const std::string& msg)
{
static const auto shouldPrint = []() -> bool
static const auto print = []() -> bool
{
return Flags::HasFlag("stdout") || Loader::IsPerformingUnitTests();
}();

if (shouldPrint)
if (print)
{
std::printf("%s", msg.data());
std::fflush(stdout);
std::fputs(msg.data(), stdout);
return;
}

Expand Down
25 changes: 16 additions & 9 deletions src/Components/Modules/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,34 @@
struct FormatWithLocation
{
std::string_view format;
#ifdef LOGGER_TRACE
std::source_location location;

FormatWithLocation(const std::string_view& fmt, std::source_location loc = std::source_location::current())
: format(fmt)
, location(std::move(loc))
#endif
#ifdef LOGGER_TRACE
FormatWithLocation(const std::string_view& fmt, std::source_location loc = std::source_location::current()) : format(fmt), location(std::move(loc))
#else
FormatWithLocation(const std::string_view& fmt) : format(fmt)
#endif
{
}

FormatWithLocation(const char* fmt, std::source_location loc = std::source_location::current())
: format(fmt)
, location(std::move(loc))
#ifdef LOGGER_TRACE
FormatWithLocation(const char* fmt, std::source_location loc = std::source_location::current()) : format(fmt), location(std::move(loc))
#else
FormatWithLocation(const char* fmt) : format(fmt)
#endif
{
}
};

template <typename... Args>
static void Debug([[maybe_unused]] const FormatWithLocation& f, [[maybe_unused]] const Args&... args)
{
#ifdef _DEBUG
(Utils::String::SanitizeFormatArgs(args), ...);
#ifdef LOGGER_TRACE
DebugInternal(f.format, std::make_format_args(args...), f.location);
#else
DebugInternal(f.format, std::make_format_args(args...));

Check failure on line 112 in src/Components/Modules/Logger.hpp

View workflow job for this annotation

GitHub Actions / Build binaries (Debug)

'Components::Logger::DebugInternal': function does not take 2 arguments (compiling source file ..\src\Components\Modules\AssetInterfaces\ILocalizeEntry.cpp) [D:\a\iw4x-client\iw4x-client\build\iw4x.vcxproj]

Check failure on line 112 in src/Components/Modules/Logger.hpp

View workflow job for this annotation

GitHub Actions / Build binaries (Debug)

'Components::Logger::DebugInternal': function does not take 2 arguments (compiling source file ..\src\Components\Modules\Bans.cpp) [D:\a\iw4x-client\iw4x-client\build\iw4x.vcxproj]

Check failure on line 112 in src/Components/Modules/Logger.hpp

View workflow job for this annotation

GitHub Actions / Build binaries (Debug)

'Components::Logger::DebugInternal': function does not take 2 arguments (compiling source file ..\src\Components\Modules\Auth.cpp) [D:\a\iw4x-client\iw4x-client\build\iw4x.vcxproj]

Check failure on line 112 in src/Components/Modules/Logger.hpp

View workflow job for this annotation

GitHub Actions / Build binaries (Debug)

'Components::Logger::DebugInternal': function does not take 2 arguments (compiling source file ..\src\Components\Modules\Chat.cpp) [D:\a\iw4x-client\iw4x-client\build\iw4x.vcxproj]

Check failure on line 112 in src/Components/Modules/Logger.hpp

View workflow job for this annotation

GitHub Actions / Build binaries (Debug)

'Components::Logger::DebugInternal': function does not take 2 arguments (compiling source file ..\src\Components\Modules\ClientCommand.cpp) [D:\a\iw4x-client\iw4x-client\build\iw4x.vcxproj]

Check failure on line 112 in src/Components/Modules/Logger.hpp

View workflow job for this annotation

GitHub Actions / Build binaries (Debug)

'Components::Logger::DebugInternal': function does not take 2 arguments (compiling source file ..\src\Components\Modules\D3D9Ex.cpp) [D:\a\iw4x-client\iw4x-client\build\iw4x.vcxproj]

Check failure on line 112 in src/Components/Modules/Logger.hpp

View workflow job for this annotation

GitHub Actions / Build binaries (Debug)

'Components::Logger::DebugInternal': function does not take 2 arguments (compiling source file ..\src\Components\Modules\Discord.cpp) [D:\a\iw4x-client\iw4x-client\build\iw4x.vcxproj]

Check failure on line 112 in src/Components/Modules/Logger.hpp

View workflow job for this annotation

GitHub Actions / Build binaries (Debug)

'Components::Logger::DebugInternal': function does not take 2 arguments (compiling source file ..\src\Components\Modules\Dvar.cpp) [D:\a\iw4x-client\iw4x-client\build\iw4x.vcxproj]

Check failure on line 112 in src/Components/Modules/Logger.hpp

View workflow job for this annotation

GitHub Actions / Build binaries (Debug)

'Components::Logger::DebugInternal': function does not take 2 arguments (compiling source file ..\src\Components\Modules\GSC\Script.cpp) [D:\a\iw4x-client\iw4x-client\build\iw4x.vcxproj]

Check failure on line 112 in src/Components/Modules/Logger.hpp

View workflow job for this annotation

GitHub Actions / Build binaries (Debug)

'Components::Logger::DebugInternal': function does not take 2 arguments (compiling source file ..\src\Components\Modules\GSC\UserInfo.cpp) [D:\a\iw4x-client\iw4x-client\build\iw4x.vcxproj]
#endif
#endif
}

Expand Down
Loading