forked from winstonjs/winston-loggly
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from loggly/3.x
Use winston 3.x by default
- Loading branch information
Showing
5 changed files
with
160 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,9 @@ Please note that the documentation below is for `[email protected]`. [Read | |
// Requiring `winston-loggly-bulk` will expose | ||
// `winston.transports.Loggly` | ||
// | ||
require('winston-loggly-bulk'); | ||
var {Loggly} = require('winston-loggly-bulk'); | ||
|
||
winston.add(winston.transports.Loggly, options); | ||
winston.add(new Loggly({options})); | ||
``` | ||
|
||
The Loggly transport is based on [Nodejitsu's][2] [node-loggly][3] implementation of the [Loggly][0] API. If you haven't heard of Loggly before, you should probably read their [value proposition][4]. The Loggly transport takes the following options. Either 'inputToken' or 'inputName' is required: | ||
|
@@ -45,6 +45,22 @@ The Loggly transport is based on [Nodejitsu's][2] [node-loggly][3] implementatio | |
|
||
*Metadata:* Logged in suggested [Loggly format][5] | ||
|
||
## Sample Working Code Snippet | ||
|
||
``` js | ||
var winston = require('winston'); | ||
var {Loggly} = require('winston-loggly-bulk'); | ||
|
||
winston.add(new Loggly({ | ||
token: "TOKEN", | ||
subdomain: "SUBDOMAIN", | ||
tags: ["Winston-NodeJS"], | ||
json: true | ||
})); | ||
|
||
winston.log('info', "Hello World from Node.js!"); | ||
``` | ||
|
||
## Buffer Support | ||
|
||
This library has buffer support during temporary network outage. User can configure size of buffer (no. of logs to be stored during network outage). | ||
|
@@ -65,11 +81,11 @@ Our library uses ajax requests to send logs to Loggly, and as ajax requests take | |
Here is an example of how to use the method: | ||
|
||
``` js | ||
var winston = require('winston'), | ||
winlog = require('winston-loggly-bulk'); | ||
var winston = require('winston'); | ||
var {flushLogsAndExit} = require('winston-loggly-bulk'); | ||
|
||
winston.log("info", "hello World"); | ||
winlog.flushLogsAndExit(); | ||
winston.log("info", "Hello World from Node.js!"); | ||
flushLogsAndExit(); | ||
|
||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "winston-loggly-bulk", | ||
"version": "2.0.3", | ||
"version": "3.0.1", | ||
"description": "A Loggly transport for winston", | ||
"author": "Loggly <[email protected]>", | ||
"contributors": [ | ||
|
@@ -19,15 +19,27 @@ | |
"type": "git", | ||
"url": "https://github.com/loggly/winston-loggly-bulk.git" | ||
}, | ||
"keywords": ["loggly", "logging", "sysadmin", "tools", "winston"], | ||
"keywords": [ | ||
"loggly", | ||
"logging", | ||
"sysadmin", | ||
"tools", | ||
"winston" | ||
], | ||
"dependencies": { | ||
"node-loggly-bulk": "^2.0.1", | ||
"winston": "^2.3.1" | ||
"clone": "^2.1.1", | ||
"winston": "^3.0", | ||
"winston-transport": "^4.2.0" | ||
}, | ||
"devDependencies": { | ||
"vows": "0.8.0" | ||
}, | ||
"main": "./lib/winston-loggly", | ||
"scripts": { "test": "vows --spec" }, | ||
"engines": { "node": ">= 0.8.0" } | ||
"scripts": { | ||
"test": "vows --spec" | ||
}, | ||
"engines": { | ||
"node": ">= 6.4.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
const winston = require('winston'); | ||
module.exports.testLevels = function (transport, assertMsg, assertFn) { | ||
var tests = {}; | ||
const levels = winston.config.npm.levels; | ||
|
||
Object.keys(levels).forEach(function (level) { | ||
var test = { | ||
topic: function () { | ||
transport.log(level, 'test message', {}, this.callback.bind(this, null)); | ||
} | ||
}; | ||
|
||
test[assertMsg] = assertFn; | ||
tests['with the ' + level + ' level'] = test; | ||
}); | ||
|
||
var metadatatest = { | ||
topic: function () { | ||
transport.log('info', 'test message', { metadata: true }, this.callback.bind(this, null)); | ||
} | ||
}; | ||
|
||
metadatatest[assertMsg] = assertFn; | ||
tests['when passed metadata'] = metadatatest; | ||
|
||
var primmetadatatest = { | ||
topic: function () { | ||
transport.log('info', 'test message', 'metadata', this.callback.bind(this, null)); | ||
} | ||
}; | ||
|
||
primmetadatatest[assertMsg] = assertFn; | ||
tests['when passed primitive metadata'] = primmetadatatest; | ||
|
||
var nummetadatatest = { | ||
topic: function () { | ||
transport.log('info', 'test message', 123456789, this.callback.bind(this, null)); | ||
} | ||
}; | ||
|
||
nummetadatatest[assertMsg] = assertFn; | ||
tests['when passed numeric metadata'] = nummetadatatest; | ||
|
||
// circular references aren't supportded by regular JSON, and it's not supported | ||
// by node-loggly-bulk. I'm omitting it for now. If it wants to be fixed, then | ||
// node-loggly-bulk needs an update. | ||
/* | ||
var circmetadata = { }; | ||
circmetadata['metadata'] = circmetadata; | ||
var circmetadatatest = { | ||
topic: function () { | ||
transport.log('info', 'circular message', circmetadata, this.callback.bind(this, null)); | ||
} | ||
}; | ||
circmetadatatest[assertMsg] = assertFn; | ||
tests['when passed circular metadata'] = circmetadatatest; | ||
var circerror = new Error("message!"); | ||
var foo = {}; | ||
var circerrordatatest; | ||
foo.bar = foo; | ||
circerror.foo = foo; | ||
circerror.stack = 'Some stacktrace'; | ||
circerrordatatest = { | ||
topic: function () { | ||
transport.log('info', 'circular error', circerror, this.callback.bind(this, null)); | ||
} | ||
}; | ||
circerrordatatest[assertMsg] = assertFn; | ||
tests['when passed circular error as metadata'] = circerrordatatest; | ||
*/ | ||
|
||
return tests; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters