mirror of
https://github.com/bitwarden/browser
synced 2025-01-01 04:38:20 +01:00
log service implementation
This commit is contained in:
parent
0ad1a482b9
commit
546d1e91e2
2
jslib
2
jslib
@ -1 +1 @@
|
||||
Subproject commit 9adabdab483aa463e38382bebdad40305f4974f1
|
||||
Subproject commit b747830c5b4360bf50d6e02126ebaab24e3028d5
|
@ -11,6 +11,7 @@ import { DesktopPlatformUtilsService } from '../../services/desktopPlatformUtils
|
||||
import { DesktopRendererMessagingService } from '../../services/desktopRendererMessaging.service';
|
||||
import { DesktopRendererSecureStorageService } from '../../services/desktopRendererSecureStorage.service';
|
||||
import { DesktopStorageService } from '../../services/desktopStorage.service';
|
||||
import { LogService } from '../../services/log.service';
|
||||
import { I18nService } from '../../services/i18n.service';
|
||||
|
||||
import { AuthGuardService } from './auth-guard.service';
|
||||
@ -49,6 +50,7 @@ import { EnvironmentService as EnvironmentServiceAbstraction } from 'jslib/abstr
|
||||
import { FolderService as FolderServiceAbstraction } from 'jslib/abstractions/folder.service';
|
||||
import { I18nService as I18nServiceAbstraction } from 'jslib/abstractions/i18n.service';
|
||||
import { LockService as LockServiceAbstraction } from 'jslib/abstractions/lock.service';
|
||||
import { LogService as LogServiceAbstraction } from 'jslib/abstractions/log.service';
|
||||
import { MessagingService as MessagingServiceAbstraction } from 'jslib/abstractions/messaging.service';
|
||||
import {
|
||||
PasswordGenerationService as PasswordGenerationServiceAbstraction,
|
||||
@ -63,6 +65,7 @@ import { TotpService as TotpServiceAbstraction } from 'jslib/abstractions/totp.s
|
||||
import { UserService as UserServiceAbstraction } from 'jslib/abstractions/user.service';
|
||||
import { UtilsService as UtilsServiceAbstraction } from 'jslib/abstractions/utils.service';
|
||||
|
||||
const logService = new LogService();
|
||||
const i18nService = new I18nService(window.navigator.language, './locales');
|
||||
const utilsService = new UtilsService();
|
||||
const stateService = new StateService();
|
||||
@ -161,6 +164,7 @@ function initFactory(): Function {
|
||||
{ provide: LockServiceAbstraction, useValue: lockService },
|
||||
{ provide: StorageServiceAbstraction, useValue: storageService },
|
||||
{ provide: StateServiceAbstraction, useValue: stateService },
|
||||
{ provide: LogServiceAbstraction, useValue: logService },
|
||||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: initFactory,
|
||||
|
@ -4,6 +4,7 @@ import * as path from 'path';
|
||||
import { DesktopMainMessagingService } from './services/desktopMainMessaging.service';
|
||||
import { DesktopStorageService } from './services/desktopStorage.service';
|
||||
import { I18nService } from './services/i18n.service';
|
||||
import { LogService } from './services/log.service';
|
||||
|
||||
import { MenuMain } from './main/menu.main';
|
||||
import { MessagingMain } from './main/messaging.main';
|
||||
@ -15,6 +16,7 @@ import { WindowMain } from './main/window.main';
|
||||
const osLocale = require('os-locale');
|
||||
|
||||
export class Main {
|
||||
logService: LogService;
|
||||
i18nService: I18nService;
|
||||
storageService: DesktopStorageService;
|
||||
messagingService: DesktopMainMessagingService;
|
||||
@ -38,8 +40,8 @@ export class Main {
|
||||
|
||||
if (appDataPath != null) {
|
||||
app.setPath('userData', appDataPath);
|
||||
app.setPath('logs', path.join(appDataPath, 'logs'));
|
||||
}
|
||||
app.setPath('logs', path.join(app.getPath('userData'), 'logs'));
|
||||
|
||||
const args = process.argv.slice(1);
|
||||
const watch = args.some((val) => val === '--watch');
|
||||
@ -49,6 +51,7 @@ export class Main {
|
||||
require('electron-reload')(__dirname, {});
|
||||
}
|
||||
|
||||
this.logService = new LogService(null, app.getPath('logs'));
|
||||
this.i18nService = new I18nService('en', './locales/');
|
||||
this.storageService = new DesktopStorageService();
|
||||
this.messagingService = new DesktopMainMessagingService(this);
|
||||
|
59
src/services/log.service.ts
Normal file
59
src/services/log.service.ts
Normal file
@ -0,0 +1,59 @@
|
||||
import log from 'electron-log';
|
||||
import * as path from 'path';
|
||||
|
||||
import { isDev } from '../scripts/utils';
|
||||
|
||||
import { LogLevelType } from 'jslib/enums/logLevelType';
|
||||
|
||||
import { LogService as LogServiceAbstraction } from 'jslib/abstractions/log.service';
|
||||
|
||||
export class LogService implements LogServiceAbstraction {
|
||||
constructor(private filter: (level: LogLevelType) => boolean = null, logDir: string = null) {
|
||||
if (logDir != null) {
|
||||
log.transports.file.file = path.join(logDir, 'app.log');
|
||||
}
|
||||
}
|
||||
|
||||
debug(message: string) {
|
||||
if (!isDev()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.write(LogLevelType.Debug, message);
|
||||
}
|
||||
|
||||
info(message: string) {
|
||||
this.write(LogLevelType.Info, message);
|
||||
}
|
||||
|
||||
warning(message: string) {
|
||||
this.write(LogLevelType.Warning, message);
|
||||
}
|
||||
|
||||
error(message: string) {
|
||||
this.write(LogLevelType.Error, message);
|
||||
}
|
||||
|
||||
write(level: LogLevelType, message: string) {
|
||||
if (this.filter != null && this.filter(level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (level) {
|
||||
case LogLevelType.Debug:
|
||||
log.debug(message);
|
||||
break;
|
||||
case LogLevelType.Info:
|
||||
log.info(message);
|
||||
break;
|
||||
case LogLevelType.Warning:
|
||||
log.warn(message);
|
||||
break;
|
||||
case LogLevelType.Error:
|
||||
log.error(message);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user