0
votes

I have a pm2 node.js process running. Everything is good, console logs and errors display very well in the terminal.

But as soon as I open logs file with vim or nano rather than view them with pm2 logs, I get a mess !

It looks like that :

01/07/2021 09:10:19 GMT+00:00: ^[[0mPOST /auth/refresh ^[[33m404^[[0m 4.601 ms - 74^[[0m
01/07/2021 09:10:20 GMT+00:00: ^[[0mPOST /auth/refresh ^[[33m404^[[0m 0.868 ms - 
01/07/2021 09:10:28 GMT+00:00: ^[[0mPOST /auth/ ^[[32m200^[[0m 163.059 ms - 677^[[0m
01/07/2021 09:10:28 GMT+00:00: ^[[0mGET /messages/info/by-role/3 ^[[32m200^[[0m 8.993 ms - 586^[[0m
01/07/2021 09:10:28 GMT+00:00: ^[[0mGET /exchanges/lasts/9?limit=5 ^[[32m200^[[0m 10.884 ms - 484^[[0m

I do think it's because of colors. They are only well interpreted by the terminal but are weirdly stored. One of the solution could be to remove those colors but I was wondering if there is a way to just display them nicely in vim, nano or another text editor.

1
There is nothing weird, those are ANSI color codes embedded in the file. vim cannot display them as colors. Try less -Rphd
It work perfectly ! Thanks ! Can you add an answer so that I can accept it as the solution ?Mathis

1 Answers

0
votes

There is nothing weird, those escape codes are ANSI color codes embedded in the file.

vim cannot display them as colors and I don't know any plugin to convert them to vim colors. Either remove them or use a different program.

Try less -R.