Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
})
/**
* The LoggerComponent allows a user to enter a message and log it using ngx-logger. The user can select the type of log message.
* This component emits an event to the parent of the message and log type so the parent can perform the logging operation.
*/
export class LoggerFormComponent implements OnInit {
@Output() logToConsole: EventEmitter = new EventEmitter();
loggerForm = this.fb.group({
logMessage: ['', Validators.required],
logType: ['', Validators.required]
});
/* Used in the mat-select on the form */
logTypes: LoggerSelectionOption[] = [
{value: NgxLoggerLevel.TRACE, viewValue: 'Trace'},
{value: NgxLoggerLevel.DEBUG, viewValue: 'Debug'},
{value: NgxLoggerLevel.INFO, viewValue: 'Info'},
{value: NgxLoggerLevel.LOG, viewValue: 'Log'},
{value: NgxLoggerLevel.WARN, viewValue: 'Warn'},
{value: NgxLoggerLevel.ERROR, viewValue: 'Error'}
];
constructor(private fb: FormBuilder) {
}
ngOnInit() {
}
/**
* Take the message and type of logging to be performed and emits it to the parent component.
*/
get loggerColor(): string {
switch (this.currentLogLevel) {
case NgxLoggerLevel.TRACE:
case NgxLoggerLevel.DEBUG:
return 'primary';
case NgxLoggerLevel.INFO:
case NgxLoggerLevel.LOG:
return 'accent';
case NgxLoggerLevel.WARN:
case NgxLoggerLevel.ERROR:
case NgxLoggerLevel.FATAL:
return 'warn';
default:
return '';
}
}
handleLog(log: LogEvent) {
switch (log.logType) {
case NgxLoggerLevel.TRACE:
this.logger.trace(log.logMessage);
break;
case NgxLoggerLevel.DEBUG:
this.logger.debug(log.logMessage);
break;
case NgxLoggerLevel.INFO:
this.logger.info(log.logMessage);
break;
case NgxLoggerLevel.LOG:
this.logger.log(log.logMessage);
break;
case NgxLoggerLevel.WARN:
this.logger.warn(log.logMessage);
break;
case NgxLoggerLevel.ERROR:
this.logger.error(log.logMessage);
isTraceEnabled(): boolean {
return this.logger.getConfigSnapshot().level === NgxLoggerLevel.TRACE;
}