log http body on debug only

This commit is contained in:
Linventif 2023-11-05 03:01:55 +01:00
parent 26285bd72f
commit fd847e3860
5 changed files with 8 additions and 13 deletions

View File

@ -7,6 +7,7 @@ if game.SinglePlayer() then return end
gmInte = {}
gmInte.version = "0.1.3"
gmInte.config = {}
gmInte.debug = false
//
// Functions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -89,10 +89,3 @@ gmInte.config.filterOnTrust = true // If true, the addon will filter the players
// 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