pimterry / loglevel

:ledger: Minimal lightweight logging for JavaScript, adding reliable log level methods to wrap any available console.log methods
MIT License
2.62k stars 157 forks source link

No log output #139

Closed ed4becky closed 4 years ago

ed4becky commented 4 years ago

I am trying to use loglevel in an angular. I have abstracted the service (I don't think that's relevant), and whenthe service is created, a console.log shows output but loglevel does not.

import {Injectable} from '@angular/core';
import {Logger} from './logger.service';
import * as loglevel from 'loglevel';

const noop = (): any => undefined;

@Injectable ({
  providedIn: 'root'
})
export class LogLevelLoggerService implements Logger {
  constructor () {
    console.log(JSON.stringify(loglevel.getLoggers()));
    loglevel.info(''this never gets logged);
  }
  info (msg: string) {
    loglevel.info (msg);
  }
}

I feel like something simple is missing...

pimterry commented 4 years ago

Have you set the log level? It defaults to warn, so only warn & error messages will appear, and info messages (like these) will be hidden.

You can change that with loglevel.setLevel("info") (or trace/debug, just a level that's not higher than info), or loglevel.enableAll() which will show all messages.

ed4becky commented 4 years ago

That was the issue, I thought the default was info.

Thanks for quick response