forked from eduardoboucas/staticman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.js
34 lines (26 loc) · 761 Bytes
/
Logger.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const logger = require('@dadi/logger')
const BunyanSlack = require('bunyan-slack')
const path = require('path')
const config = require(path.join(__dirname, '/../config'))
const Logger = function () {
let options = {
enabled: true,
level: 'info',
stream: process.stdout
}
if (typeof config.get('logging.slackWebhook') === 'string') {
this.formatFn = t => '```\n' + t + '\n```'
options.stream = new BunyanSlack({
webhook_url: config.get('logging.slackWebhook')
})
}
logger.init(options)
}
Logger.prototype.info = function (data) {
const formattedData = typeof this.formatFn === 'function'
? this.formatFn(data)
: data
logger.info(formattedData)
}
const instance = new Logger()
module.exports = instance