Wednesday 7 June 2017

How to use buyan to monitor a nodeJS server?

Hi really really big nodeJS / bunyan noob here, and in need of direction. I used the following code to create a nodeJS server on my localhost,

var http = require('http'),
    fs = require('fs');

//index.html is just a blank html with $.get request that alerts me if it works

fs.readFile('index.html', function (err, html) {
    if (err) {
        throw err; 
    }       
    http.createServer(function(request, response) {  
        response.writeHeader(200, {"Content-Type": "text/html"});  
        response.write(html);  
        response.end();  

    }).listen(118);
});

and the following code for bunyan

var bunyan = require('bunyan');

var log = bunyan.createLogger({ 
                name: 'myLog',
                streams: [
                    {
                        level: 'trace',
                        stream: process.stdout
                    },
                    {
                        level: 'trace',
                        path: './stuffhappening.log'
                    }
                ]
            });

log.info('myLog');

I want to be able to log runtime errors on my node server (port 118) on my localhost, and also see anything that happens on it so I can find out the flow and timing of calls and stuff.

How do I go about achieving that?



via Ray Lu

No comments:

Post a Comment