1.0.0-rc.2 • Published 3 years ago

@la-clic/logger v1.0.0-rc.2

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

@la-clic/logger

This project was created to provide a colorfull, strong typed and extendable logger for angular APP

usage

@la-clic/logger comes as an injectable service. You can directly use it by setting it up in appComponent.ts constructor, and then inject it wherever you want.

import { LoggerService } from "@la-clic/logger";
import { LogLevel } from "@la-clic/logger";

constructor(private readonly _logger: LoggerService) {
  this._logger.setLogLevel(LogLevel.DEBUG);
  this._logger.enableDefaultLocalStorageLogs();
}

As a service, the configuration need to be done at the very top level, and not reset in other component.

extend

@la-clic/logger is extendable. By default, the logger write in console. It has a buildin publisher for localstorage that can be enable by calling :

this._logger.enableDefaultLocalStorageLogs();

and disable by calling

this._logger.disableDefaultLocalStorageLogs();

The LogPublisher abstract class let you create your own publisher.

public class MyCustomeLogger extends LogPublisher {
  constructor() { super(); }

  public log(entry: LogEntry): void {
    // your log logic and direction
  }

  pubic clear(): void {
    //your clear logic
  }
}

With such a class, you can log into a file, an API, ect. Just make your log logic according to LogLevel in the implementation of the log function.

Then, register your custome LoggerPublisher to the loggerService like so :

this._logger.addLoggerPublisher(new MyCustomLogger())

Further help

To get more help, contact the CLIC packages owner

1.0.0-rc.2

3 years ago

1.0.0-rc.1

3 years ago