简体   繁体   中英

How to get properly encoded apache error.log with tailf?

I have code which can error with russian language message.

For example:

Неверно составлен limit

But error.log contains:

\xd0\x9d\xd0\xb5\xd0\xb2\xd0\xb5\xd1\x80\xd0\xbd\xd0\xbe \xd1\x81\xd0\xbe\xd1\x81\xd1\x82\xd0\xb0\xd0\xb2\xd0\xbb\xd0\xb5\xd0\xbd limit

Is there way to read with tailf error.log normally (with sed or something)?

Or how I can "tell" to apache do not encode utf symbols error.log?

After couple tries I found the solution.

echo -e -- to get utf insead of hex.

tailf ... | while read line; do command; done; -- to read output of tailf by line

read -r -- to avoid of convert escape sequence.

So, result is:

tailf /var/log/apache2/error.log | while read -r line; do echo -e "$line"; done;

I think you might need to use enca in your case, and if you don't know exactly what type of output encoding you have you might also use the options available in it such as -g, --guess you can have it from gitorious .

a simple description, and I'm paraphrasing here:

If you are lucky enough, the only two things you will ever need to know are: command

enca FILE

and to know what type of encoding your file uses you can try:

enconv FILE

obviously you will need to replace FILE with your error log. after that you can simply try something like:

tail -20f /path/to/your/file/error_log

to download your file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM