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 = {}
gmInte.version = "0.1.3" gmInte.version = "0.1.3"
gmInte.config = {} gmInte.config = {}
gmInte.debug = false
// //
// Functions // Functions

View File

@ -22,7 +22,7 @@ end
function socket:onMessage(txt) function socket:onMessage(txt)
gmInte.log("WebSocket Message: " .. txt, true) gmInte.log("WebSocket Message: " .. txt, true)
local data = util.JSONToTable(txt) local data = util.JSONToTable(txt)
if (gmInte.config.debug) then if (gmInte.debug) then
gmInte.log("WebSocket Message: " .. txt, true) gmInte.log("WebSocket Message: " .. txt, true)
end end
if (gmInte[data.method]) then if (gmInte[data.method]) then

View File

@ -19,13 +19,14 @@ local function sendHTTP(params)
type = "application/json", type = "application/json",
success = function(code, body, headers) success = function(code, body, headers)
gmInte.log("HTTP Response: " .. code, true) 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 (string.sub(code, 1, 1) == "2") then
if (params.success) then if (params.success) then
params.success(code, body, headers) params.success(code, body, headers)
end end
else 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
end, end,
failed = function(error) failed = function(error)

View File

@ -4,13 +4,13 @@
// Log // Log
function gmInte.log(msg, debug) 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) print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] " .. msg)
end end
// Log Error // Log Error
function gmInte.logError(msg, debug) 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) print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [ERROR] " .. msg)
if (debug) then print(debug.traceback()) end if (debug) then print(debug.traceback()) end
end end

View File

@ -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 gmInte.config.filterOnTrust = true // If true, the addon will filter the players according to their trust factor
// Ban // Ban
gmInte.config.filterOnBan = true // If true, the addon will filter the players according to their ban status 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