1 | const Isochronous = require('isochronous')
|
2 | const Publisher = require('prolific.queue/publisher')
|
3 |
|
4 | class Logger {
|
5 | constructor (destructible, Date, directory, pid, interval) {
|
6 | this._entries = []
|
7 | this._publisher = new Publisher(Date, directory, pid)
|
8 | this._Date = Date
|
9 | const isochornous = new Isochronous(interval, true, this._flush.bind(this))
|
10 | destructible.durable('isochornous', isochornous.start())
|
11 | destructible.destruct(() => isochornous.stop())
|
12 | destructible.destruct(() => this._flush())
|
13 | }
|
14 |
|
15 | say (label, entry) {
|
16 | this._entries.push({ when: this._Date.now(), qualifier: 'prolific', label, ...entry })
|
17 | }
|
18 |
|
19 | _flush () {
|
20 | if (this._entries.length != 0) {
|
21 | this._publisher.publish({ method: 'say', entries: this._entries.splice(0) })
|
22 | }
|
23 | }
|
24 | }
|
25 |
|
26 | module.exports = Logger
|