How to get the time an output was printed?

I’m making a game that includes a debug menu for developers, which basically just makes a new textlabel instance when an output is made, and sets the text property to the output’s text. I would also like to include the time the output was made. (it is displayed in the Output menu, but how can i detect this?)

Does it display it right when it is printed? If so, I’d use os.date("%X") for hour:minute:second

But, I would use

local Date = DateTime.now():ToLocalTime()

local timestamp = `{Date.Hour}:{Date.Minute}:{Date.Second}`

All of these are from

Oddly, this works, but all outputs in the debug menu are set to the same time, even when i test printing in the command bar after joining?

Are you using the same variable every time?

I believe so…?

local LogService = game:GetService("LogService")
local Date = DateTime.now():ToLocalTime()

local function onMessageOut(message, messageType)
	local messageLabel = Instance.new("TextLabel")
	messageLabel.RichText = true
	messageLabel.Parent = script.Parent
	messageLabel.Size = UDim2.new(0, 361, 0, 90)
	local timestamp = `{Date.Hour}:{Date.Minute}:{Date.Second}`
	messageLabel.Text = message.." <font color=\"#626262\">"..timestamp.."</font>"
     -- stuff down here doesnt matter i dont think
	messageLabel.TextScaled = true
	messageLabel.Font = Enum.Font.RobotoMono
	messageLabel.AutomaticSize = Enum.AutomaticSize.X
	local uicorner = Instance.new("UICorner")
	uicorner.Parent = messageLabel
	local textstroke = Instance.new("UIStroke")
	textstroke.Parent = messageLabel
	textstroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
	textstroke.Thickness = 4
	if messageType == Enum.MessageType.MessageInfo then
		textstroke.Color = Color3.new(0.384314, 0.643137, 0.756863)
	elseif messageType == Enum.MessageType.MessageError then
		textstroke.Color = Color3.new(0.588235, 0, 0.00784314)
	elseif messageType == Enum.MessageType.MessageWarning then
		textstroke.Color = Color3.new(0.941176, 0.627451, 0)
	end
end

LogService.MessageOut:Connect(onMessageOut)

Put the date variable inside the event

Dunno why my peanut brain didn’t think of this. Thank you!

1 Like

Hey, your brain isn’t a peanut, mine is. I forgot about some memory management and got a memory allocation error (and a memory dump) when I don’t know where the error is caused from in my C program. :sad:

1 Like