Add logging service.

- Implements custom logging functionality.
This commit is contained in:
Spencer Ofwiti 2021-03-14 11:11:37 +03:00
parent 32ab27730b
commit d7dcece7fe
3 changed files with 64 additions and 7 deletions

View File

@ -1,7 +0,0 @@
import { Account } from './account';
describe('Account', () => {
it('should create an instance', () => {
expect(new Account()).toBeTruthy();
});
});

View File

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { LoggingService } from './logging.service';
describe('LoggingService', () => {
let service: LoggingService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(LoggingService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,48 @@
import {Injectable} from '@angular/core';
import {NGXLogger} from 'ngx-logger';
import {environment} from '@src/environments/environment';
@Injectable({
providedIn: 'root'
})
export class LoggingService {
env: string;
canDebug: boolean;
constructor(private logger: NGXLogger) {
// TRACE|DEBUG|INFO|LOG|WARN|ERROR|FATAL|OFF
this.env = environment.production ? 'Production' : 'Development';
if (this.env === 'Development') {
this.sendInfoLevelMessage('Dropping into debug mode');
}
}
sendTraceLevelMessage(message, source, error): void {
this.logger.trace(message, source, error);
}
sendDebugLevelMessage(message, source, error): void {
this.logger.debug(message, source, error);
}
sendInfoLevelMessage(message): void {
this.logger.info(message);
}
sendLogLevelMessage(message, source, error): void {
this.logger.log(message, source, error);
}
sendWarnLevelMessage(message, error): void {
this.logger.warn(message, error);
}
sendErrorLevelMessage(message, source, error): void {
this.logger.error(message, source, error);
}
sendFatalLevelMessage(message, source, error): void {
this.logger.fatal(message, source, error);
}
}