-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.js
43 lines (37 loc) · 880 Bytes
/
log.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
const bunyan = require('bunyan')
const prettyStream = require('bunyan-prettystream')
const stream = require('stream')
const fetch = require('node-fetch')
const out_pretty = new prettyStream
out_pretty.pipe(process.stdout)
// const remote_url = 'http://45.55.38.183:4002/log'
const remote_url = "http://45.55.38.183:4002/log"
const remote = new stream.Writable({
write: async function(chunk, encoding, next){
fetch(remote_url, {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: "POST",
body: JSON.stringify({ event: "LOG", data: chunk.toString('utf8'), sender: "DOOR" })
}).catch(err => {})
next()
}
})
const log = bunyan.createLogger({
name: "door",
streams: [
{
level: 'debug',
type: 'raw',
stream: out_pretty
},
{
level: 'info',
type: 'stream',
stream: remote
}
]
})
module.exports = log