forked from rojo-rbx/rojo
Integrate fmt into log
This commit is contained in:
@@ -220,7 +220,24 @@ local function fmt(template, ...)
|
|||||||
return buffer:finish()
|
return buffer:finish()
|
||||||
end
|
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 {
|
return {
|
||||||
debugOutputBuffer = debugOutputBuffer,
|
debugOutputBuffer = debugOutputBuffer,
|
||||||
fmt = fmt,
|
fmt = fmt,
|
||||||
|
debugify = debugify,
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@ local function performRequest(requestParams)
|
|||||||
local requestId = lastRequestId + 1
|
local requestId = lastRequestId + 1
|
||||||
lastRequestId = requestId
|
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
|
if requestParams.Body ~= nil then
|
||||||
Log.trace(requestParams.Body)
|
Log.trace(requestParams.Body)
|
||||||
@@ -30,10 +30,10 @@ local function performRequest(requestParams)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
if success then
|
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))
|
resolve(HttpResponse.fromRobloxResponse(response))
|
||||||
else
|
else
|
||||||
Log.trace("Request %d failure: %s", requestId, response)
|
Log.trace("Request {} failure: {:?}", requestId, response)
|
||||||
reject(HttpError.fromRobloxErrorString(response))
|
reject(HttpError.fromRobloxErrorString(response))
|
||||||
end
|
end
|
||||||
end)()
|
end)()
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
local Fmt = require(script.Parent.Fmt)
|
||||||
|
|
||||||
local Level = {
|
local Level = {
|
||||||
Error = 0,
|
Error = 0,
|
||||||
Warning = 1,
|
Warning = 1,
|
||||||
@@ -29,25 +31,25 @@ end
|
|||||||
|
|
||||||
function Log.trace(template, ...)
|
function Log.trace(template, ...)
|
||||||
if getLogLevel() >= Level.Trace then
|
if getLogLevel() >= Level.Trace then
|
||||||
print(addTags(TRACE_TAG, string.format(template, ...)))
|
print(addTags(TRACE_TAG, Fmt.fmt(template, ...)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Log.info(template, ...)
|
function Log.info(template, ...)
|
||||||
if getLogLevel() >= Level.Info then
|
if getLogLevel() >= Level.Info then
|
||||||
print(addTags(INFO_TAG, string.format(template, ...)))
|
print(addTags(INFO_TAG, Fmt.fmt(template, ...)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Log.debug(template, ...)
|
function Log.debug(template, ...)
|
||||||
if getLogLevel() >= Level.Debug then
|
if getLogLevel() >= Level.Debug then
|
||||||
print(addTags(DEBUG_TAG, string.format(template, ...)))
|
print(addTags(DEBUG_TAG, Fmt.fmt(template, ...)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Log.warn(template, ...)
|
function Log.warn(template, ...)
|
||||||
if getLogLevel() >= Level.Warning then
|
if getLogLevel() >= Level.Warning then
|
||||||
warn(addTags(WARN_TAG, string.format(template, ...)))
|
warn(addTags(WARN_TAG, Fmt.fmt(template, ...)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ function InstanceMap:__connectSignals(instance)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function InstanceMap:__maybeFireInstanceChanged(instance, propertyName)
|
function InstanceMap:__maybeFireInstanceChanged(instance, propertyName)
|
||||||
Log.trace("%s.%s changed", instance:GetFullName(), propertyName)
|
Log.trace("{}.{} changed", instance:GetFullName(), propertyName)
|
||||||
|
|
||||||
if self.onInstanceChanged ~= nil then
|
if self.onInstanceChanged ~= nil then
|
||||||
self.onInstanceChanged(instance, propertyName)
|
self.onInstanceChanged(instance, propertyName)
|
||||||
|
|||||||
@@ -11,28 +11,26 @@ local Status = strict("Session.Status", {
|
|||||||
Disconnected = "Disconnected",
|
Disconnected = "Disconnected",
|
||||||
})
|
})
|
||||||
|
|
||||||
local function fmtPatch(patch)
|
local function debugPatch(patch)
|
||||||
local output = Fmt.debugOutputBuffer()
|
return Fmt.debugify(patch, function(patch, output)
|
||||||
|
output:writeLine("Patch {{")
|
||||||
|
output:indent()
|
||||||
|
|
||||||
output:writeLine("Patch {{")
|
for removed in ipairs(patch.removed) do
|
||||||
output:indent()
|
output:writeLine("Remove ID {}", removed)
|
||||||
|
end
|
||||||
|
|
||||||
for removed in ipairs(patch.removed) do
|
for id, added in pairs(patch.added) do
|
||||||
output:writeLine("Remove ID {}", removed)
|
output:writeLine("Add ID {} {:#?}", id, added)
|
||||||
end
|
end
|
||||||
|
|
||||||
for id, added in pairs(patch.added) do
|
for _, updated in ipairs(patch.updated) do
|
||||||
output:writeLine("Add ID {} {:#?}", id, added)
|
output:writeLine("Update ID {} {:#?}", updated.id, updated)
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, updated in ipairs(patch.updated) do
|
output:unindent()
|
||||||
output:writeLine("Update ID {} {:#?}", updated.id, updated)
|
output:write("}")
|
||||||
end
|
end)
|
||||||
|
|
||||||
output:unindent()
|
|
||||||
output:writeLine("}")
|
|
||||||
|
|
||||||
return output:finish()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local ServeSession = {}
|
local ServeSession = {}
|
||||||
@@ -104,7 +102,7 @@ function ServeSession:__initialSync(rootInstanceId)
|
|||||||
game
|
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
|
-- TODO: Prompt user to notify them of this patch, since it's
|
||||||
-- effectively a conflict between the Rojo server and the client.
|
-- effectively a conflict between the Rojo server and the client.
|
||||||
|
|||||||
Reference in New Issue
Block a user