Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fluent-logger

Package Overview
Dependencies
Maintainers
4
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fluent-logger - npm Package Compare versions

Comparing version 0.5.0 to 1.0.0

9

lib/index.js

@@ -10,6 +10,9 @@ 'use strict';

sender = new FluentSender(tag, options);
sender._setupErrorHandler();
},
createFluentSender: function(tag, options){
return new FluentSender(tag, options);
var _sender = new FluentSender(tag, options);
_sender._setupErrorHandler();
return _sender;
},

@@ -20,3 +23,5 @@

var log4jsSupport = require('../lib/log4js');
return log4jsSupport.appender(tag, options);
var appender = log4jsSupport.appender(tag, options);
appender._setupErrorHandler();
return appender;
}

@@ -23,0 +28,0 @@ }

@@ -32,5 +32,9 @@ 'use strict';

};
logSender.emit(loggingEvent.level.levelStr, rec);
if (options.levelTag !== false) {
logSender.emit(loggingEvent.level.levelStr, rec);
} else {
logSender.emit(rec);
}
};
['addListener', 'on', 'once', 'removeListener', 'removeAllListeners', 'setMaxListeners', 'getMaxListeners'].forEach(function(attr, i){
['addListener', 'on', 'once', 'removeListener', 'removeAllListeners', 'setMaxListeners', 'getMaxListeners', '_setupErrorHandler'].forEach(function(attr, i){
appender[attr] = function(){

@@ -37,0 +41,0 @@ return logSender[attr].apply(logSender, Array.prototype.slice.call(arguments));

@@ -13,3 +13,5 @@ 'use strict';

this.port = options.port || 24224;
this.path = options.path;
this.timeout = options.timeout || 3.0;
this.reconnectInterval = options.reconnectInterval || 600000; // Default is 10 minutes
this.verbose = this.verbose || false;

@@ -111,5 +113,11 @@ this._timeResolution = options.milliseconds ? 1 : 1000;

});
self._socket.connect(self.port, self.host, function(){
callback();
});
if (self.path) {
self._socket.connect(self.path, function() {
callback();
});
} else {
self._socket.connect(self.port, self.host, function() {
callback();
});
}
}else{

@@ -152,4 +160,21 @@ if( !self._socket.writable ){

FluentSender.prototype._setupErrorHandler = function() {
var self = this;
if (!self.reconnectInterval) {
return;
}
self.on('error', function(error) {
console.error('Fluentd error', error);
console.info('Fluentd will reconnect after ' + self.reconnectInterval / 1000 + ' seconds');
setTimeout(function() {
console.info("Fluentd is reconnecting...");
self._connect(function() {
console.info('Fluentd reconnection finished!!');
});
}, self.reconnectInterval);
});
};
module.exports = exports = {};
exports.FluentSender = FluentSender;
{
"name": "fluent-logger",
"version": "0.5.0",
"version": "1.0.0",
"main": "./lib/index.js",

@@ -5,0 +5,0 @@ "scripts": {

@@ -26,3 +26,4 @@ # fluent-logger for Node.js

port: 24224,
timeout: 3.0
timeout: 3.0,
reconnectInterval: 600000 // 10 minutes
});

@@ -38,3 +39,4 @@

port: 24224,
timeout: 3.0
timeout: 3.0,
reconnectInterval: 600000 // 10 minutes
});

@@ -67,2 +69,17 @@

You can add log level after tag automatically.
var log4js = require('log4js');
log4js.addAppender(require('fluent-logger').support.log4jsAppender('mytag', {
host: 'localhost',
port: 24224,
timeout: 3.0,
levelTag: true
}));
var logger = log4js.getLogger('foo');
logger.info('this log record is sent to fluent daemon');
If `levelTag` is `true`, tag is "mytag.INFO". If `levelTag` is `false`, tag is "mytag".
You can handle inner events such as 'error' it is raised when fluentd

@@ -83,2 +100,46 @@ is down.

## Options
**tag**
The tag string.
**host**
The hostname. Default value = 'localhost'.
See [socket.connect][1]
**port**
The port to listen to. Default value = 24224.
See [socket.connect][1]
**path**
The path to your Unix Domain Socket.
If you set `path` then fluent-logger ignores `host` and `port`.
See [socket.connect][1]
**timeout**
Set the socket to timetout after `timeout` milliseconds of inactivity
on the socket.
See [socket.setTimeout][2]
**reconnectInterval**
Set the reconnect interval in milliseconds.
If error occurs then reconnect after this interval.
**verbose**
If set `true`, verbose output.
[1]: https://nodejs.org/api/net.html#net_socket_connect_path_connectlistener
[2]: https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback
## License

@@ -85,0 +146,0 @@

@@ -44,2 +44,23 @@ var expect = require('chai').expect;

it('should not add levelTag', function(done){
runServer(function(server, finish){
var appender = log4jsSupport.appender('debug', {port: server.port, levelTag:false});
log4js.addAppender(appender);
var logger = log4js.getLogger('mycategory');
logger.info('foo %s', 'bar');
setTimeout(function(){
finish(function(data){
expect(data[0].tag).to.be.equal('debug');
expect(data[0].data).exist;
expect(data[0].data.data).to.be.equal('foo bar');
expect(data[0].data.category).to.be.equal('mycategory');
expect(data[0].data.timestamp).exist;
expect(data[0].data.levelInt).exist;
expect(data[0].data.levelStr).to.be.equal('INFO');
done();
});
}, 1000);
});
});
it('should not crash when fluentd is not running', function(done){

@@ -93,3 +114,11 @@ runServer(function(server, finish){

});
it('should set error handler', function(done) {
var appender = log4jsSupport.appender('debug');
expect(appender._eventEmitter.listeners('error').length).to.be.equal(0);
appender._setupErrorHandler();
expect(appender._eventEmitter.listeners('error').length).to.be.equal(1);
done();
});
});
});

@@ -145,2 +145,12 @@ var expect = require('chai').expect;

it('should set error handler', function(done){
var s = new sender.FluentSender('debug', {
reconnectInterval: 100
});
expect(s._eventEmitter.listeners('error').length).to.be.equal(0);
s._setupErrorHandler();
expect(s._eventEmitter.listeners('error').length).to.be.equal(1);
done();
});
[

@@ -147,0 +157,0 @@ {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc