Skip to content

Instantly share code, notes, and snippets.

@chilts
Created January 16, 2012 20:58
Show Gist options
  • Save chilts/1623039 to your computer and use it in GitHub Desktop.
Save chilts/1623039 to your computer and use it in GitHub Desktop.
The application itself
node_modules
*.log
*~

Test the 'forever' Logs

Sometimes the logs aren't written out to disk. This may be a sync problem somewhere, but I'd have thought forever would flush these logs when it has been asked to stop.

Test

Firstly, install forever:

npm -d install

Now, run the test script:

./test.sh

From what I see, I get one of the three following situations:

-rw-r--r-- 1 chilts chilts 0 2012-01-17 10:40 logs/access.log
-rw-r--r-- 1 chilts chilts 0 2012-01-17 10:40 logs/error.log
-rw-r--r-- 1 chilts chilts 0 2012-01-17 10:40 logs/forever.log

-rw-r--r-- 1 chilts chilts 41 2012-01-17 10:40 logs/access.log
-rw-r--r-- 1 chilts chilts  0 2012-01-17 10:40 logs/error.log
-rw-r--r-- 1 chilts chilts 41 2012-01-17 10:40 logs/forever.log

-rw-r--r-- 1 chilts chilts 41 2012-01-17 10:40 logs/access.log
-rw-r--r-- 1 chilts chilts  0 2012-01-17 10:40 logs/error.log
-rw-r--r-- 1 chilts chilts 94 2012-01-17 10:40 logs/forever.log

I'd expect all log files to always be 41 (access.log) or 64 (forever.log).

100 times

If you run the script 100 times and just watch the output, sometimes the size of the forever.log is changes (in some cases it's 53):

for I in `seq 1 100`; do
    ./test.sh
done

(Ends)

var http = require('http');
http.createServer(function (req, res) {
console.log('' + (new Date()).toISOString() + ' - GET');
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
{
"name" : "test-logs",
"version" : "0.1.0",
"dependencies" : {
"forever" : ">= 0.8.4"
}
}
#!/bin/bash
# remove old logs first
rm -f logs/{forever,access,error}.log
# start the server
PWD=`pwd`
./node_modules/.bin/forever \
-l $PWD/logs/forever.log \
-o logs/access.log \
-e logs/error.log \
start app.js
# add something to the access file
curl -s localhost:1337
# stop the app
./node_modules/.bin/forever stop app.js
# view the logfile sizes
ls -l logs/{forever,access,error}.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment