-
Notifications
You must be signed in to change notification settings - Fork 19
/
setup.ts
50 lines (45 loc) · 1019 Bytes
/
setup.ts
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
49
50
import * as log from "std/log/mod.ts";
import { getLevelByName } from "std/log/levels.ts";
import { setup } from "pls";
const level = (() => {
let toReturn = "INFO";
try {
const level = Deno.env.get("LOG_LEVEL");
if (level) {
// deno-lint-ignore no-explicit-any
getLevelByName(level as any);
toReturn = level;
}
} catch (_err) {
//
}
return toReturn as log.LevelName;
})();
await log.setup({
handlers: {
console: new log.handlers.ConsoleHandler(level),
file: new log.handlers.FileHandler(level, {
filename: ".log",
mode: "a",
}),
},
loggers: {
default: {
handlers: ["console", "file"],
},
},
});
let connected = false;
if (Deno.env.get("PLS_CONNECTION_URI")) {
try {
await setup({ include: [/^module_/] });
connected = true;
} catch (err) {
log.warning(`could not connect to the database: ${err}`);
}
}
if (connected) {
log.info("connected to the database");
} else {
log.info("not using database");
}