1 | const statement = require("./statement.js"); |
2 | const event = require("./event.js"); |
3 | const queue = require("./queue.js"); |
4 |
|
5 | class Logger { |
6 | constructor(config) { |
7 | this.name = "Logger"; |
8 | this.locations = { |
9 | "node": "./log/node" |
10 | } |
11 | if (config) { |
12 | if (config.name) { |
13 | if (typeof config.name != "string") throw new TypeError(`Expected string, got ${typeof config.name} for config.name`); |
14 | this.name = config.name; |
15 | } |
16 | if (config.locations) { |
17 | if (typeof config.locations != "object") throw new TypeError(`Expected object, got ${typeof config.locations} for config.locations`); |
18 | let locations = {}; |
19 | Object.keys(config.locations).forEach(function (name) { |
20 | let location = config.locations[name]; |
21 | if (typeof location != "string") throw new TypeError(`Expected string, got ${typeof location} for config.locations value`); |
22 | locations[name] = new queue(name, location); |
23 | }); |
24 | this.locations = locations; |
25 | } |
26 | } |
27 | return this; |
28 | } |
29 |
|
30 | queue(name) { |
31 | if (typeof name != "string") throw new TypeError(`Expect string, got ${typeof name} for name parameter`); |
32 | if (this.locations[name] == null) throw new TypeError(`Requested queue, ${name}, is nonexistent`); |
33 | return this.locations[name]; |
34 | } |
35 | } |
36 |
|
37 | module.exports = Logger; |
38 |
|