Skip to content

Commit

Permalink
fix(logger): add logger ignoreRule
Browse files Browse the repository at this point in the history
  • Loading branch information
unadlib committed Dec 18, 2024
1 parent e55974d commit 869ba46
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/logger/src/transports/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,34 @@ export class ConsoleTransport implements ITransport {

protected _consoleWrite: LogWriter;

protected _ignoreRules: RegExp[] = [];

constructor(
protected _options?: {
/**
* By default the console transport is disabled.
*/
enabled?: boolean;
/**
* By default all logs are displayed.
*/
filter?: string;
/**
* The storage to save the log.
*/
storage?: Storage;
/**
* Ignore logs that match the rules.
*/
ignoreRule?: string[];
}
) {
this._consoleWrite = createLogWriter({
storage: this._options?.storage,
});
this._ignoreRules = (this._options?.ignoreRule ?? []).map(
(rule) => new RegExp(rule)
);
}

protected get _storage() {
Expand All @@ -48,6 +66,7 @@ export class ConsoleTransport implements ITransport {
}

write({ message }: SerializedMessage) {
if (this._ignoreRules.some((regex) => regex.test(message))) return;
if (this._options?.enabled) {
this._consoleWrite(message);
}
Expand Down

0 comments on commit 869ba46

Please sign in to comment.