Integrate fmt into log

This commit is contained in:
Lucien Greathouse
2019-11-15 15:39:15 -08:00
parent 3126de2c37
commit 3a9f438390
5 changed files with 44 additions and 27 deletions

View File

@@ -220,7 +220,24 @@ local function fmt(template, ...)
return buffer:finish()
end
--[[
Wrap the given object in a type that implements the given function as its
Debug implementation, and forwards __tostring to the type's underlying
tostring implementation.
]]
local function debugify(object, fmtFunc)
return setmetatable({}, {
__fmtDebug = function(_, ...)
return fmtFunc(object, ...)
end,
__tostring = function()
return tostring(object)
end,
})
end
return {
debugOutputBuffer = debugOutputBuffer,
fmt = fmt,
debugify = debugify,
}

View File

@@ -17,7 +17,7 @@ local function performRequest(requestParams)
local requestId = lastRequestId + 1
lastRequestId = requestId
Log.trace("%s(%d) %s", requestParams.Method, requestId, requestParams.Url)
Log.trace("HTTP {}({}) {}", requestParams.Method, requestId, requestParams.Url)
if requestParams.Body ~= nil then
Log.trace(requestParams.Body)
@@ -30,10 +30,10 @@ local function performRequest(requestParams)
end)
if success then
Log.trace("Request %d success: status code %s", requestId, response.StatusCode)
Log.trace("Request {} success: status code {:?}", requestId, response.StatusCode)
resolve(HttpResponse.fromRobloxResponse(response))
else
Log.trace("Request %d failure: %s", requestId, response)
Log.trace("Request {} failure: {:?}", requestId, response)
reject(HttpError.fromRobloxErrorString(response))
end
end)()

View File

@@ -1,3 +1,5 @@
local Fmt = require(script.Parent.Fmt)
local Level = {
Error = 0,
Warning = 1,
@@ -29,25 +31,25 @@ end
function Log.trace(template, ...)
if getLogLevel() >= Level.Trace then
print(addTags(TRACE_TAG, string.format(template, ...)))
print(addTags(TRACE_TAG, Fmt.fmt(template, ...)))
end
end
function Log.info(template, ...)
if getLogLevel() >= Level.Info then
print(addTags(INFO_TAG, string.format(template, ...)))
print(addTags(INFO_TAG, Fmt.fmt(template, ...)))
end
end
function Log.debug(template, ...)
if getLogLevel() >= Level.Debug then
print(addTags(DEBUG_TAG, string.format(template, ...)))
print(addTags(DEBUG_TAG, Fmt.fmt(template, ...)))
end
end
function Log.warn(template, ...)
if getLogLevel() >= Level.Warning then
warn(addTags(WARN_TAG, string.format(template, ...)))
warn(addTags(WARN_TAG, Fmt.fmt(template, ...)))
end
end

View File

@@ -119,7 +119,7 @@ function InstanceMap:__connectSignals(instance)
end
function InstanceMap:__maybeFireInstanceChanged(instance, propertyName)
Log.trace("%s.%s changed", instance:GetFullName(), propertyName)
Log.trace("{}.{} changed", instance:GetFullName(), propertyName)
if self.onInstanceChanged ~= nil then
self.onInstanceChanged(instance, propertyName)

View File

@@ -11,28 +11,26 @@ local Status = strict("Session.Status", {
Disconnected = "Disconnected",
})
local function fmtPatch(patch)
local output = Fmt.debugOutputBuffer()
local function debugPatch(patch)
return Fmt.debugify(patch, function(patch, output)
output:writeLine("Patch {{")
output:indent()
output:writeLine("Patch {{")
output:indent()
for removed in ipairs(patch.removed) do
output:writeLine("Remove ID {}", removed)
end
for removed in ipairs(patch.removed) do
output:writeLine("Remove ID {}", removed)
end
for id, added in pairs(patch.added) do
output:writeLine("Add ID {} {:#?}", id, added)
end
for id, added in pairs(patch.added) do
output:writeLine("Add ID {} {:#?}", id, added)
end
for _, updated in ipairs(patch.updated) do
output:writeLine("Update ID {} {:#?}", updated.id, updated)
end
for _, updated in ipairs(patch.updated) do
output:writeLine("Update ID {} {:#?}", updated.id, updated)
end
output:unindent()
output:writeLine("}")
return output:finish()
output:unindent()
output:write("}")
end)
end
local ServeSession = {}
@@ -104,7 +102,7 @@ function ServeSession:__initialSync(rootInstanceId)
game
)
Log.trace("Computed hydration patch: %s", fmtPatch(hydratePatch))
Log.trace("Computed hydration patch: {:#?}", debugPatch(hydratePatch))
-- TODO: Prompt user to notify them of this patch, since it's
-- effectively a conflict between the Rojo server and the client.