LogService.MessageOut not working on Roblox Player

Reproduction Steps

1) Put this on ServerScriptService:

local LogService = game:GetService("LogService")

LogService.MessageOut:Connect(function(Message, Type)
	print('***Message, Type', Message, Type)
end)

print('PRINT SERVER')
warn('WARN SERVER')
error('ERROR SERVER')
  1. When run it on Studio, it’s working:

  2. But if I run the same in Roblox Player, it’s not working:


Expected Behavior

I need to intercept warning messages on the server script.

Actual Behavior

It only works inside Studio.

----------

Issue Area: Engine
Issue Type: Other
Impact: High
Frequency: Constantly

6 Likes

I was able to reproduce this issue, and am investigating the cause. Do you know if this is a new issue?

3 Likes

No, that’s the first time I’m testing MessageOut for real.

2 Likes

This has been an on-going issue for years. You can probably find other posts about this behavior relatively easily.

2 Likes

This was intentional behavior I believe, if you print/warn/error/anything that writes to stdout in a MessageOut callback it would become recursive

Not only that, there are ways to make LogService or ScriptContext recursive, but this isn’t related to the issue.

1 Like

However, this does function (IE: the event fires and prints), in Studio. The issue is specifically with the Roblox live server.

1 Like

I’m able to repro this but found that it just ignores prints from the event handler in a live game. The event is still fired. IIRC I saw in a release notes a while ago that printing was allowed from MessageOut where it wasn’t previously- maybe this is related to that change?

You still running into this? I can’t repro:

image

For reference, here is my script (includes a check to avoid reentrancy):

game.LogService.MessageOut:Connect(function(msg, ty)
	if string.find(msg, "Got") then
		return
	end
	print("Got:", msg, ty)
end)

print("PRINT SERVER")
warn("WARN SERVER")
error("ERROR SERVER")

Ran into this today, works in Studio but not live.

local LogService = game:GetService('LogService')

local messageTypeMap = {
	[Enum.MessageType.MessageWarning] = ' Warning:',
	[Enum.MessageType.MessageError] = ' Error:',
	[Enum.MessageType.MessageInfo] = ''
}

local function onMessageOut(message: string, messageType: Enum.MessageType, timestamp: number?)
	if messageType == Enum.MessageType.MessageOutput then return end
	timestamp = timestamp or workspace:GetServerTimeNow()
	print(`{timestamp}{messageTypeMap[messageType]} {message}`)
end

LogService.MessageOut:Connect(onMessageOut)
for _, log in LogService:GetLogHistory() do onMessageOut(log.message, log.messageType, log.timestamp) end

EDIT:
This claim seems correct: LogService doesn't work online - #4 by AlreadyPro

1 Like

If you run exactly my code above (in a Script in ServerScriptService) does it work? The above screenshot by me is running in a live server.

It does, and mine actually does too, in a fresh place. I may have overlooked something, but it doesn’t matter much as prints/warns/errors from within the function aren’t of much use anyways. What’s important is that it does pick everything up.

Does it not in some other place?

What is it not picking up?

I remain unable to repro any issues (as of 6 days ago when I last took a look at this and replied).

Correct, in some other place neither yours nor mine works (in terms of printing):

It works in Studio but not live.

Because of an NDA I cannot share further details about this place, I’m sorry. I will say that the place also uses ScriptContext.Error in another script, and that is the only somewhat related thing I can think of.

It is picking up everything, I might have worded it oddly.