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.
*/
handleFormSubmission() {
this.logToConsole.emit(this.loggerForm.value);
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.
import { NgxLoggerLevel } from 'ngx-logger';
export const environment = {
production: false,
ngxLoggerConfig: {
level: NgxLoggerLevel.INFO,
disableConsoleLogging: true
},
xsrf: {
headerName: 'ATLASMAP-XSRF-TOKEN',
cookieName: 'ATLASMAP-XSRF-COOKIE',
defaultTokenValue: 'awesome',
},
backendUrls: {
atlasServiceUrl: '/v2/atlas/',
javaInspectionServiceUrl: '/v2/atlas/java/',
xmlInspectionServiceUrl: '/v2/atlas/xml/',
jsonInspectionServiceUrl: '/v2/atlas/json/',
},
};
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 '';
}
}
import {ObserveComponent} from './observe/observe.component';
import {environment} from '../environments/environment';
@NgModule({
declarations: [
AppComponent,
ObserveComponent
],
imports: [
BrowserModule,
HttpClientModule,
FormsModule,
LoggerModule.forRoot({
level: !environment.production ? NgxLoggerLevel.DEBUG : NgxLoggerLevel.INFO,
serverLogLevel: NgxLoggerLevel.INFO
})
],
providers: [ObserveService],
bootstrap: [AppComponent]
})
export class AppModule {
}
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);
break;
case NgxLoggerLevel.FATAL:
this.logger.fatal(log.logMessage);
break;
}
}
import {ObserveService} from './observe/observe.service';
import {ObserveComponent} from './observe/observe.component';
import {environment} from '../environments/environment';
@NgModule({
declarations: [
AppComponent,
ObserveComponent
],
imports: [
BrowserModule,
HttpClientModule,
FormsModule,
LoggerModule.forRoot({
level: !environment.production ? NgxLoggerLevel.DEBUG : NgxLoggerLevel.INFO,
serverLogLevel: NgxLoggerLevel.INFO
})
],
providers: [ObserveService],
bootstrap: [AppComponent]
})
export class AppModule {
}