Comparing version 1.6.0 to 2.0.0
@@ -24,2 +24,4 @@ "use strict"; | ||
headerTextColor: 'gray', | ||
slackWebHookUrl: null, | ||
slackDisabled: false, | ||
onLog: function () { }, | ||
@@ -26,0 +28,0 @@ }; |
@@ -23,2 +23,3 @@ "use strict"; | ||
var path_1 = __importDefault(require("path")); | ||
var slack_1 = __importDefault(require("./slack")); | ||
var tracker_1 = __importDefault(require("./tracker")); | ||
@@ -33,2 +34,3 @@ var helpers_1 = __importDefault(require("./helpers")); | ||
var _helpers = new helpers_1.default(options); | ||
var _slack = new slack_1.default(); | ||
function log(level) { | ||
@@ -102,2 +104,15 @@ var args = []; | ||
return log.apply(void 0, __spreadArray([_level], __spreadArray(__spreadArray([], argc), args))); | ||
}, | ||
slack: function (slackOptions, cb) { | ||
var webHookUrl = options.slackWebHookUrl; | ||
if (!options.slackDisabled && webHookUrl) { | ||
var text = _output.getOutput(level, argc, hash, false); | ||
var payload = __assign(__assign({}, slackOptions), { text: text }); | ||
_slack.send(payload, webHookUrl) | ||
.then(cb) | ||
.catch(function (error) { | ||
console.warn("Logflake failed to send slack message: " + error); | ||
}); | ||
} | ||
return keepChain(); | ||
} | ||
@@ -104,0 +119,0 @@ }; |
{ | ||
"name": "logflake", | ||
"version": "1.6.0", | ||
"version": "2.0.0", | ||
"description": "Better console messages for NodeJS", | ||
@@ -28,2 +28,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@slack/webhook": "^6.0.0", | ||
"chalk": "^4.1.1", | ||
@@ -30,0 +31,0 @@ "md5": "^2.3.0" |
@@ -246,2 +246,4 @@ # LogFlake | ||
| onLog | Event triggered everytime a log is fired with the current function (see `Events` on this doc) | | ||
| slackDisabled | Will ignore the "slack" method, and wont send log results to slack | false | | ||
| slackWebHookUrl | Slack web hook URL used to send log messages directly to slack | null | | ||
@@ -254,2 +256,4 @@ > Obs 1. You can check all the `format` available options here: https://nodejs.org/api/util.html#util_util_inspect_object_options | ||
> Obs 4. You can see how to get a Slack Webhook Url here: https://slack.com/intl/en-br/help/articles/115005265063-Incoming-webhooks-for-Slack | ||
# Namespaces (Prefix) | ||
@@ -534,2 +538,36 @@ | ||
## slack | ||
``` | ||
slack(options?: object, callback?: function): chain | ||
``` | ||
This methods sends the current message being log directly to slack. To do it, you must first set the option "slackWebHookUrl" on you LogFlake instance. You can see how to get your Slack Webhook URL here: https://slack.com/intl/en-br/help/articles/115005265063-Incoming-webhooks-for-Slack. | ||
After that, you can send logs directly to slack like this: | ||
```js | ||
const log = require('logflake')({ | ||
slackDisabled: false, | ||
slackWebHookUrl: 'https://hooks.slack.com/services/yourwebhooktoken', | ||
}); | ||
log('Hello World!').slack(); | ||
``` | ||
The log above will be sent to slack. The channel and other details are configured while getting your webhook url. The "slackDisabled" option is false by default, you can ommit it, or turn true if you want to disabled slack messages in a given environment. The slack functions has 2 params: 1. options: which accepts any slack webhook option, and 2. a callback that will run as soon the message has been delivered. | ||
```js | ||
const log = require('logflake')({ | ||
slackDisabled: false, | ||
slackWebHookUrl: 'https://hooks.slack.com/services/yourwebhooktoken', | ||
}); | ||
log('Hello World!').slack({ icon_emoji: ':bell:' }, status => { | ||
const messageDelivered = status.text === 'ok'; | ||
//... | ||
}); | ||
``` | ||
# Events | ||
@@ -536,0 +574,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
51398
18
444
598
3
+ Added@slack/webhook@^6.0.0
+ Added@slack/types@1.10.0(transitive)
+ Added@slack/webhook@6.1.0(transitive)
+ Added@types/node@22.13.10(transitive)
+ Addedaxios@0.21.4(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedundici-types@6.20.0(transitive)