Change logging to Slack, closes #78

This commit is contained in:
Kristian Polso 2018-06-01 10:10:22 +03:00
parent 156cbde697
commit 2fd75fa25f
3 changed files with 50 additions and 51 deletions

View file

@ -19,13 +19,13 @@
"cron": "^1.3.0",
"dotenv": "^5.0.1",
"express": "^4.16.3",
"heroku-logger": "^0.3.1",
"heroku-ssl-redirect": "0.0.4",
"highlight.js": "^9.12.0",
"node-sass": "^4.9.0",
"redis": "^2.8.0",
"request": "^2.85.0",
"sass-loader": "^7.0.1",
"slack-node": "^0.1.8",
"vue": "^2.5.16",
"vue-highlightjs": "^1.3.3",
"vue-image-upload-resize": "^1.1.6",

View file

@ -20,8 +20,12 @@ var octokit = require('@octokit/rest')();
// Redis
var redis = require("redis"),
redisClient = redis.createClient(process.env.REDISCLOUD_URL);
// Logging
var logger = require('heroku-logger');
// Slack
if(typeof process.env.SLACK_WEBHOOK_URL != 'undefined') {
var Slack = require('slack-node');
var slack = new Slack();
slack.setWebhook(process.env.SLACK_WEBHOOK_URL);
}
app = express();
app.use(serveStatic(__dirname + "/content/.vuepress/dist"));
@ -63,7 +67,7 @@ app.get('/forward', function(req, res) {
}, function(error, response, body) {
// Should we parse the body before forwarding?
if(typeof body.error != "") {
logger.error('Got error from daemon', {error: body.error});
logSlackError('ERROR: Got error from daemon: ' + JSON.stringify(body.error));
}
res.setHeader('Content-Type', 'application/json');
res.send(body);
@ -105,7 +109,7 @@ app.get('/*', function(req, res) {
var port = process.env.PORT || 8080;
app.listen(port);
logger.info('server started', {port: port});
logSlackError('Server started at port ' + port);
function updateGithubFeed() {
@ -138,17 +142,31 @@ function updateGithubFeed() {
// Keep the latest 50 events
redisClient.zremrangebyrank('events', 0, -51);
logger.info('Updated Github feed');
console.log('Updated Github feed');
});
}).catch(function(err) {
logger.error('Couldn\t update Github feed', {error: error});
logSlackError('ERROR: Couldnt update Github feed: ' + JSON.stringify(err));
});
}
function logSlackError(text) {
if(typeof process.env.SLACK_WEBHOOK_URL != 'undefined') {
slack.webhook({
channel: 'dottech-errors',
username: 'lbrytech-bot',
text: text
});
}
}
// Update Github feed every minute
new CronJob("0 * * * * *", updateGithubFeed, null, true, 'America/Los_Angeles');

View file

@ -2086,10 +2086,6 @@ des.js@^1.0.0:
inherits "^2.0.1"
minimalistic-assert "^1.0.0"
destroy-circular@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/destroy-circular/-/destroy-circular-1.1.0.tgz#f76624b76f999f1ac18b0ab444495118293a3ce0"
destroy@^1.0.3, destroy@~1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80"
@ -2458,7 +2454,7 @@ extend-shallow@^3.0.0, extend-shallow@^3.0.2:
assign-symbols "^1.0.0"
is-extendable "^1.0.1"
extend@~3.0.0, extend@~3.0.1:
extend@^3.0.0, extend@~3.0.0, extend@~3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.1.tgz#a755ea7bc1adfcc5a31ce7e762dbaadc5e636444"
@ -2560,12 +2556,6 @@ find-up@^2.0.0, find-up@^2.1.0:
dependencies:
locate-path "^2.0.0"
flat@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/flat/-/flat-2.0.1.tgz#70e29188a74be0c3c89409eed1fa9577907ae32f"
dependencies:
is-buffer "~1.1.2"
flatten@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782"
@ -3028,16 +3018,6 @@ he@1.1.x, he@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/he/-/he-1.1.1.tgz#93410fd21b009735151f8868c2f271f3427e23fd"
heroku-logger@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/heroku-logger/-/heroku-logger-0.3.1.tgz#6ac749cd7779e7f903c481c50882e511cfed5849"
dependencies:
chalk "^1.1.3"
destroy-circular "^1.1.0"
flat "^2.0.1"
is "^3.2.1"
logfmt "^1.2.0"
heroku-ssl-redirect@0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/heroku-ssl-redirect/-/heroku-ssl-redirect-0.0.4.tgz#21ba0707aa503b50a412a0946abfaa88ef7d082c"
@ -3307,7 +3287,7 @@ is-binary-path@^1.0.0:
dependencies:
binary-extensions "^1.0.0"
is-buffer@^1.1.5, is-buffer@~1.1.2:
is-buffer@^1.1.5:
version "1.1.6"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
@ -3526,10 +3506,6 @@ is-wsl@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-1.1.0.tgz#1f16e4aa22b04d1336b66188a66af3c600c3a66d"
is@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/is/-/is-3.2.1.tgz#d0ac2ad55eb7b0bec926a5266f6c662aaa83dca5"
isarray@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf"
@ -3922,7 +3898,7 @@ lodash.uniq@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
lodash@4.x, lodash@^4.0.0, lodash@^4.14.0, lodash@~4.17.4:
lodash@^4.0.0, lodash@^4.14.0, lodash@^4.15.0, lodash@~4.17.4:
version "4.17.10"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"
@ -3944,14 +3920,6 @@ log-update@^2.3.0:
cli-cursor "^2.0.0"
wrap-ansi "^3.0.1"
logfmt@^1.2.0:
version "1.2.1"
resolved "https://registry.yarnpkg.com/logfmt/-/logfmt-1.2.1.tgz#0e99838eb3a87fb6272d6d2b4fc327b95a29abee"
dependencies:
lodash "4.x"
split "0.2.x"
through "2.3.x"
loglevelnext@^1.0.1, loglevelnext@^1.0.2:
version "1.0.4"
resolved "https://registry.yarnpkg.com/loglevelnext/-/loglevelnext-1.0.4.tgz#0d991d9998180991dac8bd81e73a596a8720a645"
@ -5521,7 +5489,7 @@ repeating@^2.0.0:
dependencies:
is-finite "^1.0.0"
request@2:
request@2, request@^2.74.0:
version "2.87.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.87.0.tgz#32f00235cd08d482b4d0d68db93a829c0ed5756e"
dependencies:
@ -5625,6 +5593,15 @@ request@~2.79.0:
tunnel-agent "~0.4.1"
uuid "^3.0.0"
requestretry@^1.2.2:
version "1.13.0"
resolved "https://registry.yarnpkg.com/requestretry/-/requestretry-1.13.0.tgz#213ec1006eeb750e8b8ce54176283d15a8d55d94"
dependencies:
extend "^3.0.0"
lodash "^4.15.0"
request "^2.74.0"
when "^3.7.7"
require-directory@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
@ -5878,6 +5855,12 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
slack-node@^0.1.8:
version "0.1.8"
resolved "https://registry.yarnpkg.com/slack-node/-/slack-node-0.1.8.tgz#cda98de8681485b301dc6742ddc3897117fad349"
dependencies:
requestretry "^1.2.2"
slash@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"
@ -6015,12 +5998,6 @@ split-string@^3.0.1, split-string@^3.0.2:
dependencies:
extend-shallow "^3.0.0"
split@0.2.x:
version "0.2.10"
resolved "https://registry.yarnpkg.com/split/-/split-0.2.10.tgz#67097c601d697ce1368f418f06cd201cf0521a57"
dependencies:
through "2"
sprintf-js@~1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
@ -6289,7 +6266,7 @@ through2@^2.0.0:
readable-stream "^2.1.5"
xtend "~4.0.1"
through@2, through@2.3.x, through@~2.3.4:
through@~2.3.4:
version "2.3.8"
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
@ -6957,6 +6934,10 @@ webpackbar@^2.6.1:
std-env "^1.3.0"
table "^4.0.3"
when@^3.7.7:
version "3.7.8"
resolved "https://registry.yarnpkg.com/when/-/when-3.7.8.tgz#c7130b6a7ea04693e842cdc9e7a1f2aa39a39f82"
when@~3.6.x:
version "3.6.4"
resolved "https://registry.yarnpkg.com/when/-/when-3.6.4.tgz#473b517ec159e2b85005497a13983f095412e34e"