From f4732d30aee5c2dcdab7417e41c8ddd137a59751 Mon Sep 17 00:00:00 2001 From: Stephen Buchanan Date: Fri, 17 Nov 2017 12:28:41 +0100 Subject: [PATCH 1/5] can specify useTextAsTitle, optionally --- index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 6c816e1..840f65d 100644 --- a/index.js +++ b/index.js @@ -29,9 +29,9 @@ class Transport { //jshint ignore:line 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: { @@ -92,6 +92,11 @@ class Transport { //jshint ignore:line }); var opts = api.options; opts.alert_type = loglevel; + + if (opts.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); @@ -127,7 +132,7 @@ Transport.prototype.loglevels = { warn: 'warning' }; -/** +/** * Exposes endpoint options for Data-Dog * @const */ @@ -136,6 +141,7 @@ class TransportOptions { var opts = this; return { title: opts.title, + useTextAsTitle: opts.useTextAsTitle, priority: opts.priority, date_happened: opts.date_happened, host: opts.host, From b36367e6f09f66ed3dd3888e871d4dffb0fbb119 Mon Sep 17 00:00:00 2001 From: Stephen Buchanan Date: Fri, 17 Nov 2017 16:03:52 +0100 Subject: [PATCH 2/5] fixed readme headings --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a8c437b..f3e1147 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ npm install --save winston-datadog Examples -------- -###Basic setup +### Basic setup ```javascript const winston = require('winston'); const DatadogTransport = require('winston-datadog'); @@ -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) => { @@ -46,7 +46,7 @@ logger.on('DatadogResult', (res) => { // ddTransport.receiveResults(); ``` -###Event Options +### Event Options ```javascript var ddTransport = new Datadog({ ... }); //set the new title to use @@ -61,7 +61,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'); @@ -75,7 +75,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(); From a8fa58df694147f26cdf436fa4b4e88d1e43686a Mon Sep 17 00:00:00 2001 From: Nick Riley Date: Mon, 27 Nov 2017 08:35:31 -0800 Subject: [PATCH 3/5] Adds info for useTextAsTitle to README / update .gitignore to ignore package-lock --- .gitignore | 1 + .npmignore | 1 + README.md | 4 ++++ index.js | 3 ++- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3384858..d2e7bfa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules test/.env coverage +package-lock.json diff --git a/.npmignore b/.npmignore index c1925a8..4da9807 100644 --- a/.npmignore +++ b/.npmignore @@ -4,3 +4,4 @@ node_modules .npmignore test/.env coverage +package-lock.json diff --git a/README.md b/README.md index f3e1147..66907a1 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,8 @@ logger.on('DatadogResult', (res) => { var ddTransport = new Datadog({ ... }); //set the new title to use ddTransport.options.title = 'My Custom Title'; +//or...optionally use text as title (default: false) +ddTransport.options.useTextAsTitle = true; //set the new tags to use ddTransport.options.tags = ['env:local', 'version:1', 'region:us-west-1']; @@ -115,6 +117,7 @@ Options Each Datadog Transport instance will expose the following options via `ddTransport.options` - **title** ***[default=LOG]*** - The event title. Limited to 100 characters. +- **useTextAsTitle** ***[default=false]*** - Set to force transport to use the text as the title, [see PR#2](https://github.com/sparkida/winston-datadog/pull/2) - **date_happened** ***[optional, default=now]*** - POSIX timestamp of the event. - **priority** ***[optional, default='normal']*** - The priority of the event ('normal' or 'low'). - **host** ***[optional, default=os.hostname()]*** - Host name to associate with the event. @@ -126,6 +129,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 diff --git a/index.js b/index.js index 840f65d..03e2c9a 100644 --- a/index.js +++ b/index.js @@ -94,7 +94,7 @@ class Transport { //jshint ignore:line opts.alert_type = loglevel; if (opts.useTextAsTitle) { - opts.title = text; + opts.title = text; } //efficient way to check if object is empty or error @@ -153,6 +153,7 @@ class TransportOptions { } } TransportOptions.prototype.title = 'LOG'; +TransportOptions.prototype.useTextAsTitle = false; TransportOptions.prototype.priority = 'normal'; // or low TransportOptions.prototype.date_happened = null; TransportOptions.prototype.host = hostname; From 32a79c1086f0c4b206ff380fb4ae7833b9e243fa Mon Sep 17 00:00:00 2001 From: Nick Riley Date: Mon, 27 Nov 2017 07:55:11 -0800 Subject: [PATCH 4/5] updated Travis to test NodeJS 9 --- .travis.yml | 3 ++- package.json | 2 +- test/.env.sample | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index fb16459..0d567e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ before_install: after_success: - npm run report node_js: - - '5.7.0' + - '9' + - '5' git: depth: 3 diff --git a/package.json b/package.json index 5a86c7a..7bde114 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/.env.sample b/test/.env.sample index d02a3b1..642e39c 100644 --- a/test/.env.sample +++ b/test/.env.sample @@ -1,2 +1,2 @@ -DD_API_KEY='' -DD_APPLICATION_KEY='' +DD_API_KEY= +DD_APPLICATION_KEY= From bc32d1c8ecb71c0e184a8100646eba81ae3cf4bd Mon Sep 17 00:00:00 2001 From: Nick Riley Date: Mon, 27 Nov 2017 09:02:50 -0800 Subject: [PATCH 5/5] moves useTextAsTitle from transport.options to transport to reduce network out --- README.md | 7 +++---- index.js | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 66907a1..90b882c 100644 --- a/README.md +++ b/README.md @@ -49,10 +49,10 @@ logger.on('DatadogResult', (res) => { ### 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'; -//or...optionally use text as title (default: false) -ddTransport.options.useTextAsTitle = true; //set the new tags to use ddTransport.options.tags = ['env:local', 'version:1', 'region:us-west-1']; @@ -117,7 +117,6 @@ Options Each Datadog Transport instance will expose the following options via `ddTransport.options` - **title** ***[default=LOG]*** - The event title. Limited to 100 characters. -- **useTextAsTitle** ***[default=false]*** - Set to force transport to use the text as the title, [see PR#2](https://github.com/sparkida/winston-datadog/pull/2) - **date_happened** ***[optional, default=now]*** - POSIX timestamp of the event. - **priority** ***[optional, default='normal']*** - The priority of the event ('normal' or 'low'). - **host** ***[optional, default=os.hostname()]*** - Host name to associate with the event. diff --git a/index.js b/index.js index 03e2c9a..8cda0cf 100644 --- a/index.js +++ b/index.js @@ -26,6 +26,8 @@ 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], @@ -93,7 +95,7 @@ class Transport { //jshint ignore:line var opts = api.options; opts.alert_type = loglevel; - if (opts.useTextAsTitle) { + if (api.useTextAsTitle) { opts.title = text; } @@ -141,7 +143,6 @@ class TransportOptions { var opts = this; return { title: opts.title, - useTextAsTitle: opts.useTextAsTitle, priority: opts.priority, date_happened: opts.date_happened, host: opts.host, @@ -153,7 +154,6 @@ class TransportOptions { } } TransportOptions.prototype.title = 'LOG'; -TransportOptions.prototype.useTextAsTitle = false; TransportOptions.prototype.priority = 'normal'; // or low TransportOptions.prototype.date_happened = null; TransportOptions.prototype.host = hostname;