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

I have a code that may be a mistake with a Russian-language message.

For instance:

  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 a way to read with tailf error.log normally (using sed or something else)?

Or how can I tell apache not to encode utf error.log characters?

+6
source share
2 answers

After a couple of attempts, I found a solution.

echo -e - to get utf insead from hex.

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

read -r - to avoid escape sequence conversion.

So the result is:

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

I think you may need enca in your case, and if you do not know exactly what type of output encoding you could also use the options available in it, such as -g, --guess you can get it from gitorious .

simple description, and I rephrase here:

If you're lucky, you only need two things: command

 enca FILE 

and find out 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 just try something like:

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

to download the file.

+1
source

Source: https://habr.com/ru/post/957090/


All Articles