dreamerslab/coke — pull request #31 by rayshih (2014-09-03 02:31:54+00:00)
Title: Refactor logger system

Give developer option to use other logger system.
By implementing a log adapter, developer can easily use other log framework.

Here is an example of a bunyan log adapter
``` js
var bunyan = require('bunyan');
var log = bunyan.createLogger({
name: 'popapp',
streams: [{
type: 'raw',
stream: require( 'bunyan-logstash-tcp' ).createStream({
host: '192.168.59.103', // '127.0.0.1',
port: 5505
})
}]
});

var rename_time = function ( data ){
if( data.time ){
data.timer = data.time;
delete data.time;
}
};

module.exports = {
sys : function ( data ){
var msg = data.msg || '';
data.type = 'SYSTEM';
log.info( data, msg );
},

request : function ( data ){
var msg = data.msg || '';
data.type = 'REQUEST';
log.info( data, msg );
},

response : function ( data ){
var msg = data.msg || '';
data.type = 'RESPONSE';
rename_time( data );
log.info( data, msg );
},

error : function ( data ){
var msg = data.msg || '';
data.type = 'ERROR';
rename_time( data );
log.error( data, msg );
},

debug : function ( data ){
var msg = data.msg || '';
data.type = 'DEBUG';
rename_time( data );
log.debug( data, msg );
},

raw : log
};
```