Skip to content

Commit

Permalink
Merge pull request fluent#47 from sveneh/master
Browse files Browse the repository at this point in the history
fixed timestamp format according to fluent in_forward module
  • Loading branch information
okkez committed May 9, 2016
2 parents c60b04f + 04b147b commit 07b03a2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Simple configuration is following:
Singleton style

var logger = require('fluent-logger')
// The 2nd argument can be omitted. Here is a defualt value for options.
// The 2nd argument can be omitted. Here is a default value for options.
logger.configure('tag', {
host: 'localhost',
port: 24224,
Expand Down Expand Up @@ -144,10 +144,6 @@ See [socket.setTimeout][2]
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

Expand Down
3 changes: 1 addition & 2 deletions lib/sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function FluentSender(tag, options){
this.path = options.path;
this.timeout = options.timeout || 3.0;
this.reconnectInterval = options.reconnectInterval || 600000; // Default is 10 minutes
this.verbose = this.verbose || false;
this._timeResolution = options.milliseconds ? 1 : 1000;
this._socket = null;
this._sendQueue = []; // queue for items waiting for being sent.
Expand Down Expand Up @@ -83,7 +82,7 @@ FluentSender.prototype._makePacketItem = function(label, data, time){
var tag = label ? [self.tag, label].join('.') : self.tag;

if (typeof time != "number") {
time = (time ? time.getTime() : Date.now()) / this._timeResolution;
time = Math.floor((time ? time.getTime() : Date.now()) / this._timeResolution);
}

var packet = [tag, time, data];
Expand Down
9 changes: 5 additions & 4 deletions test/test.sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ describe("FluentSender", function(){
it('should allow to emit with a custom timestamp', function(done){
runServer(function(server, finish){
var s = new sender.FluentSender('debug', {port: server.port});
var timestamp = new Date();
var timestamp = new Date(2222, 12, 04);
var timestamp_seconds_since_epoch = Math.floor(timestamp.getTime() / 1000);

s.emit("1st record", "1st data", timestamp, function() {
finish(function(data) {
expect(data[0].time).to.be.equal(timestamp.getTime() / 1000);
expect(data[0].time).to.be.equal(timestamp_seconds_since_epoch);
done();
});
});
Expand All @@ -78,7 +79,7 @@ describe("FluentSender", function(){
it('should allow to emit with a custom numeric timestamp', function(done){
runServer(function(server, finish){
var s = new sender.FluentSender('debug', {port: server.port});
var timestamp = new Date().getTime() / 1000;
var timestamp = Math.floor(new Date().getTime() / 1000);

s.emit("1st record", "1st data", timestamp, function() {
finish(function(data) {
Expand Down Expand Up @@ -235,7 +236,7 @@ describe("FluentSender", function(){
expect: {
tag: 'debug',
data: { bar: 1 },
time: 1384434467.952
time: 1384434467
}
}
].forEach(function(testCase) {
Expand Down

0 comments on commit 07b03a2

Please sign in to comment.