Skip to content

Commit

Permalink
version 0.0.6
Browse files Browse the repository at this point in the history
Merge branch 'development'
  • Loading branch information
Craig Thayer committed Jul 2, 2015
2 parents 50071db + 44243b3 commit e5da5dc
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
language: node_js
node_js:
- "0.10"
- "0.8"
- "0.8"
before_install:
- '[ "${TRAVIS_NODE_VERSION}" != "0.8" ] || npm install -g npm@~1.4.6'
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ Run Tests
npm test
```

Troubleshooting
====================

* **I get an error when installing node packages *"ERR! Error: No compatible version found: assertion-error@'^1.0.1'"***

If you are running a version of NodeJS less than or equal to 0.8, upgrading NPM to a version greater than or equal to 1.4.6 should solve this issue.

```
npm install -g npm@~1.4.6
```

Another way around is to simply avoid installing the development dependencies:

```
npm install --production
```

====================

#### Author: [Craig Thayer](https://github.com/sazze)
Expand Down
9 changes: 8 additions & 1 deletion lib/winston-logstash-udp.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var LogstashUDP = exports.LogstashUDP = function(options) {
this.port = options.port || 9999;
this.application = options.appName || process.title;
this.pid = options.pid || process.pid;
this.trailingLineFeed = options.trailingLineFeed === true;
this.trailingLineFeedChar = options.trailingLineFeedChar || os.EOL;

this.client = null;

Expand Down Expand Up @@ -79,9 +81,14 @@ LogstashUDP.prototype.log = function(level, msg, meta, callback) {

LogstashUDP.prototype.sendLog = function(message, callback) {
var self = this;

if (this.trailingLineFeed === true) {
message = message.replace(/\s+$/, '') + this.trailingLineFeedChar;
}

var buf = new Buffer(message);

callback = (callback || function() {});

self.client.send(buf, 0, buf.length, self.port, self.host, callback);
};
};
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "winston-logstash-udp",
"version": "0.0.5",
"version": "0.0.6",
"description": "A Logstash UDP transport for winston",
"main": "./lib/winston-logstash-udp",
"homepage": "https://github.com/sazze/winston-logstash-udp",
"scripts": {
"test": "mocha test/*_test.js"
},
"engines": {
"node": ">=0.8.x"
"node": ">=0.8.x",
"npm" : ">=1.4.6"
},
"repository": {
"type": "git",
Expand All @@ -21,7 +22,8 @@
"winston": ">=0.7.2",
"mocha": ">=1.8.2",
"chai": ">=1.5.0",
"timekeeper": ">=0.0.3"
"timekeeper": ">=0.0.3",
"sinon-chai": "~2.8.0"
},
"keywords": [
"logging",
Expand All @@ -47,6 +49,10 @@
{
"name": "devAsterisk",
"email": "[email protected]"
},
{
"name": "Anis Safine",
"email": "[email protected]"
}
],
"maintainers": [
Expand All @@ -55,4 +61,4 @@
"email": "[email protected]"
}
]
}
}
71 changes: 63 additions & 8 deletions test/winston-logstash-udp_test.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
process.env.NODE_ENV = 'test';

var chai = require('chai'),
sinon = require('sinon'),
sinonChai = require('sinon-chai'),
expect = chai.expect,
dgram = require('dgram'),
winston = require('winston'),
timekeeper = require('timekeeper'),
os = require('os'),
common = require('winston/lib/winston/common'),
freezed_time = new Date(1330688329321);

chai.Assertion.includeStack = true;
chai.should();
chai.use(sinonChai);

require('../lib/winston-logstash-udp');

Expand Down Expand Up @@ -35,15 +41,25 @@ describe('winston-logstash-udp transport', function () {
return server;
}

function createLogger(port) {
function createLogger(port, options) {
var defaultOptions = {
port: port,
appName: 'test',
localhost: 'localhost',
pid: 12345
},
options = options || {},
field;

for (field in defaultOptions) {
if (defaultOptions.hasOwnProperty(field) && !options.hasOwnProperty(field)) {
options[field] = defaultOptions[field];
}
}

return new (winston.Logger)({
transports: [
new (winston.transports.LogstashUDP)({
port: port,
appName: 'test',
localhost: 'localhost',
pid: 12345
})
new (winston.transports.LogstashUDP)(options)
]
});
}
Expand All @@ -70,6 +86,45 @@ describe('winston-logstash-udp transport', function () {
logger.log('info', 'hello world', {stream: 'sample'});
});

describe('with the option \'trailing line-feed\' on', function () {
it('remove all trailing blank characters and replace them with the operating system\'s EOL character', function (done) {
var logger = createLogger(
port,
{
trailingLineFeed: true
}
);

common.log = sinon.stub().returns('{"what":"ever"}' + "\r\n\t ");

test_server = createTestServer(port, function (data) {
expect(data.toString()).to.be.eql('{"what":"ever"}' + os.EOL);
done();
});

logger.log('info', 'hello world', {stream: 'sample'});
});

it('if set in the options, remove all trailing blank characters and replace them with a custom character', function (done) {
var logger = createLogger(
port,
{
trailingLineFeed: true,
trailingLineFeedChar: os.EOL + "\n"
}
);

common.log = sinon.stub().returns('{"what":"ever"}' + "\r\n\t ");

test_server = createTestServer(port, function (data) {
expect(data.toString()).to.be.eql('{"what":"ever"}' + os.EOL + "\n");
done();
});

logger.log('info', 'hello world', {stream: 'sample'});
});
});

// Teardown
afterEach(function () {
if (test_server) {
Expand All @@ -82,4 +137,4 @@ describe('winston-logstash-udp transport', function () {

});

});
});

0 comments on commit e5da5dc

Please sign in to comment.