Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for setting the transport name #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Basic transport that works just like all other winston transports. Sends logged messages to a specified slack chat channel

First install winston...

$ npm install winston

Then install winston-bishop-slack
Expand All @@ -16,11 +16,12 @@ Then install winston-bishop-slack
* **icon_url:** *avatar of the message 'sender' as it appears in slack*
* **channel:** *channel on which the sent message will appear in slack*
* **username:** *name displayed in the chat channel. default "Winston Bishop"*
* **name:** *name of the transport. default "slack"*

<code>
var winston = require('winston');
var slack = require('winston-bishop-slack').Slack;

winston.add(slack, {
webhook_url: "https://hooks.slack.com/services/...",
icon_url: "https://stagefisher.s3.amazonaws.com/images/character/image/519b31da5bf1614f8100000e/Winston-Bishop-New_Girl.jpg",
Expand All @@ -41,13 +42,12 @@ Then install winston-bishop-slack
}]}
}
})
winston.error('Ferguson Ran Away!', { detail: "He was last seen at 3pm on Tuesday" },

winston.error('Ferguson Ran Away!', { detail: "He was last seen at 3pm on Tuesday" },
function(err, res) {
console.log('Finished 3: (error=%s)', JSON.stringify(err, null, 2));
}
);
</code>

![winston](https://cldup.com/ZcEghxatuM-3000x3000.png "Looks like this...")

6 changes: 3 additions & 3 deletions lib/winston-slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ var Slack = exports.Slack = function (options) {
}
else {
this.webhook_url = options.webhook_url;
this.channel = options.channel;
this.channel = options.channel;
this.icon_url = options.icon_url || "https://cldup.com/9M--n6m2F6-3000x3000.jpeg";
this.username = options.username || "Winston Bishop";
this.level = options.level || 'info';
this.silent = options.silent || false;
this.raw = options.raw || false;
this.name = options.name || 'slack'
this.customFormatter = options.customFormatter;

//- Enabled loging of uncaught exceptions
Expand All @@ -25,7 +26,6 @@ var Slack = exports.Slack = function (options) {

util.inherits(Slack, winston.Transport);
winston.transports.Slack = Slack;
Slack.prototype.name = 'slack'

Slack.prototype.log = function (level, msg, meta, callback) {
//- Use custom formatter for message if set
Expand All @@ -44,4 +44,4 @@ Slack.prototype.log = function (level, msg, meta, callback) {
.post(this.webhook_url)
.send(message)
.end(callback)
};
};