Skip to content

Commit

Permalink
Refactor logging ones
Browse files Browse the repository at this point in the history
  • Loading branch information
Wend4r committed Sep 20, 2024
1 parent 49c9cef commit 15da25d
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 312 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
path = external/sourcesdk
url = https://github.com/Wend4r/sourcesdk/
branch = cs2
[submodule "external/logger"]
path = external/logger
url = https://github.com/untrustedmodders/s2u-logger.git
22 changes: 21 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ if(POLICY CMP0092)
cmake_policy(SET CMP0092 NEW) # Don't add -W3 warning level by default.
endif()

set(EXTERNAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external")

function(set_or_external_dir VAR_NAME DEFAULT_DIR)
if(${VAR_NAME})
file(TO_CMAKE_PATH "${${VAR_NAME}}" ${VAR_NAME})
else()
set(${VAR_NAME} "${EXTERNAL_DIR}/${DEFAULT_DIR}")
endif()

set(${VAR_NAME} "${${VAR_NAME}}" PARENT_SCOPE)
endfunction()

string(TIMESTAMP PROJECT_BUILD_DATE_YEAR "%Y")

set_or_external_dir(LOGGER_DIR "logger")

include(cmake/logger.cmake)

project(cs2-plugify VERSION 1.0.0.0 DESCRIPTION "Plugify CS2 Core" HOMEPAGE_URL "https://github.com/untrustedmodders/cs2-plugify" LANGUAGES C CXX ASM)

Expand Down Expand Up @@ -52,6 +69,8 @@ set(SOURCESDK_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/sourcesdk)
set(METAMOD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/metamod-source)

target_include_directories(${PROJECT_NAME} PRIVATE
${LOGGER_INCLUDE_DIRS}

${SOURCESDK_DIR}
${SOURCESDK_DIR}/common
${SOURCESDK_DIR}/game/shared
Expand All @@ -71,6 +90,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "plugify")

target_compile_definitions(${PROJECT_NAME} PRIVATE
PLUGIFY_PROJECT_YEAR="${PROJECT_BUILD_DATE_YEAR}"
PLUGIFY_PROJECT_NAME="${PROJECT_NAME}"
PLUGIFY_PROJECT_DESCRIPTION="${CMAKE_PROJECT_DESCRIPTION}"
PLUGIFY_PROJECT_HOMEPAGE_URL="${CMAKE_PROJECT_HOMEPAGE_URL}"
Expand Down Expand Up @@ -106,7 +126,7 @@ elseif(WIN32)
#set_target_properties(${PROJECT_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()

set(PLUGIFY_LINK_LIBRARIES plugify::plugify sourcesdk miniz)
set(PLUGIFY_LINK_LIBRARIES ${LOGGER_BINARY_DIR} plugify::plugify sourcesdk miniz)

if(WIN32)
set(PLUGIFY_LINK_LIBRARIES ${PLUGIFY_LINK_LIBRARIES} winhttp.lib)
Expand Down
17 changes: 17 additions & 0 deletions cmake/logger.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# cs2-plugify
# Copyright (C) 2024 untrustedmodders
# Licensed under the MIT license. See LICENSE file in the project root for details.

if(NOT LOGGER_DIR)
message(FATAL_ERROR "LOGGER_DIR is empty")
endif()

set(LOGGER_BINARY_DIR "s2u-logger")

set(LOGGER_INCLUDE_DIRS
${LOGGER_INCLUDE_DIRS}

${LOGGER_DIR}/include
)

add_subdirectory(${LOGGER_DIR} ${LOGGER_BINARY_DIR})
1 change: 1 addition & 0 deletions external/logger
Submodule logger added at 63659e
2 changes: 1 addition & 1 deletion external/plugify
2 changes: 1 addition & 1 deletion external/sourcesdk
Submodule sourcesdk updated 82 files
+6 −13 .github/workflows/build-linux.yml
+0 −131 .github/workflows/build-macos.yml
+4 −11 .github/workflows/build-windows.yml
+7 −23 CMakeLists.txt
+7 −7 cmake/platform/linux.cmake
+0 −37 cmake/platform/macos.cmake
+2 −6 cmake/platform/shared.cmake
+4 −4 cmake/platform/windows.cmake
+3 −5 cmake/protobuf/targets/libprotobuf-lite.cmake
+3 −5 cmake/protobuf/targets/libprotobuf.cmake
+3 −5 cmake/protobuf/targets/libprotoc.cmake
+3 −5 cmake/protobuf/targets/protoc.cmake
+42 −70 cmake/sourcesdk.cmake
+2 −2 cmake/sourcesdk/proto.cmake
+10 −21 cmake/sourcesdk/proto/generate.cmake
+0 −9 cmake/sourcesdk/targets/common.cmake
+0 −9 cmake/sourcesdk/targets/engine.cmake
+11 −18 cmake/sourcesdk/targets/entity2.cmake
+0 −11 cmake/sourcesdk/targets/game/server.cmake
+0 −11 cmake/sourcesdk/targets/game/shared.cmake
+9 −22 cmake/sourcesdk/targets/interfaces.cmake
+10 −18 cmake/sourcesdk/targets/mathlib.cmake
+0 −9 cmake/sourcesdk/targets/public.cmake
+0 −13 cmake/sourcesdk/targets/steamworks.cmake
+0 −13 cmake/sourcesdk/targets/tier0.cmake
+10 −18 cmake/sourcesdk/targets/tier1.cmake
+0 −17 common/networksystem_protomessages.proto
+ devtools/bin/osx64/protoc
+ devtools/bin/protoc
+ devtools/bin/protoc.exe
+109 −97 game/server/recipientfilter.h
+9 −0 game/shared/ehandle.h
+3 −3 game/shared/igamesystem.h
+0 −4 interfaces/interfaces.cpp
+ lib/linux/libsteam_api.so
+ lib/linux/libtier0.so
+ lib/linux64/libsteam_api.so
+ lib/linux64/libtier0.so
+ lib/linux64/libvstdlib_client.so
+ lib/osx64/libsteam_api.dylib
+ lib/osx64/libtier0.dylib
+ lib/osx64/libvstdlib.dylib
+ lib/public/steam_api.lib
+ lib/public/tier0.lib
+ lib/public/win64/steam_api64.lib
+ lib/public/win64/tier0.lib
+5 −0 linux_sdk/.gitignore
+189 −0 linux_sdk/Makefile
+58 −0 linux_sdk/Makefile.choreo
+51 −0 linux_sdk/Makefile.interfaces
+70 −0 linux_sdk/Makefile.mathlib
+57 −0 linux_sdk/Makefile.plugin
+28 −0 linux_sdk/Makefile.server
+55 −0 linux_sdk/Makefile.shaderapiempty
+53 −0 linux_sdk/Makefile.srcds
+58 −0 linux_sdk/Makefile.tier1
+50 −0 linux_sdk/Makefile.vcpm
+210 −0 linux_sdk/x86-64/Makefile
+58 −0 linux_sdk/x86-64/Makefile.choreo
+51 −0 linux_sdk/x86-64/Makefile.interfaces
+70 −0 linux_sdk/x86-64/Makefile.mathlib
+57 −0 linux_sdk/x86-64/Makefile.plugin
+28 −0 linux_sdk/x86-64/Makefile.server
+55 −0 linux_sdk/x86-64/Makefile.shaderapiempty
+59 −0 linux_sdk/x86-64/Makefile.tier1
+50 −0 linux_sdk/x86-64/Makefile.vcpm
+2 −2 mathlib/mathlib_base.cpp
+0 −25 public/frame.h
+5 −5 public/iserver.h
+0 −90 public/netmessages.h
+1 −1 public/schemasystem/schematypes.h
+21 −3 public/serversideclient.h
+4 −6 public/tier0/memdbgon.h
+0 −37 public/tier1/convar.h
+0 −6 public/tier1/keyvalues3.h
+3 −3 public/tier1/utlhashtable.h
+3 −54 public/tier1/utlmemory.h
+4 −5 public/tier1/utlrbtree.h
+3 −9 public/tier1/utlvector.h
+1 −1 thirdparty/protobuf
+0 −70 tier1/convar.cpp
+15 −36 tier1/keyvalues3.cpp
176 changes: 16 additions & 160 deletions src/mm_logger.cpp
Original file line number Diff line number Diff line change
@@ -1,205 +1,61 @@
#include "mm_logger.h"
#include "mm_plugin.h"

using namespace plugifyMM;

MMLogger::MMLogger(const char *name, RegisterTagsFunc registerTagsFunc, int flags, LoggingVerbosity_t verbosity, const Color &defaultColor)
{
m_channelID = LoggingSystem_RegisterLoggingChannel(name, registerTagsFunc, flags, verbosity, defaultColor);
}

bool MMLogger::IsChannelEnabled(LoggingSeverity_t severity) const
{
return LoggingSystem_IsChannelEnabled(m_channelID, severity);
}

bool MMLogger::IsChannelEnabled(LoggingVerbosity_t verbosity) const
{
return LoggingSystem_IsChannelEnabled(m_channelID, verbosity);
}

LoggingVerbosity_t MMLogger::GetChannelVerbosity() const
{
return LoggingSystem_GetChannelVerbosity(m_channelID);
}

Color MMLogger::GetColor() const
{
Color rgba;
rgba.SetRawColor(LoggingSystem_GetChannelColor(m_channelID));
return rgba;
}

LoggingChannelFlags_t MMLogger::GetFlags() const
{
return LoggingSystem_GetChannelFlags(m_channelID);
}

void MMLogger::SetSeverity(plugify::Severity severity)
{
m_severity = severity;
}

LoggingResponse_t MMLogger::Log(LoggingSeverity_t severity, const char *message)
{
LoggingResponse_t response = LR_ABORT;

if (IsChannelEnabled(severity))
{
response = LoggingSystem_LogDirect(m_channelID, severity, message);
}

return response;
}

LoggingResponse_t MMLogger::Log(LoggingSeverity_t severity, const Color &color, const char *message)
{
LoggingResponse_t response = LR_ABORT;

if (IsChannelEnabled(severity))
{
response = LoggingSystem_LogDirect(m_channelID, severity, color, message);
}

return response;
}

LoggingResponse_t MMLogger::Log(LoggingSeverity_t severity, const LeafCodeInfo_t &code, const char *message)
{
LoggingResponse_t response = LR_ABORT;

if (IsChannelEnabled(severity))
{
response = LoggingSystem_LogDirect(m_channelID, severity, code, message);
}

return response;
}

LoggingResponse_t MMLogger::Log(LoggingSeverity_t severity, const LeafCodeInfo_t &code, const Color &color, const char *message)
{
LoggingResponse_t response = LR_ABORT;

if (IsChannelEnabled(severity))
{
response = LoggingSystem_LogDirect(m_channelID, severity, code, color, message);
}

return response;
}
/*
LoggingResponse_t MMLogger::LogFormat(LoggingSeverity_t severity, const char *format, ...)
{
char buffer[MAX_LOGGING_MESSAGE_LENGTH];
va_list params;
va_start(params, format);
V_vsnprintf((char *)buffer, sizeof(buffer), format, params);
va_end(params);
return Log(severity, buffer);
}
LoggingResponse_t MMLogger::LogFormat(LoggingSeverity_t severity, const Color &color, const char *format, ...)
{
LoggingResponse_t response = LR_ABORT;
if (IsChannelEnabled(severity))
{
char buffer[1024];
va_list params;
va_start(params, format);
V_vsnprintf((char *)buffer, sizeof(buffer), format, params);
va_end(params);
response = Log(severity, color, buffer);
}
return response;
}
LoggingResponse_t MMLogger::LogFormat(LoggingSeverity_t severity, const LeafCodeInfo_t &code, const char *format, ...)
{
LoggingResponse_t response = LR_ABORT;
if (IsChannelEnabled(severity))
{
char buffer[1024];
va_list params;
va_start(params, format);
V_vsnprintf((char *)buffer, sizeof(buffer), format, params);
va_end(params);
response = Log(severity, code, buffer);
}
return response;
}
LoggingResponse_t MMLogger::LogFormat(LoggingSeverity_t severity, const LeafCodeInfo_t &code, const Color &color, const char *format, ...)
{
LoggingResponse_t response = LR_ABORT;
if (IsChannelEnabled(severity))
{
char buffer[1024];
va_list params;
va_start(params, format);
V_vsnprintf((char *)buffer, sizeof(buffer), format, params);
va_end(params);
response = Log(severity, code, color, buffer);
}
return response;
}
*/
void MMLogger::Log(std::string_view message, plugify::Severity severity)
{
if (severity <= m_severity)
{
std::string sMessage = std::format("{}\n", message);

const char *pszMessage = sMessage.c_str();

switch (severity)
{
case plugify::Severity::Fatal:
{
Log(LS_ERROR, Color(255, 0, 255, 255), std::format("{}\n", message).c_str());
Error({255, 0, 255, 255}, pszMessage);

break;
}

case plugify::Severity::Error:
{
Log(LS_WARNING, Color(255, 0, 0, 255), std::format("{}\n", message).c_str());
Warning({255, 0, 0, 255}, pszMessage);

break;
}

case plugify::Severity::Warning:
{
Log(LS_WARNING, Color(255, 127, 0, 255), std::format("{}\n", message).c_str());
Warning({255, 127, 0, 255}, pszMessage);

break;
}

case plugify::Severity::Info:
{
Log(LS_MESSAGE, Color(255, 255, 0, 255),std::format("{}\n", message).c_str());
Message({255, 255, 0, 255}, pszMessage);

break;
}

case plugify::Severity::Debug:
{
Log(LS_MESSAGE, Color(0, 255, 0, 255), std::format("{}\n", message).c_str());
Detailed({0, 255, 255, 255}, pszMessage);

break;
}

case plugify::Severity::Verbose:
{
Log(LS_MESSAGE, Color(255, 255, 255, 255), std::format("{}\n", message).c_str());
Detailed({255, 255, 255, 255}, pszMessage);

break;
}

Expand Down
32 changes: 11 additions & 21 deletions src/mm_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,26 @@
#include <plugify/log.h>
#include <plugify/compat_format.h>

#include <logger.hpp>

namespace plugifyMM
{
class MMLogger final : public plugify::ILogger
using MMLoggerBase = Logger;

class MMLogger final : public MMLoggerBase, public plugify::ILogger
{
public:
MMLogger(const char *name, RegisterTagsFunc registerTagsFunc, int flags = 0, LoggingVerbosity_t verbosity = LV_DEFAULT, const Color &defaultColor = UNSPECIFIED_LOGGING_COLOR);
~MMLogger() override = default;

bool IsChannelEnabled(LoggingSeverity_t severity) const;
bool IsChannelEnabled(LoggingVerbosity_t verbosity) const;
LoggingVerbosity_t GetChannelVerbosity() const;
Color GetColor() const;
LoggingChannelFlags_t GetFlags() const;
using Base = MMLoggerBase;
using Base::Base;

LoggingResponse_t Log(LoggingSeverity_t severity, const char *message);
LoggingResponse_t Log(LoggingSeverity_t severity, const Color &color, const char *message);
LoggingResponse_t Log(LoggingSeverity_t severity, const LeafCodeInfo_t &code, const char *message);
LoggingResponse_t Log(LoggingSeverity_t severity, const LeafCodeInfo_t &code, const Color &color, const char *message);
~MMLogger() override = default;

//LoggingResponse_t LogFormat(LoggingSeverity_t severity, const char *format, ...);
//LoggingResponse_t LogFormat(LoggingSeverity_t severity, const Color &color, const char *format, ...);
//LoggingResponse_t LogFormat(LoggingSeverity_t severity, const LeafCodeInfo_t &code, const char *format, ...);
//LoggingResponse_t LogFormat(LoggingSeverity_t severity, const LeafCodeInfo_t &code, const Color &color, const char *format, ...);
void SetSeverity(plugify::Severity severity);

/*plugify*/
public: // plugify::ILogger
void Log(std::string_view message, plugify::Severity severity);
void SetSeverity(plugify::Severity severity);

private:
plugify::Severity m_severity{ plugify::Severity::None };
LoggingChannelID_t m_channelID;
plugify::Severity m_severity { plugify::Severity::None };
};
} // namespace plugifyMM
Loading

0 comments on commit 15da25d

Please sign in to comment.