From 25ca0bb27e96b19753892a79920e26af8e762567 Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 1 Mar 2026 16:43:21 -0600 Subject: [PATCH] Improve logging performance by conditionally checking trace level - Introduced a new `isTraceEnabled` function in the logging module to check if trace logging is enabled based on the current log level. - Updated the `performRequest` function to only log HTTP request details and responses if trace logging is enabled, reducing unnecessary log output and improving performance. These changes aim to enhance the efficiency of logging during HTTP requests by avoiding excessive logging when not needed. --- plugin/http/init.lua | 17 +++++++++++------ plugin/log/init.lua | 4 ++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/plugin/http/init.lua b/plugin/http/init.lua index d74183ce..eec1af7e 100644 --- a/plugin/http/init.lua +++ b/plugin/http/init.lua @@ -18,10 +18,11 @@ local function performRequest(requestParams) local requestId = lastRequestId + 1 lastRequestId = requestId - Log.trace("HTTP {}({}) {}", requestParams.Method, requestId, requestParams.Url) - - if requestParams.Body ~= nil then - Log.trace("{}", requestParams.Body) + if Log.isTraceEnabled() then + Log.trace("HTTP {}({}) {}", requestParams.Method, requestId, requestParams.Url) + if requestParams.Body ~= nil then + Log.trace("{}", requestParams.Body) + end end return Promise.new(function(resolve, reject) @@ -31,7 +32,9 @@ local function performRequest(requestParams) end) if success then - Log.trace("Request {} success, response {:#?}", requestId, response) + if Log.isTraceEnabled() then + Log.trace("Request {} success, response {:#?}", requestId, response) + end local httpResponse = HttpResponse.fromRobloxResponse(response) if httpResponse:isSuccess() then resolve(httpResponse) @@ -39,7 +42,9 @@ local function performRequest(requestParams) reject(HttpError.fromResponse(httpResponse)) end else - Log.trace("Request {} failure: {:?}", requestId, response) + if Log.isTraceEnabled() then + Log.trace("Request {} failure: {:?}", requestId, response) + end reject(HttpError.fromRobloxErrorString(response)) end end)() diff --git a/plugin/log/init.lua b/plugin/log/init.lua index b1974b43..d4f62e51 100644 --- a/plugin/log/init.lua +++ b/plugin/log/init.lua @@ -29,6 +29,10 @@ function Log.setLogLevelThunk(thunk) getLogLevel = thunk end +function Log.isTraceEnabled() + return getLogLevel() >= Level.Trace +end + function Log.trace(template, ...) if getLogLevel() >= Level.Trace then print(addTags(TRACE_TAG, Fmt.fmt(template, ...)))