-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Luya's logger alters arguments of method it was called from #456
Comments
Do you suggest any fix here? Because it seems to be a "problem" of php's debug backtrace function not the logger itself. maybe we could add a php doc regarding this? |
I think the problem is here, $fnArgs is a ref to args and it being altered after
I think doing clone() before calling Json::encode() should help as it will destroy the reference. |
would you please send a pull request? would nice! thanks |
@nadar Yep I will try tomorrow to fix it. |
Hey @nadar, btw what do you think if to remove hardcoded debug_backtrace from Logger::success() and Logger::info()? Or to make it conditional? Such info log output can be often even in production and it takes time and performance to get and encode backtrace into json and usually it is not needed for info and success types of messages, when you want just echo some information. PS And I mean not only backtrace but whole bunch of debug info
PPS Btw the debug_backtrace has an option since 5.3.6 to omit 'args' from output because of memory concerns. |
well i would not change the main intent of the function. Its not just a log mechanism it should also collect its environment, this might help to debug or find informations in certain situations. The trace is limited to 2 rows, which i don't think is a memory problem. But we could add |
Beware of using
\luya\admin\models\Logger::info()
or
\luya\admin\models\Logger::warning()
or
\luya\admin\models\Logger::error()
inside any method which has object argument passed by reference.
After calling the logger the argument will become array.
Example:
Looks like it is because ['args'] part of array from debug_backtrace() is returned by reference and it is being altered during json encode inside Logger::log()
https://www.php.net/manual/en/function.debug-backtrace.php#110237
The text was updated successfully, but these errors were encountered: