Skip to content

Commit

Permalink
updates version / documentation / add name to transport
Browse files Browse the repository at this point in the history
  • Loading branch information
sparkida committed Feb 28, 2016
1 parent 77355fb commit d226adb
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 4 deletions.
72 changes: 70 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,91 @@ logger.on('DatadogResult', (res) => {
// disable receiver
// ddTransport.stopResults();

// start receiver on last logger
// ddTransport.receiveResults();
```

###Event Options
```javascript
var ddTransport = new Datadog({ ... });
//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'];

//do stuff ...

//reset options
ddTransport.resetOptions();
```


###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');
var Options = DatadogTransport.prototype.Options;
Options.prototype.title = 'Custom Global Title';
Options.prototype.tags = ['custom:MyCustomTag'];
//now these changes will persist through each instance
var ddTransport = new DatadogTransport({ ... });
console.log(ddTransport.options.title);
// 'Custom Global Title'
```


###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();

```javascript
var ddTransport = new Datadog({ ... });
console.log(ddTransport.loglevels);
// {
// silly: 'info',
// debug: 'info',
// verbose: 'info',
// warn: 'warning'
// }

// make all info messages route to ddTransport.options.alert_type = 'success'
ddTransport.loglevels.info = 'success';
// make all verbose messages route to ddTransport.options.alert_type = 'success'
ddTransport.loglevels.verbose = 'success';
```

Receiving Response Data
-----------------------

By default, this transport only sends logs, it does not do anything with the response object. Enabling the receiver will add some overhead, but may be necessary.



Events
------
***DatadogResult*** - emitted by the logger when a response object has finished receiving data. The response object will have a body object containing the resulting data.


Logging
-------
The body of the event(log) is limited to 4000 characters and supports markdown.


Options
-------
Each Datadog Transport instance will expose the following options via `ddTransport.options`

- **title** ***[default=LOG]*** - The event title. Limited to 100 characters.
- **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.
- **tags** ***[optional, default='env:process.env.NODE_ENV']*** - A list of tags to apply to the event.
- **alert_type** ***[optional, default='info']*** - "error", "warning", "info" or "success". (These are overriden by the default winston log levels, but you can do something about that through `ddTransport.loglevels`
- **aggregation_key** ***[optional, default=None]*** - An arbitrary string to use for aggregation, max length of 100 characters.
- **source_type_name** ***[optional, default=None]*** - The type of event being posted. Options: nagios, hudson, jenkins, user, my apps, feed, chef, puppet, git, bitbucket, fabric, capistrano


Updates
-------
* 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
* Check back notice - 08:09 PDT Feb 27th, 2016
16 changes: 15 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Transport { //jshint ignore:line
constructor(credentials) {
var api = this;
var paths = Transport.API_ENDPOINT.split('/').filter(Boolean);
api.name = 'Datadog';
api.attachResults = false;
api.requestOptions = {
port: paths[0] === 'https:' ? 443 : 80,
Expand All @@ -48,7 +49,9 @@ class Transport { //jshint ignore:line
receiveResults(logger) {
var api = this;
api.attachResults = true;
api.logger = logger;
if (logger) {
api.logger = logger;
}
}

/**
Expand All @@ -58,6 +61,14 @@ class Transport { //jshint ignore:line
this.attachResults = false;
}

/**
* Sets the winston logger to use for DatadogResult event
*/
resetOptions() {
var api = this;
api.options = new api.Options();
}

/**
* Log events from winston
*/
Expand Down Expand Up @@ -94,6 +105,9 @@ class Transport { //jshint ignore:line
if (!opts.text) {
opts.text = text;
}
if (opts.text.length > 4000) {
opts.text = opts.text.substr(0, 4000);
}
req.write(JSON.stringify(opts));
req.end();
opts.text = null;
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.1",
"version": "1.0.2",
"description": "Super light transport for logging Datadog events",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit d226adb

Please sign in to comment.