تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Introducing ValetLog0:00

We'll get into this topic in greater detail in a later episode about troubleshooting Valet. But when something goes wrong with one of your dependencies, Laravel can only tell you so much. Thankfully, there's ValetLog, which makes it very easy to find and then also tail the logs of your various dependencies. Let's take a look. If you run ValetLog with no parameters, you'll see the default log files Valet can tail out of the box. There's only two options, nginx and phpfpm, but this particular feature is built with the intention that you're going to customize it, so don't even think that's all it's

Default logs explained0:29

There's only two options, nginx and phpfbm, but this particular feature is built with the intention that you're going to customize it, so don't even think that's all it's for. But I'm getting ahead of myself. Let's take a look at the log files it handles by default first. phpfbm is the version of php that nginx calls, versus the command line version that you're normally running when you type php, space, something on the command line. So this is for PHP logs that come from viewing your sites through Valet. nginx is the web server Valet uses to respond to traffic. If you're familiar with Apache, nginx is similar, but better.

Using log options0:56

nginx is the web server Valet uses to respond to traffic. If you're familiar with Apache, nginx is similar, but better. We run Valet log phpfbm, and we see the last 10 lines of that file, which if you've ever worked with tail before is going to seem really familiar. tail /user/local/var/log/phpfbm.log, you get the last 10 lines of that file. If you've ever worked with tail, you know there are a few parameters you can pass to customize how many lines you're seeing or to make it follow. So let's take a look at help for log. We can see we have two primary parameters here, follow and numberOfLines, which is going to seem very familiar if you work with tail before.

We can see we have two primary parameters here, follow and number of lines, which is going to seem very familiar if you work with tail before. So let's try ValetLog php fm lines 3, lines 30. So as you can see, this first parameter allows you to define how many lines you're actually going to show. What I think is more interesting, however, is the follow parameter. You can see that if we pass -f, it will actually follow along with the file. And what follow means is that if any changes are made to that file, we will see them in line. Let's clear it up.

Following logs live2:01

line. Let's clear it up. Let's say ValetLog phpfbm. Now let's do a -f. And notice we have those same lines, but it's not closed. So let's open up a new tab here. Remember what was the file name php, oh, /usr/local/var/log/phpfbm.log. So let's just echo extra line and add it to the end of that file /usr/local/var/log/phpfbm.log. And notice when we add that extra line, it automatically shows up over here. So that's what following does.

And notice when we add that extra line, it automatically shows up over here. So that's what following does. following allows you to say when anything happens here, don't make me go run it again. Just add it there. So every single time we had extra line, it's going to show up over there. As always, to get out of that, you can just hit control C. So just to be totally clear, ValetLog is doing very similar work to what tail does. And so if you were interested, you could just remember those two paths all the time, and you wouldn't even need ValetLog at all. But what ValetLog does for you is it creates two easy shortcuts or keys to get these logs

Adding custom logs3:06

you wouldn't even need ValetLog at all. But what ValetLog does for you is it creates two easy shortcuts or keys to get these logs quickly without having to memorize where they are. And that's a perfect transition for us to talk about how to add custom log files. Now, if you're not familiar, Laravel's default mailer in the .env of any new app is called MailPip. But Valet doesn't actually ship with MailPip, so it's not in the default log file. However, installing MailPip is super easy. Just brew install MailPip. Once you do that, and then run brew services start MailPip, you're going to have a mail

Just brew install MailPip. Once you do that, and then run brew services start MailPip, you're going to have a mail server running at all times that's accessible at 0.0.0.0:1025 for your mail, which means your .env just needs to say MAIL_HOST=0.0.0.0 and MAIL_PORT=1025, and all your mail will instantly be sent over to MailPip. And if you want to take a look at the mail you received, you can go to 0.0.0.0:8025, and you'll see the really nice user interface for MailPip that looks like a nice little mailer, and you can click through your mail, just like MailHog or MailTrap or any of those other mail capture services. This is not about MailPip.

of those other mail capture services. This is not about MailPip. I just wanted you to see that this is something that's super easy for you to install. But how do you get access to MailPip's logs? Well, the good news is because we installed this one over brew, if you say valet log, you can see these other homebrew services, and you may not be able to see this because these two are different, but usually they're going to end up in here, /usr/local/var/log or /opt/homebrew/var/log if you're on a more modern machine. So if we take a look at /usr/local/var/log and just see, is there anything that starts with MailPip?

So if we take a look at user local var log and just see, is there anything that starts with MailPip? Well, there you go. Autocomplete MailPip.log. So if we were to look at that file, it's yet another log, which would be helpful for us to potentially follow in certain contexts. So wouldn't it be nice to add it to our valet log list? Let's do it. So open up our valet config file, we're going to add a new key called logs. Its value should be an object, and the left side, so the key of every single one of these

So open up our valet config file, we're going to add a new key called logs. Its value should be an object, and the left side, so the key of every single one of these entries should be the short name, so we'll call it MailPip. And the longer side, so the value, should be the path of the file. We quit that out, and now when we run valet log, we can see that MailPip has been added there. So let's now try valet log MailPip, and there we go, able to follow it, able to get a certain number of lines, whatever else we need. So the idea here is that you find all the logs that are important, helpful, useful to you, put them all in that configuration item, and then every time you say, you know what,

Recap and workflow5:44

So the idea here is that you find all the logs that are important, helpful, useful to you, put them all in that configuration item, and then every time you say, you know what, I got to go look at my Redis log again, or I got to go look at my logs for one important Laravel app, even if you want. Whatever it is, you put it into the logs entry in your config file, and now you can run valet log, which doesn't just make it easy to run tail on it, it makes it easy for you to remember that path and be able to access it with a nice little shortcut, MailPip instead of /user/local/var/log/MailPip.log. So that's it, valet log, a convenient tool on top of tail that makes it really easy to add shortcuts to common paths to your logs.

So that's it, valet log, a convenient tool on top of tail that makes it really easy to add shortcuts to common paths to your logs.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟