Logging in node.js to a file, without another module
I'm running a node application as a daemon. When debugging the daemon, I
need to see the output, so I'd like to redirect stdout and stderr to a
file.
I'd expect I can just reassign stdout and stderr like in Python or C:
fs = require('fs');
process.stdout = fs.openSync('/var/log/foo', 'w');
process.stderr = process.stdout;
console.log('hello');
When I run the script directly, "hello" is printed to the console! Of
course when I run in the background, I see output neither on the console
(of course) or in /var/log/foo.
I don't want or need sophisticated logging. I just need to see the builtin
messages that node already provides.
No comments:
Post a Comment