ngx-rocket / generator-ngx-rocket

:rocket: Extensible Angular 14+ enterprise-grade project generator
https://ngx-rocket.github.io/
MIT License
1.53k stars 218 forks source link

correct a small typo in the log function #584

Closed rom3r4 closed 3 years ago

rom3r4 commented 3 years ago

https://github.com/ngx-rocket/generator-ngx-rocket/blob/e05fee047c6f8e5eafd17c9c063d2ab162d6a572/generators/app/templates/src/app/%40core/logger.service.ts#L106

Not sure about this: when checking the passed log-level against the one in the class, shouldn't we only accept the levels greater than the one in the class?

eg.

if we set a logLevel=Warning in the class, and do a log.debug('msg') we would not expect this message to be printed.

just changing if (level <= Logger.level) { for if (level >= Logger.level) { would make it

  private log(func: (...args: any[]) => void, level: LogLevel, objects: any[]) {
    if (level <= Logger.level) {
      const log = this.source ? ['[' + this.source + ']'].concat(objects) : objects;
      func.apply(console, log);
      Logger.outputs.forEach(output => output.apply(output, [this.source, level, ...objects]));
    }
sinedied commented 3 years ago

That may seem counter-intuitive, but log levels with higher importance have lower values, as defined by:

export enum LogLevel {
  Off = 0,
  Error,       // 1
  Warning, // 2
  Info,         // 3
  Debug     // 4
}

So the code is actually correct 😉