Skip to content

Commit

Permalink
Merge pull request #3 from sparkida/integration-1.1.0
Browse files Browse the repository at this point in the history
Integration 1.1.0 - Feature support for useTextAsTitle
  • Loading branch information
sparkida authored Nov 27, 2017
2 parents d226adb + bc32d1c commit f153318
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
test/.env
coverage
package-lock.json
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
.npmignore
test/.env
coverage
package-lock.json
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ before_install:
after_success:
- npm run report
node_js:
- '5.7.0'
- '9'
- '5'
git:
depth: 3
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ npm install --save winston-datadog
Examples
--------

###Basic setup
### Basic setup
```javascript
const winston = require('winston');
const DatadogTransport = require('winston-datadog');
Expand All @@ -26,13 +26,13 @@ const ddTransport = new DatadogTransport({
});
const logger = new winston.Logger({
transports: [
ddTransport
ddTransport
]
});

```

###Receiving Results from Datadog
### Receiving Results from Datadog
```javascript
ddTransport.receiveResults(logger);
logger.on('DatadogResult', (res) => {
Expand All @@ -46,10 +46,12 @@ logger.on('DatadogResult', (res) => {
// ddTransport.receiveResults();
```

###Event Options
### Event Options
```javascript
var ddTransport = new Datadog({ ... });
//set the new title to use
//have the text be used in place of title (default: false)
ddTransport.useTextAsTitle = true;
//or...set the new title to use
ddTransport.options.title = 'My Custom Title';
//set the new tags to use
ddTransport.options.tags = ['env:local', 'version:1', 'region:us-west-1'];
Expand All @@ -61,7 +63,7 @@ ddTransport.resetOptions();
```


###Permanently Override Default Options
### Permanently Override Default Options
In case you have multiple instances of the transport running and/or find you need to permanently change the default `DatadogTransport.Options`
```javascript
var DatadogTransport = require('winston-datadog');
Expand All @@ -75,7 +77,7 @@ console.log(ddTransport.options.title);
```


###Loglevels
### Loglevels

When Winston passes logs off to the Datadog transport, winston-datadog will map the log type (info, warn, error, etc...) to the corresponding `ddTransport.options.alert_type`. A check will be done to see if the log type exists in `ddTransport.loglevels`, if found it will override the default log type sent from winston. We have to do this, for isntance, in order to map Winston->warn() to DatadogTransport->warning();

Expand Down Expand Up @@ -126,6 +128,7 @@ Each Datadog Transport instance will expose the following options via `ddTranspo

Updates
-------
* Added new feature [useTextAsTitle](https://github.com/sparkida/winston-datadog/pull/2) / updated for NodeJS 9 - @v1.1.0 08:30 PST Nov 27th, 2017
* Adds name to winston transports - @v1.0.2 09:03 PDT Feb 28th, 2016
* Stable Release - @v1.0.1 21:58 PDT Feb 27th, 2016
* Initial Release - 20:11 PDT Feb 27th, 2016
Expand Down
15 changes: 11 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ class Transport { //jshint ignore:line
var paths = Transport.API_ENDPOINT.split('/').filter(Boolean);
api.name = 'Datadog';
api.attachResults = false;
//set to true to force transport to use text in place of the title
api.useTextAsTitle = false;
api.requestOptions = {
port: paths[0] === 'https:' ? 443 : 80,
hostname: paths[1],
path: format('/%s/v%d/events?%s',
paths[2],
Transport.API_VERSION,
path: format('/%s/v%d/events?%s',
paths[2],
Transport.API_VERSION,
qs.stringify(credentials)),
method: 'POST',
headers: {
Expand Down Expand Up @@ -92,6 +94,11 @@ class Transport { //jshint ignore:line
});
var opts = api.options;
opts.alert_type = loglevel;

if (api.useTextAsTitle) {
opts.title = text;
}

//efficient way to check if object is empty or error
if (data instanceof Error) {
opts.text = text + (text.length ? ' | ' + data.stack : data.stack);
Expand Down Expand Up @@ -127,7 +134,7 @@ Transport.prototype.loglevels = {
warn: 'warning'
};

/**
/**
* Exposes endpoint options for Data-Dog
* @const
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "winston-datadog",
"version": "1.0.2",
"version": "1.1.0",
"description": "Super light transport for logging Datadog events",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions test/.env.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
DD_API_KEY=''
DD_APPLICATION_KEY=''
DD_API_KEY=
DD_APPLICATION_KEY=

0 comments on commit f153318

Please sign in to comment.