mirror of
https://github.com/bitwarden/jslib
synced 2025-12-28 22:23:14 +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:
@@ -18,7 +18,7 @@ export abstract class BaseProgram {
|
||||
if (!response.success) {
|
||||
if (process.env.BW_QUIET !== 'true') {
|
||||
if (process.env.BW_RESPONSE === 'true') {
|
||||
this.writeLn(this.getJson(response), true, true);
|
||||
this.writeLn(this.getJson(response), true, false);
|
||||
} else {
|
||||
this.writeLn(chalk.redBright(response.message), true, true);
|
||||
}
|
||||
|
||||
@@ -1,27 +1,10 @@
|
||||
import { LogLevelType } from '../../enums/logLevelType';
|
||||
|
||||
import { LogService as LogServiceAbstraction } from '../../abstractions/log.service';
|
||||
import { ConsoleLogService as BaseConsoleLogService } from '../../services/consoleLog.service';
|
||||
|
||||
export class ConsoleLogService implements LogServiceAbstraction {
|
||||
constructor(private isDev: boolean, private filter: (level: LogLevelType) => boolean = null) { }
|
||||
|
||||
debug(message: string) {
|
||||
if (!this.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);
|
||||
export class ConsoleLogService extends BaseConsoleLogService {
|
||||
constructor(isDev: boolean, filter: (level: LogLevelType) => boolean = null) {
|
||||
super(isDev, filter);
|
||||
}
|
||||
|
||||
write(level: LogLevelType, message: string) {
|
||||
@@ -29,25 +12,12 @@ export class ConsoleLogService implements LogServiceAbstraction {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (level) {
|
||||
case LogLevelType.Debug:
|
||||
// tslint:disable-next-line
|
||||
console.log(message);
|
||||
break;
|
||||
case LogLevelType.Info:
|
||||
// tslint:disable-next-line
|
||||
console.log(message);
|
||||
break;
|
||||
case LogLevelType.Warning:
|
||||
// tslint:disable-next-line
|
||||
console.warn(message);
|
||||
break;
|
||||
case LogLevelType.Error:
|
||||
// tslint:disable-next-line
|
||||
console.error(message);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
if (process.env.BW_RESPONSE) {
|
||||
// tslint:disable-next-line
|
||||
console.error(message);
|
||||
return;
|
||||
}
|
||||
|
||||
super.write(level, message);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user