Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

File logger produces strange text

use Phalcon\Logger\Adapter\File The log files are randomly broken. Weird charactersets or something. The log files appear as text/plain but often contain asian symbols and all sorts of rubbish. I have to jump around several editors to find one that can display the text as text. Is there a setting to fix it? If not, I will revert to PHP.



3.2k

Hello,

Can you post our service logger d├ęclaration and how to write log ?



4.8k
Accepted
answer

I found out it is not Phalcon. A raw PHP file_put_contents creates the same random garbage. I replaced the Phalcon logger with PHP code and ended up with the same mess. A file that randomly fails in Bluefish and Text Editor but works in Notepad and LibreOffice Writer. I guess I will have to use LibreOffice Writer for my development environment!



4.8k

I will look in PHP and Linux sites to find out why some files trigger garbage displays in editors. In Linux Mint, Text Editor is xed.

I can append dozens of rows to a working log file then the next row will make the change that kills the file display in editors. For one file, some of the editors displayed text at the start then garbage.

I opened a garbage file in LO Writer, saved the file as text, then opened the new file in Bluefish and it displayed as text. I never had this problem with Linux Mint 18, it was a rare occurence in LM 18.1, and is frequent in LM 18.2. Something in linux is going downhill.

What's your language? It could be some charset error...

edited Jul '17

Wait. You're putting it too much here - IDE of your choice is one thing, while actual output produced by Logger class / or simple file_put_contents function is another. So you need to validate those files by "non-smart" text editors, and command line tools such as less. I'm guessing that line breaks (LF) might be causing issues especially for Windows based editors (notepad, wordpad etc.).

I'm using:

use \Phalcon\Logger\Adapter\File as AuditLogFileAdapter,
    \Phalcon\Logger\Formatter\Json as AuditLogFormatterJson,

w/o any issues, especially that other systems parse that json and make use of the logs.

Tip: try to open your log file in nano, do you see any garbage chars?



4.8k
edited Jul '17

My code is back to the Phalcon logger. I found part of the problem. Nano, Notepad, and LibreOffice are all happy with the text. Switching to LibreOffice for an IDE might not be so bad. The code comments could have beautiful formatting. :-)

Bluefish thinks it is UTF-16BE desipite the start of the file being plain text. Bluefish must read the while file before guessing what the characterset might be.

Xed displays a characterset error message and highlights \00 characters. They are from serialize. s:7:"\00*\00name" I added str_replace("\00", '', to the serialize output and the log files work in every editor. Maybe I should capture var_dump output instead.