-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (37 loc) · 987 Bytes
/
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
'use strict'
const debug = require('debug')
const EventEmitter = require('events').EventEmitter
module.exports = function plugin (options) {
return new DebugPlugin(options)
}
class DebugPlugin extends EventEmitter {
constructor (options) {
if (!options) options = {}
super()
const scope = options.scope || 'telemetry'
this._debug = {}
for (const type of ['start', 'ping', 'process', 'publish', 'stop']) {
this._debug[type] = debug(`${scope}:${type}`)
}
}
start (callback) {
this._debug.start(new Date().toISOString())
process.nextTick(callback)
}
ping (callback) {
this._debug.ping(new Date().toISOString())
// No need to dezalgo ping()
callback()
}
process (metric) {
this._debug.process('%o', metric)
this.emit('metric', metric)
}
publish (metric) {
this._debug.publish('%o', metric)
}
stop (callback) {
this._debug.stop(new Date().toISOString())
process.nextTick(callback)
}
}