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 Error(`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 Error(`Expected object, got ${typeof config.locations} for config.locations`); |
18 | let locations = {}; |
19 | Object.keys(config.locations).forEach(function (name) { |
20 | if (typeof name != "string") throw new Error(`Expected string, got ${typeof name} for config.locations key`); |
21 | let location = config.locations[name]; |
22 | if (typeof location != "string") throw new Error(`Expected string, got ${typeof location} for config.locations value`); |
23 | locations[name] = new queue(name, location); |
24 | }); |
25 | this.locations = locations; |
26 | } |
27 | } |
28 | return this; |
29 | } |
30 |
|
31 | queue(name) { |
32 | if (typeof name != "string") throw new Error(`Expect string, got ${typeof name} for name parameter`); |
33 | if (this.location[name] == null) throw new Error(`Requested queue, ${name}, is nonexistent`); |
34 | return this.locations[name]; |
35 | } |
36 | } |
37 |
|
38 | module.exports = Logger; |
39 |
|