Skip to content

Commit

Permalink
add options for slack
Browse files Browse the repository at this point in the history
  • Loading branch information
arthur committed Mar 14, 2018
1 parent d23fbc1 commit a654402
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/service/logger.js
Expand Up @@ -9,6 +9,7 @@ const requiredConfig = [
const baseConfig = {
// default minimum log level when it's not specified
logLevel: Level.INFO,
options: {},
};

// abstract base class for different logging services
Expand Down
21 changes: 19 additions & 2 deletions src/service/slack.js
Expand Up @@ -12,6 +12,17 @@ function formatLogLevelSlackColor(logLevel) {
return ['good', 'good', 'warning', 'danger', 'danger'][logLevel];
}

function formatMessage(message, maxLine) {
if (!maxLine) {
return message;
}

return message
.split('\n')
.slice(0, maxLine)
.join('\n');
}

class SlackLogger extends Logger {
IsConfigValid() {
return super.IsConfigValid() &&
Expand All @@ -27,8 +38,14 @@ class SlackLogger extends Logger {
project,
environment,
slackChannel,
options: { fields },
} = this.config;

const {
maxLine,
short,
} = fields || {};

const logMessageFields = message.toObject();
const messageOpts = {
as_user: true,
Expand All @@ -40,8 +57,8 @@ class SlackLogger extends Logger {
.filter(key => !(key === 'message'))
.map(key => ({
title: key,
value: logMessageFields[key],
short: false,
value: formatMessage(logMessageFields[key], maxLine),
short,
})),
footer: `${project} - ${environment} - ${label}`,
},
Expand Down

0 comments on commit a654402

Please sign in to comment.