Skip to content

Commit

Permalink
Remove logger
Browse files Browse the repository at this point in the history
  • Loading branch information
qubka committed Oct 12, 2024
1 parent 5ac5f1b commit f320f33
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 59 deletions.
5 changes: 1 addition & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,4 @@
[submodule "external/sourcesdk"]
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
branch = main
8 changes: 3 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ function(set_or_external_dir VAR_NAME TARGET)
set(${VAR_NAME} "${${VAR_NAME}}" PARENT_SCOPE)
endfunction()

set_or_external_dir(LOGGER_DIR "logger")
set_or_external_dir(METAMOD_DIR "metamod-source")
set_or_external_dir(PLUGIFY_DIR "plugify")
set_or_external_dir(SOURCESDK_DIR "sourcesdk")

include(cmake/platform/shared.cmake)
include(cmake/logger.cmake)
include(cmake/metamod.cmake)
include(cmake/plugify.cmake)
include(cmake/sourcesdk.cmake)
Expand Down Expand Up @@ -87,10 +85,10 @@ if(UNIX)
endif()
endif()

target_compile_definitions(${PROJECT_NAME} PRIVATE ${COMPILE_DEFINITIONS} ${LOGGER_COMPILE_DEFINITIONS} ${METAMOD_COMPILE_DEFINITIONS} ${PLUGIFY_COMPILE_DEFINITIONS})
target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDE_DIRS} ${LOGGER_INCLUDE_DIRS} ${METAMOD_INCLUDE_DIRS} ${PLUGIFY_INCLUDE_DIRS})
target_compile_definitions(${PROJECT_NAME} PRIVATE ${METAMOD_COMPILE_DEFINITIONS} ${PLUGIFY_COMPILE_DEFINITIONS})
target_include_directories(${PROJECT_NAME} PRIVATE ${METAMOD_INCLUDE_DIRS} ${PLUGIFY_INCLUDE_DIRS})

target_link_libraries(${PROJECT_NAME} PRIVATE ${LOGGER_BINARY_DIR} ${PLUGIFY_BINARY_DIR} ${PLUGIFY_LINK_LIBRARIES} ${SOURCESDK_BINARY_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE ${PLUGIFY_BINARY_DIR} ${PLUGIFY_LINK_LIBRARIES} ${SOURCESDK_BINARY_DIR})

configure_file(
${CMAKE_SOURCE_DIR}/plugify.pconfig.in
Expand Down
17 changes: 0 additions & 17 deletions cmake/logger.cmake

This file was deleted.

1 change: 0 additions & 1 deletion external/logger
Submodule logger deleted from 63659e
2 changes: 1 addition & 1 deletion external/plugify
Submodule plugify updated 85 files
+4 −5 .github/workflows/clang.yml
+3 −3 .github/workflows/gcc.yml
+3 −3 .github/workflows/msvc.yml
+2 −2 .github/workflows/msys2.yml
+2 −2 .github/workflows/publish-docs.yml
+96 −28 CMakeLists.txt
+1 −1 README.md
+3 −3 docs/doxy.in
+1 −1 include/plugify/assembly.h
+1 −1 include/plugify/compat_format.h
+1 −1 include/plugify/config.h
+1 −1 include/plugify/descriptor.h
+10 −9 include/plugify/jit/call.h
+173 −0 include/plugify/jit/call_arm.cpp
+17 −17 include/plugify/jit/call_x86.cpp
+8 −7 include/plugify/jit/callback.h
+272 −0 include/plugify/jit/callback_arm.cpp
+23 −26 include/plugify/jit/callback_x86.cpp
+80 −4 include/plugify/jit/helpers.cpp
+1 −1 include/plugify/jit/helpers.h
+1 −1 include/plugify/language_module_descriptor.h
+1 −1 include/plugify/load_flag.h
+1 −1 include/plugify/mem_addr.h
+1 −1 include/plugify/mem_protector.h
+1 −1 include/plugify/method.h
+1 −1 include/plugify/package.h
+1 −1 include/plugify/package_manager.h
+1 −1 include/plugify/path.h
+1 −1 include/plugify/plugify_provider.h
+1 −1 include/plugify/plugin_descriptor.h
+1 −1 include/plugify/plugin_reference_descriptor.h
+1 −1 include/plugify/prot_flag.h
+0 −1 include/plugify/reference_wrapper.h
+3 −3 include/plugify/value_type.h
+1 −1 src/core/language_module_descriptor.h
+1 −1 src/core/method.h
+1 −1 src/core/module.cpp
+1 −1 src/core/module.h
+3 −3 src/core/package_manager.cpp
+1 −1 src/core/package_manager.h
+1 −1 src/core/package_manifest.h
+1 −1 src/core/plugify_provider.cpp
+1 −1 src/core/plugin.h
+1 −1 src/core/plugin_descriptor.h
+1 −1 src/core/plugin_manager.cpp
+1 −1 src/core/plugin_manager.h
+1 −1 src/core/plugin_reference_descriptor.h
+1 −1 src/interface/language_module_descriptor.cpp
+1 −1 src/interface/method.cpp
+1 −1 src/interface/module.cpp
+1 −1 src/interface/plugify_provider.cpp
+1 −1 src/interface/plugin.cpp
+1 −1 src/interface/plugin_descriptor.cpp
+1 −1 src/interface/plugin_reference_descriptor.cpp
+1 −1 src/pch.h
+26 −3 src/utils/assembly.cpp
+14 −3 src/utils/assembly_apple.cpp
+18 −7 src/utils/assembly_linux.cpp
+136 −0 src/utils/assembly_playstation.cpp
+150 −0 src/utils/assembly_switch.cpp
+29 −10 src/utils/assembly_windows.cpp
+10 −6 src/utils/assert.h
+9 −3 src/utils/binary_format.h
+1 −1 src/utils/date_time.h
+1 −1 src/utils/file_system.cpp
+1 −1 src/utils/file_system.h
+1 −1 src/utils/hash.h
+1 −1 src/utils/http_downloader.cpp
+1 −1 src/utils/http_downloader.h
+1 −0 src/utils/http_downloader_curl.cpp
+1 −1 src/utils/http_downloader_curl.h
+1 −1 src/utils/http_downloader_winhttp.cpp
+1 −1 src/utils/http_downloader_winhttp.h
+1 −1 src/utils/json.h
+1 −1 src/utils/log.cpp
+1 −1 src/utils/mem_accesor.cpp
+12 −1 src/utils/os.h
+1 −1 src/utils/platform.cpp
+1 −1 src/utils/platform.h
+1 −1 src/utils/pointer.h
+219 −197 src/utils/sha256.cpp
+28 −15 src/utils/sha256.h
+1 −1 src/utils/strings.cpp
+3 −3 src/utils/strings.h
+1 −1 test/plug/CMakeLists.txt
2 changes: 1 addition & 1 deletion external/sourcesdk
101 changes: 87 additions & 14 deletions src/mm_logger.cpp
Original file line number Diff line number Diff line change
@@ -1,61 +1,134 @@
#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) const
{
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) const
{
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) const
{
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) const
{
LoggingResponse_t response = LR_ABORT;

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

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:
{
Error({255, 0, 255, 255}, pszMessage);

Log(LS_ERROR, Color(255, 0, 255, 255), sMessage.c_str());
break;
}

case plugify::Severity::Error:
{
Warning({255, 0, 0, 255}, pszMessage);

Log(LS_WARNING, Color(255, 0, 0, 255), sMessage.c_str());
break;
}

case plugify::Severity::Warning:
{
Warning({255, 127, 0, 255}, pszMessage);

Log(LS_WARNING, Color(255, 127, 0, 255), sMessage.c_str());
break;
}

case plugify::Severity::Info:
{
Message({255, 255, 0, 255}, pszMessage);

Log(LS_MESSAGE, Color(255, 255, 0, 255),sMessage.c_str());
break;
}

case plugify::Severity::Debug:
{
Detailed({0, 255, 255, 255}, pszMessage);

Log(LS_MESSAGE, Color(0, 255, 0, 255), sMessage.c_str());
break;
}

case plugify::Severity::Verbose:
{
Detailed({255, 255, 255, 255}, pszMessage);

Log(LS_MESSAGE, Color(255, 255, 255, 255), sMessage.c_str());
break;
}

Expand Down
32 changes: 18 additions & 14 deletions src/mm_logger.h
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
#pragma once

#include <functional>
#include <string>
#include <string_view>

#include <tier0/dbg.h>
#include <tier0/logging.h>

#include <plugify/log.h>
#include <plugify/compat_format.h>

#include <logger.hpp>

namespace plugifyMM
{
using MMLoggerBase = Logger;

class MMLogger final : public MMLoggerBase, public plugify::ILogger
class MMLogger final : public plugify::ILogger
{
public:
using Base = MMLoggerBase;
using Base::Base;

MMLogger(const char *name, RegisterTagsFunc registerTagsFunc, int flags = 0, LoggingVerbosity_t verbosity = LV_DEFAULT, const Color &defaultColor = UNSPECIFIED_LOGGING_COLOR);
~MMLogger() override = default;

void SetSeverity(plugify::Severity severity);
bool IsChannelEnabled(LoggingSeverity_t severity) const;
bool IsChannelEnabled(LoggingVerbosity_t verbosity) const;
LoggingVerbosity_t GetChannelVerbosity() const;
Color GetColor() const;
LoggingChannelFlags_t GetFlags() const;

LoggingResponse_t Log(LoggingSeverity_t severity, const char *message) const;
LoggingResponse_t Log(LoggingSeverity_t severity, const Color &color, const char *message) const;
LoggingResponse_t Log(LoggingSeverity_t severity, const LeafCodeInfo_t &code, const char *message) const;
LoggingResponse_t Log(LoggingSeverity_t severity, const LeafCodeInfo_t &code, const Color &color, const char *message) const;

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

private:
plugify::Severity m_severity { plugify::Severity::None };
plugify::Severity m_severity{ plugify::Severity::None };
LoggingChannelID_t m_channelID;
};
} // namespace plugifyMM
4 changes: 2 additions & 2 deletions src/mm_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ namespace plugifyMM
PlugifyMMPlugin g_Plugin;
PLUGIN_EXPOSE(PlugifyMMPlugin, g_Plugin);

#define CONPRINT(x) g_Plugin.m_logger->Message(x)
#define CONPRINTE(x) g_Plugin.m_logger->Warning(x)
#define CONPRINT(x) g_Plugin.m_logger->Log(LS_MESSAGE, x)
#define CONPRINTE(x) g_Plugin.m_logger->Log(LS_WARNING, x)

template <typename S, typename T, typename F> requires (std::is_function_v<F>)
void Print(std::string& out, const T &t, F &f, std::string_view tab = " ")
Expand Down

0 comments on commit f320f33

Please sign in to comment.