mirror of
https://github.com/bitwarden/browser
synced 2025-12-25 20:53:22 +00:00
Use logService for console messages (#214)
* Use logService for console messages * linter autofixes * Use full import path * Implement a base ConsoleLog service Use this class as a default for other services that would like to output to console. This service is overriden in CLI and Desktop to use CLI's consoleLogService and electronLogService, respectively. * linter fixes Co-authored-by: Matt Gibson <mdgibson@Matts-MBP.lan>
This commit is contained in:
@@ -8,6 +8,8 @@ import { LogLevelType } from '../../enums/logLevelType';
|
||||
import { LogService as LogServiceAbstraction } from '../../abstractions/log.service';
|
||||
|
||||
export class ElectronLogService implements LogServiceAbstraction {
|
||||
private timersMap: Map<string, bigint> = new Map();
|
||||
|
||||
constructor(private filter: (level: LogLevelType) => boolean = null, logDir: string = null) {
|
||||
if (log.transports == null) {
|
||||
return;
|
||||
@@ -61,4 +63,17 @@ export class ElectronLogService implements LogServiceAbstraction {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
time(label: string = 'default') {
|
||||
if (!this.timersMap.has(label)) {
|
||||
this.timersMap.set(label, process.hrtime.bigint());
|
||||
}
|
||||
}
|
||||
|
||||
timeEnd(label: string = 'default'): bigint {
|
||||
const elapsed = (process.hrtime.bigint() - this.timersMap.get(label)) / BigInt(1000000);
|
||||
this.timersMap.delete(label);
|
||||
this.write(LogLevelType.Info, `${label}: ${elapsed}ms`);
|
||||
return elapsed;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user