@invsqr/logging v1.0.0
Installation
Using npm:
npm install @invsqr/logging --saveSetup
In your root module (e.g. AppModule):
import { LoggingModule, LoggingService, LogLevel } from "auth";
@NgModule({
declarations: [
...
],
imports: [
...
LoggingModule.forRoot({ apiUrl: "..." }, LogLevel.error, LogLevel.info)
],
providers: [
...
LoggingService
],
bootstrap: [...]
})
export class AppModule { }LoggingModule.forRoot could, for instance, accept the application's environment file, assuming the environment file contains an apiUrl property.
A second, optional parameter can be passed in to forRoot in order to specify the log upload threshold, which determines at what level of severity a log will be uploaded (defaults to LogLevel.error if not specified).
A third, optional parameter can be passed in to forRoot in order to specify the log intercept threshold, which determines at what level of severity a log will be intercepted (defaults to LogLevel.info if not specified).
Usage
Any console.info, console.log, console.warn or console.error will be intercepted (severity dependent on configuration) by the LoggingService and uploaded to the server (severity dependent on configuration).
There's no need to directly interface with the LoggingService unless the intent is to upload a log to the server while bypassing the console class or the current upload severity configuration. To do so:
import { LogLevel, LoggingService } from "@invsqr/logging";
class ExampleClassPossiblyAComponentOrServiceDoesntMatterJustDontMakeYourClassNamesTooLong {
constructor(private loggingService: LoggingService) {
this.loggingService.log(LogLevel.info, "test message");
}
}Notes
To use the console object and bypass the LoggingService's interceptor, pass "_" as the first argument:
console.log("_", "this message will be ignored by the LoggingService interceptor");