async-logging
Advanced tools
Comparing version 0.1.20 to 0.1.21
@@ -27,11 +27,19 @@ 'use strict'; | ||
wss = options.websocket ? new WebSocketServer({ | ||
httpServer: server, | ||
// You should not use autoAcceptConnections for production | ||
// applications, as it defeats all standard cross-origin protection | ||
// facilities built into the protocol and the browser. You should | ||
// *always* verify the connection's origin and decide whether or not | ||
// to accept it. | ||
maxReceivedMessageSize: 4 * 1024 * 1024,//4mb for the max message size | ||
autoAcceptConnections: false | ||
}) : null, | ||
httpServer: server, | ||
// You should not use autoAcceptConnections for production | ||
// applications, as it defeats all standard cross-origin protection | ||
// facilities built into the protocol and the browser. You should | ||
// *always* verify the connection's origin and decide whether or not | ||
// to accept it. | ||
maxReceivedMessageSize: 4 * 1024 * 1024,//4mb for the max message size | ||
autoAcceptConnections: false | ||
}) | ||
:{ | ||
'on': function(){ | ||
}, | ||
'shutDown': function(){ | ||
} | ||
}, | ||
actualOptions = { | ||
@@ -83,3 +91,3 @@ 'port': 3000, | ||
_.isFunction(actualOptions.LogBuffer) ? actualOptions.LogBuffer(emitter) : actualOptions.LogBuffer; | ||
_.isFunction(actualOptions.LogPublisher) ? actualOptions.LogPublisher(emitter) : actualOptions.LogPublisher; | ||
_.isFunction(actualOptions.LogPublisher) ? actualOptions.LogPublisher(emitter, actualOptions) : actualOptions.LogPublisher; | ||
@@ -86,0 +94,0 @@ //a cleanup logic that is added to avoid logs never closed taking too much memory, threshold set to one day for now |
@@ -5,12 +5,14 @@ 'use strict'; | ||
var WinstonPublisher = exports.WinstonPublisher = function(emitter){ | ||
var WinstonPublisher = exports.WinstonPublisher = function(emitter, options){ | ||
//a specific publisher, could be as simple as log file appender | ||
options = options || {}; | ||
var logger = new (winston.Logger)({ | ||
transports: [ | ||
new winston.transports.File({ filename: './log/all.log' }) | ||
], | ||
exceptionHandlers: [ | ||
new winston.transports.File({ filename: './log/exceptions.log' }) | ||
] | ||
transports: options.transports || [ | ||
new winston.transports.File({ filename: './log/all.log' }) | ||
], | ||
exceptionHandlers: options.exceptionHandlers || [ | ||
new winston.transports.File({ filename: './log/exceptions.log' }) | ||
] | ||
}); | ||
@@ -23,8 +25,8 @@ | ||
emitter.on('heartbeat', function(heartbeat){ | ||
logger.log(atomicEvent.level, heartbeat.msg, heartbeat); | ||
logger.log(heartbeat.level, heartbeat.msg, heartbeat); | ||
}); | ||
emitter.on('transaction', function(tx){ | ||
logger.log(atomicEvent.level, tx.msg, tx); | ||
logger.log(tx.level, tx.msg, tx); | ||
}); | ||
}; |
@@ -41,3 +41,3 @@ 'use strict'; | ||
console.log('[transport] using websocket:' + body); | ||
//console.log('[transport] using websocket:' + body); | ||
_this.transport = new WebSocketTransport({ | ||
@@ -53,3 +53,3 @@ 'url': body, | ||
console.log('[transport] using http:' + url); | ||
//console.log('[transport] using http:' + url); | ||
_this.transport = new HttpTransport({ | ||
@@ -56,0 +56,0 @@ 'url':url, |
@@ -110,4 +110,4 @@ 'use strict'; | ||
catch(e){ | ||
console.log(e); | ||
console.trace(e); | ||
} | ||
}; |
{ | ||
"author": "cubejs", | ||
"name": "async-logging", | ||
"version": "0.1.20", | ||
"version": "0.1.21", | ||
"description": "0.1.6 is the same as 0.2.2 just to get around ebay-logging-client vs. async-logging-client change", | ||
@@ -30,4 +30,5 @@ "repository": { | ||
"scripts":{ | ||
"start":"node ./lib/log-server.js" | ||
"start":"node ./lib/log-server.js", | ||
"test": "mocha --ui bdd --timeout 10s --reporter spec ./test/*-test.js" | ||
} | ||
} |
@@ -1,33 +0,64 @@ | ||
## What is async-logging | ||
async-logging-node | ||
================== | ||
This module is trying to solve the discrepency between the async model & the common synchronous logging model | ||
This module is trying to solve the discrepancy between the async model & the common synchronous logging model | ||
* Logging types: heartbeat, atomic, transaction | ||
* Logging params: type, level, msg, uuid, event, parent | ||
* Transaction: this is the key structure we're trying to restore from async events model | ||
* Logging proxy: part of this module is trying to build a proxy service running websocket server accepting log payload as message pack | ||
* Logging client: the other part is a client which runs in the application runtime, connecting to websocket, transfer the log event over | ||
* **Logging types**: heartbeat, atomic, transaction | ||
* **Logging params**: type, level, msg, uuid, event, parent | ||
* **Transaction**: this is the key structure we're trying to restore from async events model | ||
* **Logging proxy**: part of this module builds a proxy service which is a websocket server accepting log payload as message pack | ||
* **Logging client**: the other part is a client which runs in the application runtime, connecting to websocket, and transferring the log event over | ||
* **MonApp**: optional monitoring app which can generate heartbeat logs | ||
## API | ||
|Function | Description | | ||
|---|---| | ||
|**LogCluster**| | ||
|`require('log-cluster').LogCluster`|importing constructor| | ||
|`new LogCluster(options, emitter)`|constructor accepts two parameters; | | ||
|**LogBuffer**| | ||
|`require('log-buffer').LogBuffer`|importing constructor| | ||
|`new LogBuffer(emitter,mapper)`|constructor accepts two parameters, emitter which emits 'log' events and optional mapper which can map log properties to correct format| | ||
|**LogListener**| | ||
|require('log-listener').LogListener|importing constructor| | ||
## Installation | ||
``` | ||
npm install async-logging | ||
``` | ||
## Usage | ||
### Getting async-logging | ||
npm install async-logging | ||
### Start a proxy service | ||
var LogCluster = require("log-cluster.js").LogCluster, | ||
``` | ||
var LogCluster = require("log-cluster.js").LogCluster, | ||
CalPublisher = require("cal-publisher.js").CalPublisher; | ||
new LogCluster({LogPublisher:CalPublisher}); | ||
new LogCluster({LogPublisher:CalPublisher}); | ||
``` | ||
### Provide a Log Publisher | ||
var CalPublisher = exports.CalPublisher = function(emitter, calMapper, calSender, calCallback){ | ||
//a specific publisher, could be as simple as log file appender | ||
} | ||
``` | ||
var CalPublisher = exports.CalPublisher = function(emitter, calMapper, calSender, calCallback){ | ||
//a specific publisher, could be as simple as log file appender | ||
} | ||
``` | ||
### Start a client | ||
new require("log-client").LogClient({url:""}); //url must be given | ||
## Example | ||
Look at lib/log-server.js. You can start it by typing following commands from the root of the project | ||
``` | ||
npm install | ||
node lib/log-server.js | ||
``` | ||
## LogCluster constructor options | ||
* `port`: port on which the cluster will run(default 3000) | ||
* `monPort`: port of the monitoring app if any(default 3001) | ||
* `cluster`: (default true) | ||
* `noWorders` number of worker processes to create: | ||
* `connThreshold`: max number of connections to accept(default 1024) | ||
* `ecv`: | ||
* `heartbeatInterval`: | ||
* `LogListener`: defaults to 'log-listen.js' | ||
* `LogBuffer`: defaults to 'log-buffer.js' | ||
* `LogPublisher`: defautls to 'winston-publisher.js' |
35841
21
746
65