diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-05-03 19:47:39 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-05-16 00:55:02 +0200 |
commit | d2aa484b600dc0d122bb994b9bb29504ffe4cf12 (patch) | |
tree | 1d3e38fdb22f7afe02f1ebcf4b07734761970985 /packages/main/src/utils/log.ts | |
parent | refactor: config file saving and debugging (diff) | |
download | sophie-d2aa484b600dc0d122bb994b9bb29504ffe4cf12.tar.gz sophie-d2aa484b600dc0d122bb994b9bb29504ffe4cf12.tar.zst sophie-d2aa484b600dc0d122bb994b9bb29504ffe4cf12.zip |
build: integration testing support
Run integration tests in an electron environment for the main process.
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/main/src/utils/log.ts')
-rw-r--r-- | packages/main/src/utils/log.ts | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/packages/main/src/utils/log.ts b/packages/main/src/utils/log.ts deleted file mode 100644 index d9748f4..0000000 --- a/packages/main/src/utils/log.ts +++ /dev/null | |||
@@ -1,64 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2021-2022 Kristóf Marussy <kristof@marussy.com> | ||
3 | * | ||
4 | * This file is part of Sophie. | ||
5 | * | ||
6 | * Sophie is free software: you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU Affero General Public License as | ||
8 | * published by the Free Software Foundation, version 3. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Affero General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Affero General Public License | ||
16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
17 | * | ||
18 | * SPDX-License-Identifier: AGPL-3.0-only | ||
19 | */ | ||
20 | |||
21 | // eslint-disable-next-line unicorn/import-style -- Import the type `ChalkInstance` separately. | ||
22 | import chalk, { ChalkInstance } from 'chalk'; | ||
23 | import loglevel from 'loglevel'; | ||
24 | import prefix from 'loglevel-plugin-prefix'; | ||
25 | |||
26 | if (import.meta.env?.DEV) { | ||
27 | loglevel.setLevel('debug'); | ||
28 | } else { | ||
29 | loglevel.setLevel('info'); | ||
30 | } | ||
31 | |||
32 | const COLORS: Map<string, ChalkInstance> = new Map([ | ||
33 | ['TRACE', chalk.magenta], | ||
34 | ['DEBUG', chalk.cyan], | ||
35 | ['INFO', chalk.blue], | ||
36 | ['WARN', chalk.yellow], | ||
37 | ['ERROR', chalk.red], | ||
38 | ['CRITICAL', chalk.red], | ||
39 | ]); | ||
40 | |||
41 | prefix.reg(loglevel); | ||
42 | prefix.apply(loglevel, { | ||
43 | format(level, name, timestamp) { | ||
44 | const levelColor = COLORS.get(level) ?? chalk.gray; | ||
45 | const timeStr = timestamp.toString(); | ||
46 | const nameStr = | ||
47 | typeof name === 'undefined' | ||
48 | ? levelColor(':') | ||
49 | : ` ${chalk.green(`${name}:`)}`; | ||
50 | return `${chalk.gray(`[${timeStr}]`)} ${levelColor(level)}${nameStr}`; | ||
51 | }, | ||
52 | }); | ||
53 | |||
54 | export function getLogger(loggerName: string): loglevel.Logger { | ||
55 | return loglevel.getLogger(loggerName); | ||
56 | } | ||
57 | |||
58 | export function silenceLogger(): void { | ||
59 | loglevel.disableAll(); | ||
60 | const loggers = loglevel.getLoggers(); | ||
61 | Object.values(loggers).forEach((logger) => { | ||
62 | logger.disableAll(); | ||
63 | }); | ||
64 | } | ||