Add logging service.
- Implements custom logging functionality.
This commit is contained in:
parent
32ab27730b
commit
d7dcece7fe
@ -1,7 +0,0 @@
|
||||
import { Account } from './account';
|
||||
|
||||
describe('Account', () => {
|
||||
it('should create an instance', () => {
|
||||
expect(new Account()).toBeTruthy();
|
||||
});
|
||||
});
|
16
src/app/_services/logging.service.spec.ts
Normal file
16
src/app/_services/logging.service.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
48
src/app/_services/logging.service.ts
Normal file
48
src/app/_services/logging.service.ts
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user