diff options
Diffstat (limited to 'packages/main/src')
-rw-r--r-- | packages/main/src/controllers/config.ts | 7 | ||||
-rw-r--r-- | packages/main/src/controllers/nativeTheme.ts | 5 | ||||
-rw-r--r-- | packages/main/src/utils/index.ts (renamed from packages/main/src/utils.ts) | 2 | ||||
-rw-r--r-- | packages/main/src/utils/logging.ts | 49 |
4 files changed, 56 insertions, 7 deletions
diff --git a/packages/main/src/controllers/config.ts b/packages/main/src/controllers/config.ts index b6aba35..7187ab4 100644 --- a/packages/main/src/controllers/config.ts +++ b/packages/main/src/controllers/config.ts | |||
@@ -18,18 +18,17 @@ | |||
18 | * SPDX-License-Identifier: AGPL-3.0-only | 18 | * SPDX-License-Identifier: AGPL-3.0-only |
19 | */ | 19 | */ |
20 | 20 | ||
21 | import consola from 'consola'; | ||
22 | import { debounce } from 'lodash'; | 21 | import { debounce } from 'lodash'; |
23 | import ms from 'ms'; | 22 | import ms from 'ms'; |
24 | import { applySnapshot, getSnapshot, onSnapshot } from 'mobx-state-tree'; | 23 | import { applySnapshot, getSnapshot, onSnapshot } from 'mobx-state-tree'; |
25 | 24 | ||
26 | import type { ConfigPersistenceService } from '../services/ConfigPersistenceService'; | 25 | import type { ConfigPersistenceService } from '../services/ConfigPersistenceService'; |
27 | import type { Config, ConfigSnapshotOut } from '../stores/Config'; | 26 | import type { Config, ConfigSnapshotOut } from '../stores/Config'; |
28 | import { Disposer } from '../utils'; | 27 | import { Disposer, getLogger } from '../utils'; |
29 | 28 | ||
30 | const DEFAULT_CONFIG_DEBOUNCE_TIME = ms('1s'); | 29 | const DEFAULT_CONFIG_DEBOUNCE_TIME = ms('1s'); |
31 | 30 | ||
32 | const logger = consola.withTag('sophie:controller:config'); | 31 | const logger = getLogger('controller:config'); |
33 | 32 | ||
34 | export async function initConfig( | 33 | export async function initConfig( |
35 | config: Config, | 34 | config: Config, |
@@ -71,7 +70,7 @@ export async function initConfig( | |||
71 | logger.info('Config file was not found'); | 70 | logger.info('Config file was not found'); |
72 | try { | 71 | try { |
73 | await writeConfig(); | 72 | await writeConfig(); |
74 | logger.success('Created config file'); | 73 | logger.info('Created config file'); |
75 | } catch (err) { | 74 | } catch (err) { |
76 | logger.error('Failed to initialize config'); | 75 | logger.error('Failed to initialize config'); |
77 | } | 76 | } |
diff --git a/packages/main/src/controllers/nativeTheme.ts b/packages/main/src/controllers/nativeTheme.ts index 6548771..9f9bc21 100644 --- a/packages/main/src/controllers/nativeTheme.ts +++ b/packages/main/src/controllers/nativeTheme.ts | |||
@@ -18,14 +18,13 @@ | |||
18 | * SPDX-License-Identifier: AGPL-3.0-only | 18 | * SPDX-License-Identifier: AGPL-3.0-only |
19 | */ | 19 | */ |
20 | 20 | ||
21 | import consola from 'consola'; | ||
22 | import { nativeTheme } from 'electron'; | 21 | import { nativeTheme } from 'electron'; |
23 | import { autorun } from 'mobx'; | 22 | import { autorun } from 'mobx'; |
24 | 23 | ||
25 | import type { MainStore } from '../stores/MainStore'; | 24 | import type { MainStore } from '../stores/MainStore'; |
26 | import { Disposer } from '../utils'; | 25 | import { Disposer, getLogger } from '../utils'; |
27 | 26 | ||
28 | const logger = consola.withTag('sophie:controller:nativeTheme'); | 27 | const logger = getLogger('controller:nativeTheme'); |
29 | 28 | ||
30 | export function initNativeTheme(store: MainStore): Disposer { | 29 | export function initNativeTheme(store: MainStore): Disposer { |
31 | logger.debug('Initializing controller'); | 30 | logger.debug('Initializing controller'); |
diff --git a/packages/main/src/utils.ts b/packages/main/src/utils/index.ts index 0d469dd..9a57e02 100644 --- a/packages/main/src/utils.ts +++ b/packages/main/src/utils/index.ts | |||
@@ -21,3 +21,5 @@ | |||
21 | import { IDisposer } from 'mobx-state-tree'; | 21 | import { IDisposer } from 'mobx-state-tree'; |
22 | 22 | ||
23 | export type Disposer = IDisposer; | 23 | export type Disposer = IDisposer; |
24 | |||
25 | export { getLogger } from './logging'; | ||
diff --git a/packages/main/src/utils/logging.ts b/packages/main/src/utils/logging.ts new file mode 100644 index 0000000..9f1133f --- /dev/null +++ b/packages/main/src/utils/logging.ts | |||
@@ -0,0 +1,49 @@ | |||
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 | import loglevel, { Logger } from 'loglevel'; | ||
22 | import prefix from 'loglevel-plugin-prefix'; | ||
23 | |||
24 | const isDevelopment = import.meta.env.MODE === 'development'; | ||
25 | |||
26 | if (isDevelopment) { | ||
27 | loglevel.enableAll(); | ||
28 | } | ||
29 | |||
30 | prefix.reg(loglevel); | ||
31 | prefix.apply(loglevel, { | ||
32 | format(level, name, timestamp) { | ||
33 | let shortName = 'global'; | ||
34 | if (name !== undefined) { | ||
35 | const nameSegments = name.split(':'); | ||
36 | const lastSegment = nameSegments.pop(); | ||
37 | shortName = [...nameSegments.map((segment) => segment[0]), lastSegment].join(':'); | ||
38 | } | ||
39 | if (isDevelopment) { | ||
40 | // `watch.js` already appends timestamps. | ||
41 | return `${level} (${shortName})`; | ||
42 | } | ||
43 | return `[${timestamp}] ${level} (${shortName})`; | ||
44 | }, | ||
45 | }); | ||
46 | |||
47 | export function getLogger(loggerName: string): Logger { | ||
48 | return loglevel.getLogger(`sophie:${loggerName}`); | ||
49 | } | ||