Skip to content

Commit

Permalink
refactor(@angular/ssr): move ignored messages as a global
Browse files Browse the repository at this point in the history
Refactored the ignored log messages into a global constant.

(cherry picked from commit 6eed460)
  • Loading branch information
alan-agius4 committed Dec 11, 2024
1 parent 251bd9f commit 544d139
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/angular/ssr/src/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@

import { ɵConsole } from '@angular/core';

/**
* A set of log messages that should be ignored and not printed to the console.
*/
const IGNORED_LOGS = new Set(['Angular is running in development mode.']);

/**
* Custom implementation of the Angular Console service that filters out specific log messages.
*
* This class extends the internal Angular `ɵConsole` class to provide customized logging behavior.
* It overrides the `log` method to suppress logs that match certain predefined messages.
*/
export class Console extends ɵConsole {
/**
* A set of log messages that should be ignored and not printed to the console.
*/
private readonly ignoredLogs = new Set(['Angular is running in development mode.']);

/**
* Logs a message to the console if it is not in the set of ignored messages.
*
* @param message - The message to log to the console.
*
* This method overrides the `log` method of the `ɵConsole` class. It checks if the
* message is in the `ignoredLogs` set. If it is not, it delegates the logging to
* message is in the `IGNORED_LOGS` set. If it is not, it delegates the logging to
* the parent class's `log` method. Otherwise, the message is suppressed.
*/
override log(message: string): void {
if (!this.ignoredLogs.has(message)) {
if (!IGNORED_LOGS.has(message)) {
super.log(message);
}
}
Expand Down
4 changes: 4 additions & 0 deletions packages/angular/ssr/src/routes/ng-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,11 @@ export async function getRoutesFromAngularRouterConfig(
useValue: { document, url: `${protocol}//${host}/` },
},
{
// An Angular Console Provider that does not print a set of predefined logs.
provide: ɵConsole,
// Using `useClass` would necessitate decorating `Console` with `@Injectable`,
// which would require switching from `ts_library` to `ng_module`. This change
// would also necessitate various patches of `@angular/bazel` to support ESM.
useFactory: () => new Console(),
},
]);
Expand Down

0 comments on commit 544d139

Please sign in to comment.