Adam Roszyk
Adam Roszyk

Reputation: 409

Change the log destination for node.js running on GCE

I am using rc.local to start my node script on start with:

node .> "/log_file_$(date +"%H:%M:%S_%m_%d_%Y").txt"

It works fine - but now once the log grows in size - I need to create a new log on a server every 12/24 hours; without restarting the server.

Is there any simple way to change the node app output destination?

I would prefer not to use any library for that, because I need to log all the messages including errors, warns, not only console.log.

Thanks for your help.

Upvotes: 1

Views: 43

Answers (1)

Travis Webb
Travis Webb

Reputation: 15018

There are a number of options, I'll offer two:

1. Stackdriver

Stream your logs to Stackdriver, which is part of Google Cloud, and don't store them on your server at all. In your node.js application, you can can setup Winston and use the Winston transport for Stackdriver. Then you can analyze and query them there, and don't need to worry about storage running out.

2. logrotate

If you want to deal with this manually, you can configure logrotate. It will gzip older logs so that they consume less disk space. This is a sort of older, "pre-cloud" way of doing things.

Upvotes: 3

Related Questions