Tutorials

Today I want to look at a new feature in PhpStorm, one that I think many Laravel developers will find very interesting. Now, to be clear, I’m a Developer Advocate at JetBrains, so you might think it’s obvious I’m excited about PhpStorm. Well, I wouldn’t be writing this post if I weren’t genuinely thrilled about it myself. First and foremost, I’m a PHP and Laravel developer, and I write code daily. So yes, I can say from experience: I’m really excited about this one!

So, let’s take a look at how the latest version of PhpStorm has improved logger support!

Improved log files

Until recently, log files in PhpStorm have been pretty… boring. They are huge blobs of text – that’s it:

AD 4nXcrhP FiIUx6mJUARaD1ATc9JGeF0mKmnvkWdhaI7dclXN5DIKdLAsOtDMvetH9QPmxb9vLih9ylbIjY Hpovwx0BG9rWN5jlWORE3TtilcsKvSqUMdjJ40q vmJsQBoP vSrrQlgdB4q8Dg7QZ3ajzC o?key=Kz3wGKkee EWeQvVyTm6pA

Now, I don’t know about you, but scrolling through those huge blobs becomes annoying pretty quickly – especially when you’re trying to debug production issues, which is probably the most common use case for reading a log file.

To streamline the experience of working with logs, the latest version of PhpStorm presents log files in a format that’s much easier to understand at a glance. They will now look something like this:

AD 4nXe4ot b62gyB6EuEhSdT JEq8quKBtmfAxSkcoi7daU7INqJ MOMHImuxm4kyLMuBSuZ0RjKQsyQx5fmHvgPnA MAHDgqBuflCMBQPwnYJ3AK q1IV3UeaIgJpRGDS7I4a3tu1amQqsZy7IPm6vwiD sJXd?key=Kz3wGKkee EWeQvVyTm6pA

You can see how the lines are color-coded, errors are highlighted in the scroll bar, and links are styled and clickable. On top of that, bigger log files no longer affect PhpStorm’s performance. A special new renderer for log files allows the IDE to highlight only the code that is visible at any given time, which drastically reduces the amount of memory and CPU needed. Naturally, when you scroll, any new lines that appear will be styled properly as well.

Speaking of scrolling, another use case for log files is to tail them in a terminal window. We’ve added the same styling on that output as well, which means that you can keep your log file open and any new lines will be automatically styled correctly:

AD 4nXeOwrFYm Rq7SvkjK6iyO1gPoQFs8QsNeAPyLb91WM0d5RSj3i5ofBhuM25D9QeoAtz2ulbKXFZ 1GPQW1DfXzb6glm3J aqThQzDVYZT1QBdYD212zdovp8n3UVQpdBW5Bbdg7yx2Wpq92nQX1JmQWSzE?key=Kz3wGKkee EWeQvVyTm6pA

Log files on remote servers

Another common use case is browsing production log files via SSH. Let’s take a look at how that works in PhpStorm. 

First you need to configure an SSH connection, which you can do by going to Settings | Tools | SSH Configurations.

AD 4nXfpHBvcJO6JiPvqYsXZYkuhmdo95HHWUSqOezdboPqaJphX2UINekqvwS I cpxe4KoNaFfM FEjhQxw7O91tfz8zggQiKBpDgFBvceRsHWpdLD VYteJRpBKidyL4N 6a6Cqwr469oECaH9b ciH2fAFZ3?key=Kz3wGKkee EWeQvVyTm6pA

Next, with the SSH configuration in place, you can start a new SSH session. Go to Tools | Deployment | Browse Remote Host and choose your newly created SSH configuration. 

AD 4nXeR2AKDESX6XOhRenjMWH5pbzZRuH7j82mijc1EJPLBxhxRFv 64CAqhWge6NSVmnr68O4MbnE6YswgbJQrAJY4DAg4y7e2F2yPAnnK9ewgB3vcb vdlxHnPUoU1eqseeqZrQlxNrXZ8HfwnTWvavmCN38J?key=Kz3wGKkee EWeQvVyTm6pA

PhpStorm will open a new tool window for browsing the remote server. You can navigate to the log file, open it, and… 

It looks just the same!

AD 4nXdqKYNL30d5aA Ft6Uudibdgrmh3q1Ajd3nm5Uv XUxckLgZPdb2XuIza6J7Ya337rI4DNwr1bzV yuKkZrM1O3yrB3ynmSD6SjPlVdWk8GMRsbnBg22VZOmBHvXx0J 51PNNq45wKiPyWOL7Tofcv2o7oP?key=Kz3wGKkee EWeQvVyTm6pA

Pretty neat, right?

Finally, let’s talk about settings. You can go to Settings | Editor | Log Highlighting to configure how log files should be styled. You can enable or disable the heatmap (the colored scroll bar), choose whether links are highlighted, patterns, filters, and configure log formats (we’ve got support for Laravel, Symfony, WordPress, and more).

AD 4nXel8MBgiOttdGiIh1kDNW7DJaK8itq 2km2GOI99Pvr7bfwWHsCP3DyysmoOSQi qY0bEGuVS Qd36xuwuu Pg7ExvOfFUYIVqmN7TzQQlEJUTscEh 2Upn1 EJGjbffDzXEgBTYOMz5XBzi9JUFYWWGpdo?key=Kz3wGKkee EWeQvVyTm6pA

The section that’s probably most interesting is the patterns table, where you can change the styling of highlighted log entries. For example, I don’t like errors being bold, so I can change the error pattern accordingly:

AD 4nXfLh42fATOLYzuZupeyPtnXwOVDtG2 16Qd6W2 yOjG1tMnoPaHG0olu9l6VrJsFn8Hua00HcUL5CUqYCIUg3c0XJ3zmwAbhL8KBjHHgmFgsda1kf01GiJ6l222OoiKFeoyYzwWimrHD4cpR2Z3Q2QYE Ma?key=Kz3wGKkee EWeQvVyTm6pA

On top of that, you can create your own patterns if you want to, which is pretty powerful if you want to create your own log highlighting rules, or if you’re reading a log file whose format isn’t supported out of the box.

In closing

The new support for log files is quite impressive if you ask me. Introduced in PhpStorm 2024.2, you can experience it now by starting a 30-day free trial or simply updating your IDE if you’re already a PhpStorm user.

image description

Share.
Leave A Reply