diff options
author | Kristóf Marussy <kristof@marussy.com> | 2021-12-31 01:52:28 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2021-12-31 01:56:30 +0100 |
commit | 7108c642f4ff6dc5f0c4d30b8a8960064ff8e90f (patch) | |
tree | f8c0450a6e1b62f7e7f8470efd375b3659b91b2b /packages/main/src/utils/logging.ts | |
parent | refactor: Install devtools extensions earlier (diff) | |
download | sophie-7108c642f4ff6dc5f0c4d30b8a8960064ff8e90f.tar.gz sophie-7108c642f4ff6dc5f0c4d30b8a8960064ff8e90f.tar.zst sophie-7108c642f4ff6dc5f0c4d30b8a8960064ff8e90f.zip |
test: Add tests for main package
- Changed jest to run from the root package and reference the packages
as projects. This required moving the base jest config file away from
the project root.
- Module isolation seems to prevent ts-jest from loading the shared
package, so we disabled it for now.
- To better facilitate mocking, services should be split into interfaces
and implementation
- Had to downgrade to chald 4.1.2 as per
https://github.com/chalk/chalk/releases/tag/v5.0.0 at least until
https://github.com/microsoft/TypeScript/issues/46452 is resolved.
Diffstat (limited to 'packages/main/src/utils/logging.ts')
-rw-r--r-- | packages/main/src/utils/logging.ts | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/packages/main/src/utils/logging.ts b/packages/main/src/utils/logging.ts index 6c4cba2..ed40365 100644 --- a/packages/main/src/utils/logging.ts +++ b/packages/main/src/utils/logging.ts | |||
@@ -18,17 +18,17 @@ | |||
18 | * SPDX-License-Identifier: AGPL-3.0-only | 18 | * SPDX-License-Identifier: AGPL-3.0-only |
19 | */ | 19 | */ |
20 | 20 | ||
21 | import chalk, { ChalkInstance } from 'chalk'; | 21 | import chalk, { Chalk } from 'chalk'; |
22 | import loglevel, { Logger } from 'loglevel'; | 22 | import loglevel, { Logger } from 'loglevel'; |
23 | import prefix from 'loglevel-plugin-prefix'; | 23 | import prefix from 'loglevel-plugin-prefix'; |
24 | 24 | ||
25 | if (import.meta.env.DEV) { | 25 | if (import.meta.env?.DEV) { |
26 | loglevel.setLevel('debug'); | 26 | loglevel.setLevel('debug'); |
27 | } else { | 27 | } else { |
28 | loglevel.setLevel('info'); | 28 | loglevel.setLevel('info'); |
29 | } | 29 | } |
30 | 30 | ||
31 | const COLORS: Partial<Record<string, ChalkInstance>> = { | 31 | const COLORS: Partial<Record<string, Chalk>> = { |
32 | TRACE: chalk.magenta, | 32 | TRACE: chalk.magenta, |
33 | DEBUG: chalk.cyan, | 33 | DEBUG: chalk.cyan, |
34 | INFO: chalk.blue, | 34 | INFO: chalk.blue, |
@@ -37,7 +37,7 @@ const COLORS: Partial<Record<string, ChalkInstance>> = { | |||
37 | CRITICAL: chalk.red, | 37 | CRITICAL: chalk.red, |
38 | }; | 38 | }; |
39 | 39 | ||
40 | function getColor(level: string): ChalkInstance { | 40 | function getColor(level: string): Chalk { |
41 | return COLORS[level] ?? chalk.gray; | 41 | return COLORS[level] ?? chalk.gray; |
42 | } | 42 | } |
43 | 43 | ||
@@ -52,3 +52,11 @@ prefix.apply(loglevel, { | |||
52 | export function getLogger(loggerName: string): Logger { | 52 | export function getLogger(loggerName: string): Logger { |
53 | return loglevel.getLogger(loggerName); | 53 | return loglevel.getLogger(loggerName); |
54 | } | 54 | } |
55 | |||
56 | export function silenceLogger(): void { | ||
57 | loglevel.disableAll(); | ||
58 | const loggers = loglevel.getLoggers(); | ||
59 | for (const loggerName of Object.keys(loggers)) { | ||
60 | loggers[loggerName].disableAll(); | ||
61 | } | ||
62 | } | ||