mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
[ADF-1723] log service fix debug scenario
This commit is contained in:
parent
834b8a98a2
commit
c9dbd41047
@ -49,16 +49,25 @@ describe('Log Service', () => {
|
||||
providesLogComponent = TestBed.createComponent(ProvidesLogComponent);
|
||||
|
||||
spyOn(console, 'log');
|
||||
spyOn(console, 'error');
|
||||
spyOn(console, 'trace');
|
||||
spyOn(console, 'debug');
|
||||
spyOn(console, 'info');
|
||||
spyOn(console, 'warn');
|
||||
spyOn(console, 'error');
|
||||
|
||||
providesLogComponent.componentInstance.log();
|
||||
providesLogComponent.componentInstance.error();
|
||||
providesLogComponent.componentInstance.trace();
|
||||
providesLogComponent.componentInstance.debug();
|
||||
providesLogComponent.componentInstance.info();
|
||||
providesLogComponent.componentInstance.warn();
|
||||
providesLogComponent.componentInstance.error();
|
||||
|
||||
expect(console.log).toHaveBeenCalled();
|
||||
expect(console.error).toHaveBeenCalled();
|
||||
expect(console.trace).toHaveBeenCalled();
|
||||
expect(console.debug).toHaveBeenCalled();
|
||||
expect(console.info).toHaveBeenCalled();
|
||||
expect(console.warn).toHaveBeenCalled();
|
||||
expect(console.error).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not log anything if is silent', () => {
|
||||
@ -66,16 +75,25 @@ describe('Log Service', () => {
|
||||
providesLogComponent = TestBed.createComponent(ProvidesLogComponent);
|
||||
|
||||
spyOn(console, 'log');
|
||||
spyOn(console, 'error');
|
||||
spyOn(console, 'trace');
|
||||
spyOn(console, 'debug');
|
||||
spyOn(console, 'info');
|
||||
spyOn(console, 'warn');
|
||||
spyOn(console, 'error');
|
||||
|
||||
providesLogComponent.componentInstance.log();
|
||||
providesLogComponent.componentInstance.error();
|
||||
providesLogComponent.componentInstance.trace();
|
||||
providesLogComponent.componentInstance.debug();
|
||||
providesLogComponent.componentInstance.info();
|
||||
providesLogComponent.componentInstance.warn();
|
||||
providesLogComponent.componentInstance.error();
|
||||
|
||||
expect(console.log).not.toHaveBeenCalled();
|
||||
expect(console.error).not.toHaveBeenCalled();
|
||||
expect(console.trace).not.toHaveBeenCalled();
|
||||
expect(console.debug).not.toHaveBeenCalled();
|
||||
expect(console.info).not.toHaveBeenCalled();
|
||||
expect(console.warn).not.toHaveBeenCalled();
|
||||
expect(console.error).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should log only warning and errors if is warning level', () => {
|
||||
@ -98,6 +116,58 @@ describe('Log Service', () => {
|
||||
expect(console.trace).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should debug level not log trace and log', () => {
|
||||
appConfigService.config['logLevel'] = 'debug';
|
||||
providesLogComponent = TestBed.createComponent(ProvidesLogComponent);
|
||||
|
||||
spyOn(console, 'log');
|
||||
spyOn(console, 'trace');
|
||||
spyOn(console, 'debug');
|
||||
spyOn(console, 'info');
|
||||
spyOn(console, 'warn');
|
||||
spyOn(console, 'error');
|
||||
|
||||
providesLogComponent.componentInstance.log();
|
||||
providesLogComponent.componentInstance.trace();
|
||||
providesLogComponent.componentInstance.debug();
|
||||
providesLogComponent.componentInstance.info();
|
||||
providesLogComponent.componentInstance.warn();
|
||||
providesLogComponent.componentInstance.error();
|
||||
|
||||
expect(console.log).not.toHaveBeenCalled();
|
||||
expect(console.trace).not.toHaveBeenCalled();
|
||||
expect(console.debug).toHaveBeenCalled();
|
||||
expect(console.info).toHaveBeenCalled();
|
||||
expect(console.warn).toHaveBeenCalled();
|
||||
expect(console.error).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should trace level log all', () => {
|
||||
appConfigService.config['logLevel'] = 'trace';
|
||||
providesLogComponent = TestBed.createComponent(ProvidesLogComponent);
|
||||
|
||||
spyOn(console, 'log');
|
||||
spyOn(console, 'trace');
|
||||
spyOn(console, 'debug');
|
||||
spyOn(console, 'info');
|
||||
spyOn(console, 'warn');
|
||||
spyOn(console, 'error');
|
||||
|
||||
providesLogComponent.componentInstance.log();
|
||||
providesLogComponent.componentInstance.trace();
|
||||
providesLogComponent.componentInstance.debug();
|
||||
providesLogComponent.componentInstance.info();
|
||||
providesLogComponent.componentInstance.warn();
|
||||
providesLogComponent.componentInstance.error();
|
||||
|
||||
expect(console.log).toHaveBeenCalled();
|
||||
expect(console.trace).toHaveBeenCalled();
|
||||
expect(console.debug).toHaveBeenCalled();
|
||||
expect(console.info).toHaveBeenCalled();
|
||||
expect(console.warn).toHaveBeenCalled();
|
||||
expect(console.error).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@Component({
|
||||
@ -125,6 +195,10 @@ class ProvidesLogComponent {
|
||||
this.logService.log('Test message');
|
||||
}
|
||||
|
||||
debug() {
|
||||
this.logService.debug('Test message');
|
||||
}
|
||||
|
||||
trace() {
|
||||
this.logService.trace('Test message');
|
||||
}
|
||||
|
@ -42,6 +42,14 @@ export class LogService {
|
||||
};
|
||||
}
|
||||
|
||||
get debug(): (message?: any, ...optionalParams: any[]) => any {
|
||||
if (this.currentLogLevel >= LogLevelsEnum.DEBUG) {
|
||||
return console.debug.bind(console);
|
||||
}
|
||||
return (message?: any, ...optionalParams: any[]) => {
|
||||
};
|
||||
}
|
||||
|
||||
get info(): (message?: any, ...optionalParams: any[]) => any {
|
||||
if (this.currentLogLevel >= LogLevelsEnum.INFO) {
|
||||
return console.info.bind(console);
|
||||
|
Loading…
x
Reference in New Issue
Block a user