From fd847e38600a0b5e8b085dd5cfa59c9c72962b30 Mon Sep 17 00:00:00 2001 From: Linventif Date: Sun, 5 Nov 2023 03:01:55 +0100 Subject: [PATCH] log http body on debug only --- lua/autorun/gmod_integration.lua | 1 + lua/gmod_integration/server/sv__websocket.lua | 2 +- lua/gmod_integration/shared/sh_http.lua | 5 +++-- lua/gmod_integration/shared/sh_main.lua | 4 ++-- lua/gmod_integration/sv_config.lua | 9 +-------- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/lua/autorun/gmod_integration.lua b/lua/autorun/gmod_integration.lua index b4e7b58..c2344d6 100644 --- a/lua/autorun/gmod_integration.lua +++ b/lua/autorun/gmod_integration.lua @@ -7,6 +7,7 @@ if game.SinglePlayer() then return end gmInte = {} gmInte.version = "0.1.3" gmInte.config = {} +gmInte.debug = false // // Functions diff --git a/lua/gmod_integration/server/sv__websocket.lua b/lua/gmod_integration/server/sv__websocket.lua index fbebd73..291a065 100644 --- a/lua/gmod_integration/server/sv__websocket.lua +++ b/lua/gmod_integration/server/sv__websocket.lua @@ -22,7 +22,7 @@ end function socket:onMessage(txt) gmInte.log("WebSocket Message: " .. txt, true) local data = util.JSONToTable(txt) - if (gmInte.config.debug) then + if (gmInte.debug) then gmInte.log("WebSocket Message: " .. txt, true) end if (gmInte[data.method]) then diff --git a/lua/gmod_integration/shared/sh_http.lua b/lua/gmod_integration/shared/sh_http.lua index cdd67d2..6cb4998 100644 --- a/lua/gmod_integration/shared/sh_http.lua +++ b/lua/gmod_integration/shared/sh_http.lua @@ -19,13 +19,14 @@ local function sendHTTP(params) type = "application/json", success = function(code, body, headers) gmInte.log("HTTP Response: " .. code, true) - gmInte.log("HTTP Body: " .. body, true) + if (gmInte.debug) then gmInte.log("HTTP Body: " .. body, true) end if (string.sub(code, 1, 1) == "2") then if (params.success) then params.success(code, body, headers) end else - gmInte.logError("HTTP Request failed with code " .. code .. " and body " .. body) + gmInte.logError("HTTP Request failed with code " .. code) + if (gmInte.debug) then gmInte.logError("HTTP Body: " .. body) end end end, failed = function(error) diff --git a/lua/gmod_integration/shared/sh_main.lua b/lua/gmod_integration/shared/sh_main.lua index 6f5b40e..c41384f 100644 --- a/lua/gmod_integration/shared/sh_main.lua +++ b/lua/gmod_integration/shared/sh_main.lua @@ -4,13 +4,13 @@ // Log function gmInte.log(msg, debug) - if (debug && !gmInte.config.debug) then return end + if (debug && !gmInte.debug) then return end print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] " .. msg) end // Log Error function gmInte.logError(msg, debug) - if (debug && !gmInte.config.debug) then return end + if (debug && !gmInte.debug) then return end print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [ERROR] " .. msg) if (debug) then print(debug.traceback()) end end \ No newline at end of file diff --git a/lua/gmod_integration/sv_config.lua b/lua/gmod_integration/sv_config.lua index a85cb7d..3a04fdf 100644 --- a/lua/gmod_integration/sv_config.lua +++ b/lua/gmod_integration/sv_config.lua @@ -88,11 +88,4 @@ gmInte.config.minimalTrust = 30 // The minimal trust factor of an user to be abl gmInte.config.filterOnTrust = true // If true, the addon will filter the players according to their trust factor // Ban -gmInte.config.filterOnBan = true // If true, the addon will filter the players according to their ban status - -// -// Other -// - -// Debug -gmInte.config.debug = false // If true, the addon will print debug informations in the console \ No newline at end of file +gmInte.config.filterOnBan = true // If true, the addon will filter the players according to their ban status \ No newline at end of file