Skip to content

Commit

Permalink
Adding support for sending logs verbatim into logentries. fixes issue…
Browse files Browse the repository at this point in the history
…s #40
  • Loading branch information
Gearoid O Fearghail committed Dec 7, 2015
1 parent e3af3f9 commit 1f9bf59
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 14 deletions.
2 changes: 2 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var testFiles = [
];
var apiVersion = 1;
var apiEndpoint = 'js.logentries.com/v' + apiVersion;
var webhookEndpoint = 'webhook.logentries.com/noformat';


gulp.task('default', ['test', 'build']);
Expand All @@ -26,6 +27,7 @@ gulp.task('build', function() {
return gulp.src('src/le.js')
.pipe(concat('le.js')) // We've only got one file but still need this
.pipe(replace(/localhost:8080\/v1/g, apiEndpoint))
.pipe(replace(/localhost:8080\/noformat/g, webhookEndpoint))
.pipe(gulp.dest('product'))
.pipe(closureCompiler({
compilation_level: 'SIMPLE_OPTIMIZATIONS',
Expand Down
7 changes: 6 additions & 1 deletion product/le.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
/** @type {boolean} */
var _print = options.print;
/** @type {boolean} */
var _noFormat = options.no_format;
/** @type {boolean} */
var _SSL = function() {
if (typeof XDomainRequest === "undefined") {
return options.ssl;
Expand All @@ -78,7 +80,10 @@
var _endpoint;
if (window.LEENDPOINT) {
_endpoint = window.LEENDPOINT;
} else {
} else if (_noFormat) {
_endpoint = "webhook.logentries.com/noformat";
}
else {
_endpoint = "js.logentries.com/v1";
}
_endpoint = (_SSL ? "https://" : "http://") + _endpoint + "/logs/" + _token;
Expand Down
16 changes: 8 additions & 8 deletions product/le.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/le.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
/** @type {boolean} */
var _print = options.print;
/** @type {boolean} */
var _noFormat = options.no_format;
/** @type {boolean} */
var _SSL = function() {
if (typeof XDomainRequest === "undefined") {
return options.ssl;
Expand All @@ -78,7 +80,10 @@
var _endpoint;
if (window.LEENDPOINT) {
_endpoint = window.LEENDPOINT;
} else {
} else if (_noFormat) {
_endpoint = "localhost:8080/noformat";
}
else {
_endpoint = "localhost:8080/v1";
}
_endpoint = (_SSL ? "https://" : "http://") + _endpoint + "/logs/" + _token;
Expand Down
37 changes: 33 additions & 4 deletions test/leSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,26 +331,56 @@ describe('destroys log streams', function () {
name: 'test'
});
}).not.toThrow();
LE.destroy('test');
});

afterEach(destroy);
});

describe('no_format option', function () {
beforeEach(mockXMLHttpRequests);
beforeEach(addGetJson);

it('Should send data to noformat if no format is enabled', function () {
LE.init({
token: TOKEN,
no_format: true
});
LE.log('some message');
var url = this.requestList[0].url;
expect(url).toContain("noformat");
});

it('Should send data to js if no format is disabled', function () {
LE.init({
token: TOKEN,
no_format: false
});
LE.log('some message');
var url = this.requestList[0].url;
expect(url).toContain("v1");
});

afterEach(restoreXMLHttpRequests);
afterEach(destroy);
});


describe('custom endpoint', function () {
beforeEach(mockXMLHttpRequests);
beforeEach(addGetJson);
beforeEach(function () {
window.LEENDPOINT = 'somwhere.com/custom-logging';
window.LEENDPOINT = 'somewhere1.com/custom-logging';
LE.init({
token: TOKEN
});
});

it('can be set', function () {
LE.log('some message');
var lastReq = this.requestList[1]; //no idea why its sending two messages
var lastReq = this.requestList[0];

expect(lastReq.url).toBe('https://somwhere.com/custom-logging/logs/test_token');
expect(lastReq.url).toBe('https://somewhere1.com/custom-logging/logs/test_token');
});

afterEach(restoreXMLHttpRequests);
Expand All @@ -364,7 +394,6 @@ describe('print option', function () {
spyOn(console, 'info');
spyOn(console, 'warn');
spyOn(console, 'error');
window.LEENDPOINT = 'somwhere.com/custom-logging';
LE.init({
token: TOKEN,
print: true
Expand Down

0 comments on commit 1f9bf59

Please sign in to comment.