me_astr
me_astr

Reputation: 1042

How to handle node logs file on my server?

I am new to node and ubuntu and currently developing a node application. My logs are being generated at /var/log/appname/debug.log.

Whenever log file becomes very big, I just clear the logs(currently it is in testing phase), but the problem is whenever I do this I have to restart my node server to start logging again in my debug.log file.

Can you please tell me the reason for this(I am using non root user to log and clear) ?

How to handle log files in production ? I just read about cron job(logrotate) in linux, Can you please guide me how to handle my logs through cron job ?

Upvotes: 0

Views: 165

Answers (1)

Jeff Kilbride
Jeff Kilbride

Reputation: 2814

If you don't care about the contents of the log file and just wish to delete it without restarting your server, you can cat /dev/null > debug.log. This will zero the contents. If you care about saving the contents of the log file, read the logrotate manual by typing man logrotate from the command line. If you want to learn about using cron jobs, read the crontab manual by typing man 5 crontab. Or you can search the web for documentation and examples of either of those tools.

Upvotes: 1

Related Questions