-
Notifications
You must be signed in to change notification settings - Fork 418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fabiangosebrink/adding abstract services #1422
Fabiangosebrink/adding abstract services #1422
Conversation
@timdeschryver if you have the time to review, feel free :) |
Azure Static Web Apps: Your stage site is ready! Visit it here: https://nice-hill-002425310-1422.centralus.azurestaticapps.net |
@FabianGosebrink I'll make some time for this next week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that a couple of changes already were pushed to main
(ad4b090).
This PR looks good to me and I also like the changes to the storage, this makes things consistent and flexible.
But I had something else in mind for the logger.
import { Injectable } from '@angular/core';
import { OpenIdConfiguration } from '../config/openid-configuration';
import { AbstractLoggerService } from './abstract-logger.service';
import { LogLevel } from './log-level';
@Injectable()
export class LoggerService {
+ constructor(private log: AbstractLoggerService) {}
logError(configuration: OpenIdConfiguration, message: any, ...args: any[]): void {
if (this.loggingIsTurnedOff(configuration)) {
return;
}
const { configId } = configuration;
if (!!args && !!args.length) {
- console.error(`[ERROR] ${configId} - ${message}`, ...args);
+ this.log.logError(`[ERROR] ${configId} - ${message}`, ...args);
} else {
- console.error(`[ERROR] ${configId} - ${message}`);
+ this.log.logError(`[ERROR] ${configId} - ${message}`);
}
}
logWarning(configuration: OpenIdConfiguration, message: any, ...args: any[]): void {
if (!this.logLevelIsSet(configuration)) {
return;
}
if (this.loggingIsTurnedOff(configuration)) {
return;
}
if (!this.currentLogLevelIsEqualOrSmallerThan(configuration, LogLevel.Warn)) {
return;
}
const { configId } = configuration;
if (!!args && !!args.length) {
- console.warn(`[WARN] ${configId} - ${message}`, ...args);
+ this.log.logWarning(`[WARN] ${configId} - ${message}`, ...args);
} else {
- console.warn(`[WARN] ${configId} - ${message}`);
+ this.log.logWarning(`[WARN] ${configId} - ${message}`);
}
}
logDebug(configuration: OpenIdConfiguration, message: any, ...args: any[]): void {
if (!this.logLevelIsSet(configuration)) {
return;
}
if (this.loggingIsTurnedOff(configuration)) {
return;
}
if (!this.currentLogLevelIsEqualOrSmallerThan(configuration, LogLevel.Debug)) {
return;
}
const { configId } = configuration;
if (!!args && !!args.length) {
- console.log(`[DEBUG] ${configId} - ${message}`, ...args);
+ this.log.logDebug(`[DEBUG] ${configId} - ${message}`, ...args);
} else {
- console.log(`[DEBUG] ${configId} - ${message}`);
+ this.log.logDebug(`[DEBUG] ${configId} - ${message}`);
}
}
private currentLogLevelIsEqualOrSmallerThan(configuration: OpenIdConfiguration, logLevelToCompare: LogLevel): boolean {
const { logLevel } = configuration || {};
return logLevel <= logLevelToCompare;
}
private logLevelIsSet(configuration: OpenIdConfiguration): boolean {
const { logLevel } = configuration || {};
if (logLevel === null) {
return false;
}
if (logLevel === undefined) {
return false;
}
return true;
}
private loggingIsTurnedOff(configuration: OpenIdConfiguration): boolean {
const { logLevel } = configuration || {};
return logLevel === LogLevel.None;
}
}
The reasoning behind this, is that the logger service already contains some useful checks whether that it should log or not, and these are fine. From a consumers view, I just want to use another logger implementation than console.log
.
With the current implementation we would have to rewrite that logic, which is fine if that's intended.
Thoughts?
I like that idea. That of course makes sense. With this, the user can use the checks which are already there. Will implement this and push. But with this we would need another logger service, like an |
Azure Static Web Apps: Your stage site is ready! Visit it here: https://nice-hill-002425310-1422.centralus.azurestaticapps.net |
Azure Static Web Apps: Your stage site is ready! Visit it here: https://nice-hill-002425310-1422.centralus.azurestaticapps.net |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FabianGosebrink Exactly, this is perfect! 🤩
Thanks for implementing this so quickly.
Thank you for providing such a valuable and good feedback so quickly! Thanks :) |
#1416