为什么我的 PHP 日志文件不完全是文本?
我正在尝试调试插件臃肿的 WordPress 安装;所以我添加了一个非常简单的自制记录器来记录所有回调,这些回调基本上列在 WordPress 中的一个最终 250 多行多维数组中(我不能使用 print_r()
因为我需要在他们被叫之前抓住他们)。
我的记录器行是 $logger->log("\t" . $callback . "\n");
记录器在正常情况下会生成一个漂亮的文本文件,但在此特定情况下会在两个点上生成任务是添加一些导致我的日志文件不再正确编码的内容。 Gedit(我在 Ubuntu 上)不会打开该文件,声称不理解编码。在 vim 中,罪魁祸首损坏的回调(我无法在调试器中找到,查看数组)大约在中间并打印为 ^@lambda_546
在文件末尾有一个可爱的家伙<代码>^M。 ^M
和 ^@
在我的 vim 中是蓝色的,它没有为 .txt
文件设置颜色主题。我不知道这意味着什么。
我尝试添加 is_string($callback) 条件,但得到相同的结果。
有什么想法吗?
I'm trying to debug a plugin-bloated Wordpress installation; so I've added a very simple homebrew logger that records all the callbacks, which are basically listed in a single, ultimately 250+ row multidimensional array in Wordpress (I can't use print_r()
because I need to catch them right before they are called).
My logger line is $logger->log("\t" . $callback . "\n");
The logger produces a dandy text file in normal situations, but at two points during this particular task it is adding something which causes my log file to no longer be encoded properly. Gedit (I'm on Ubuntu) won't open the file, claiming to not understand the encoding. In vim, the culprit corrupt callback (which I could not find in the debugger, looking at the array) is about in the middle and printed as ^@lambda_546
and at the end of file there's this cute guy ^M
. The ^M
and ^@
are blue in my vim, which has no color theme set for .txt
files. I don't know what it means.
I tried adding an is_string($callback)
condition, but I get the same results.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
^@
是 NUL 字符 (\0
),^M
是 CR (\r
)。但不知道为什么会生成它们。您必须仔细研究源代码和数据库才能找到答案。不过 geany 应该能够轻松打开该文件。^@
is a NUL character (\0
) and^M
is a CR (\r
). No idea why they're being generated though. You'd have to muck through the source and database to find out. geany should be able to open the file easily enough though.看来这些可爱的家伙是你的 Windows 回调格式的结果。
Seems these cute guys are a result of your callback formatting for windows.
谜底揭晓。其中一个回调是匿名函数。在调查 PHP
create_function
文档时,我发现评论者指出创建的函数的名称如下:chr(0) 。 lambda_n。谢谢 PHP。
至于
\r
。嗯,那就更尴尬了。我的记录器重用了我之前编写的一些旧代码,这些代码在\r\n
中结束了行。Mystery over. One of the callbacks was an anonymous function. Investigating the PHP
create_function
documentation, I saw that a commenter had noted that the created function has a name like so:chr(0) . lambda_n
. Thanks PHP.As for the
\r
. Well, that is more embarrassing. My logger reused some older code that I previously written which did end lines in\r\n
.