Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 662
sectus Avatar asked Oct 31 '13 02:10

sectus


People also ask

How do I find the Apache error log?

On a Linux server, you can access Apache error logs from var/log/apache2/error. log. You can then log out the errors from the error log file by writing the following command: sudo tail -f /var/log/apache2/error.

Where is the Apache error log may have more information?

Apache errors can be found in this directory /usr/local/apache/logs/error_log. All the Apache errors are logged in the error_log.

What is the difference between Apache's access log and the error log?

Basically, the difference is in the names. Access logs is everything, so everyone, every time somebody or something has accessed the website. Error logs just record the same information but only for error pages.

Where is Apache error log Ubuntu?

If you are troubleshooting a Debian or Ubuntu derived system, examine /var/log/apache2/error. log for errors using a tool like tail or less . For example, to view the last two lines of the error log using tail , run the following command: sudo tail -n 2 /var/log/apache2/error.


2 Answers

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;
like image 120
sectus Avatar answered Oct 09 '22 17:10

sectus


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.

like image 45
mamdouh alramadan Avatar answered Oct 09 '22 17:10

mamdouh alramadan