-
Notifications
You must be signed in to change notification settings - Fork 4
/
log.test
31 lines (29 loc) · 884 Bytes
/
log.test
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
'use strict'
const util = require('util')
const nats = require('nats')
const chalk = require('chalk')
const formats = {
create: chalk.cyan.bold
, replace: chalk.blue
, execute: chalk.blue.bold
, cancel: chalk.yellow.bold
, fail: chalk.red
, success: chalk.green.bold
, shutdown: chalk.bgYellow.white
, ready: chalk.bgGreen.white.bold
, recover: chalk.bgMagenta.bold
, rebalance: chalk.bgBlue
, purge: chalk.bgRed.white.bold
, evict: chalk.red.bold
}
var client = nats.connect({servers: ['nats://0.0.0.0:4222']})
client.subscribe('skyring:node', onNode)
client.subscribe('skyring:events', onEvent)
function onEvent(msg) {
const p = JSON.parse(msg)
console.log(util.format('[%s] timer: %s node: %s', formats[p.type](p.type), p.timer, p.node))
}
function onNode(msg) {
const p = JSON.parse(msg)
console.log((util.format('[%s] node: %s', formats[p.type](p.type), p.node)))
}