-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (44 loc) · 1.06 KB
/
index.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict'
const axios = require('axios')
const BASE_URI = 'https://us.js.logs.insight.rapid7.com'
const POST_PATH = '/v1/logs/'
const LOG_LEVEL = {
LOG: 'LOG',
WARN: 'WARN',
ERROR: 'ERROR',
INFO: 'INFO'
}
const Logger = ({ token, level, message, data }) => {
return axios.post(
`${BASE_URI}${POST_PATH}${token}`,
{
level,
event: {
message,
stringify: JSON.stringify(data)
}
},
{
headers: {
'Content-Type': 'application/json'
}
}
)
}
const logger = token => {
const log = ({ message, data }) =>
Logger({ token: token, level: LOG_LEVEL.LOG, message, data })
const warm = ({ message, data }) =>
Logger({ token: token, level: LOG_LEVEL.WARN, message, data })
const error = ({ message, data }) =>
Logger({ token: token, level: LOG_LEVEL.ERROR, message, data })
const info = ({ message, data }) =>
Logger({ token: token, level: LOG_LEVEL.INFO, message, data })
return {
log,
warm,
error,
info
}
}
module.exports = { Logger, logger, LOG_LEVEL }