backend, Locastic Apr 01

A quick way to browse Symfony Logs with PHPStorm

1 min read –

Recently, I had to browse some logs to debug a flow, and it started to get a bit tiring, looking for those keywords. Of course, there is the search shortcut Ctrl + F but when you want a bit more than that, or just something faster, PHPStorm comes in to help.

Log Format

PHPStorm comes with a few log formats already configured, but also allows you to define a new one. To do so, go into Settings -> Editor -> Log Highlighting (Ideolog) (you can also hit double shift and type Log formats.
There, you will be able to add a new Log format. Let’s name it Symfony, and give it the following config:

Name: Symfony
Message Pattern: ^\[(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2})\]\s+(\w+).(\w+):\s+(.*)$
Message start pattern: ^\[
Time format: yyyy-MM-dd HH:mm:ss
Time capture group: 1
Severity capture group: 3
Category capture group: 2

You should also add a Pattern for the messages which is: ^\s*c(ritical)?\s*$ and perhaps apply red colour to it.

Enjoy your logs!

That’s it – from now on, you will enjoy some colourful logfile, making your debug process way easier!

I have to point out, the idea was inspired by Github user dszczer in this cheat sheet, so huge thanks for his work and contribution.