Skip to content
Snippets Groups Projects
Commit a17f7899 authored by jojohoch's avatar jojohoch
Browse files

[player] Fix LogService.log method

- Improve tests
- Change log level logic
- change default log level
parent 0922e55d
No related branches found
No related tags found
No related merge requests found
...@@ -15,34 +15,34 @@ describe('LoggerService', () => { ...@@ -15,34 +15,34 @@ describe('LoggerService', () => {
it('should call LogService.log', () => { it('should call LogService.log', () => {
spyOn(LogService, 'log') spyOn(LogService, 'log')
.withArgs('test'); .withArgs('test', 'test2');
LogService.log('test'); LogService.log('test', 'test2');
expect(LogService.log).toHaveBeenCalled(); expect(LogService.log).toHaveBeenCalled();
expect(LogService.log).toHaveBeenCalledWith('test'); expect(LogService.log).toHaveBeenCalledWith('test', 'test2');
}); });
it('should call LogService.info', () => { it('should call LogService.info', () => {
spyOn(LogService, 'info') spyOn(LogService, 'info')
.withArgs('test'); .withArgs('test', 'test2');
LogService.info('test'); LogService.info('test', 'test2');
expect(LogService.info).toHaveBeenCalled(); expect(LogService.info).toHaveBeenCalled();
expect(LogService.info).toHaveBeenCalledWith('test'); expect(LogService.info).toHaveBeenCalledWith('test', 'test2');
}); });
it('should call LogService.warn', () => { it('should call LogService.warn', () => {
spyOn(LogService, 'warn') spyOn(LogService, 'warn')
.withArgs('test'); .withArgs('test', 'test2');
LogService.warn('test'); LogService.warn('test', 'test2');
expect(LogService.warn).toHaveBeenCalled(); expect(LogService.warn).toHaveBeenCalled();
expect(LogService.warn).toHaveBeenCalledWith('test'); expect(LogService.warn).toHaveBeenCalledWith('test', 'test2');
}); });
it('should call LogService.error', () => { it('should call LogService.error', () => {
spyOn(LogService, 'error') spyOn(LogService, 'error')
.withArgs('test'); .withArgs('test', 'test2');
LogService.error('test'); LogService.error('test', 'test2');
expect(LogService.error).toHaveBeenCalled(); expect(LogService.error).toHaveBeenCalled();
expect(LogService.error).toHaveBeenCalledWith('test'); expect(LogService.error).toHaveBeenCalledWith('test', 'test2');
}); });
it('should set LogService.level to "LOG"', () => { it('should set LogService.level to "LOG"', () => {
......
...@@ -6,33 +6,33 @@ export enum LogLevel { LOG = 0, INFO = 1, WARN = 2, ERROR = 3, NONE = 4} ...@@ -6,33 +6,33 @@ export enum LogLevel { LOG = 0, INFO = 1, WARN = 2, ERROR = 3, NONE = 4}
providedIn: 'root' providedIn: 'root'
}) })
export class LogService { export class LogService {
static level: LogLevel = 1; static level: LogLevel = 3;
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
static error(...args: any[]): void { static error(...args: any[]): void {
if (LogService.level >= LogLevel.ERROR) { if (LogService.level <= LogLevel.ERROR) {
window.console.error.apply( console, args ); window.console.error.apply( console, args );
} }
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
static warn(...args: any[]): void { static warn(...args: any[]): void {
if (LogService.level >= LogLevel.WARN) { if (LogService.level <= LogLevel.WARN) {
window.console.warn.apply( console, args ); window.console.warn.apply( console, args );
} }
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
static info(...args: any[]): void { static info(...args: any[]): void {
if (LogService.level >= LogLevel.INFO) { if (LogService.level <= LogLevel.INFO) {
window.console.info.apply( console, args ); window.console.info.apply( console, args );
} }
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
static log(...args: any[]): void { static log(...args: any[]): void {
if (LogService.level >= LogLevel.LOG) { if (LogService.level <= LogLevel.LOG) {
window.console.info.apply( console, args ); window.console.log.apply( console, args );
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment