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 | let 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 | locations = config.locations; |
19 | } |
20 | } |
21 | Object.keys(locations).forEach(function (name) { |
22 | let location = locations[name]; |
23 | if (typeof location != "string") throw new TypeError(`Expected string, got ${typeof location} for location`); |
24 | locations[name] = new queue(name, location); |
25 | }); |
26 | this.locations = locations; |
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 |
|