This course has been updated! We now recommend you take the Full Stack for Front-End Engineers, v2 course.

Check out a free preview of the full Full Stack for Front End Engineers course:
The "Log files" Lesson is part of the full, Full Stack for Front End Engineers course featured in this preview video. Here's what you'd learn in this lesson:

Jem sets up log files to track any potential errors Forever.

Get Unlimited Access Now

Transcript from the "Log files" Lesson

>> Jem Young: We're almost there. We've got a way to keep it up and running. We can play with our server. We can keep forever, we can build our goal task and keep our app up and running forever. But, let's put it all together into something useful. Yes, I almost forgot about this part.

[00:00:20] This is the most important part actually. We need a log file. We wanna log everything that happens cuz let's say forever keeps crashing. How would you know how and why it keeps crashing? Well we have to log it somewhere. Well first we need to change ownership of the log directory.

[00:00:36] So currently they're owned by sudo. So.
>> Jem Young: Sudo chown -R $USER shorthand, /var/log/forever. So I'm gonna go ahead and do those as well. That didn't show up.
>> Jem Young: First make that directory. I'm sorry, need to fix my animations. So, clear this out,
>> Jem Young: sudo -p mkdir.
>> Jem Young: Var/log.

[00:01:07] We'll just call this forever. Cool. Just Linux general tip. All of your log files are almost always going to be in /var/log. So you see here your nginx log is in here, your auth log's in here. You always want to put your logs in one place, and it's just much easier then trying to dig through your system like, where did I log that output to?

[00:01:33] Always put things in / log. So we made our log directory, so but we still need to change ownership cuz we have to sudo this every time and we don't want to do that when we're running forever scripts. So we can sudo chown -R $USER or your username doesn't matter.

[00:01:52] And we're just going to say /var/log/forever and we just changed ownership of that particular directory into the current user.
>> Jem Young: Excellent, everybody's looking good, a little tired. So we're there, that means we learned a lot today. So now, we're going to start forever but we're going to log the output into our log file.

[00:02:34] So, what do you call it, greater than greater than sign. What is that actually called? Is it called the greater than sign? I don't know, I'm gonna call it the greater than sign. So two of those will actually write to a file. So everything that forever start puts out, it's gonna write to this log file.

[00:02:54] So it's gonna write to forever.log. And because we changed the ownership of forever.log, we don't need to sudo any of this. So let's go ahead and do that. So, forever.
>> Jem Young: Start app and put the output to /var/log/forever. And we're just gonna call it forever.log.
>> Jem Young: And you don't see any output, why?

[00:03:24] Because it's writing to the log. So if I just cat that file, so cat /var/log/forever/forever we see all the output is going into that log file. This is extremely useful. Logging is how you solve things. Otherwise, you're just guessing. If you don't log it, you're literally just guessing about what's happening on your server.