question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom logger and console.log output

See original GitHub issue

Hi,

I have implemented a custom logger and it arrives there. I wanted to do all my logging in my custom logger because i dont want any output to the console. Right now i am seeing…

ngx-logger.js:228 2018-10-31T14:18:45.675Z ERROR [main.js:4864] THIS WAS ERROR

2018-10-31T14:18:51.650Z INFO [main.js:4866] THIS WAS INFO

ngx-logger is logging to the console, is it possible to turn this off ?

I have my custom logger

import { NGXLoggerMonitor, NGXLogInterface, Levels } from "ngx-logger"

export class MyLoggerMonitor implements NGXLoggerMonitor {
  onLog(log: NGXLogInterface) {
    debugger
    //console.log("myCustomLoggerMonitor", log)
  }
}

and my main logger service, where I inject NGXlogger

  constructor(private logger: NGXLogger) {

    this.logger.registerMonitor(new MyLoggerMonitor())

    this.logger.updateConfig({ level: NgxLoggerLevel.INFO })

    this.logger.error("THIS WAS ERROR")
    this.logger.debug("THIS WAS DEBUG")
    this.logger.info("THIS WAS INFO")

I basically have wrapping methods ie…

  debug(message: string, ...additional: any[]) {
    this.logger.debug(message, additional)
  }

  info(message: string, ...additional: any[]) {
    this.logger.info(message, additional)
  }

and I set this up in my core module -imports, like so

    LoggerModule.forRoot({ level: NgxLoggerLevel.OFF })

As I say, it does work, it arrives inside my custom logger when I do a logger.info for example BUT the it still does a console.log

Can this be turned off in production, I can’t set the log level to OFF as then my custom logger doesn’t get activated.

Any ideas - thanks in advance

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
iangregsondevcommented, Nov 5, 2018

great, that works for me. Thanks

0reactions
dbfannincommented, Nov 5, 2018

@appsolutegeek, this is by design. Updated the config is meant to completely overwrite the current config. We want to be explicit. There would be ambiguity if we were to just extend the config.

We do provide a method called getConfigSnapshot(), so if you wanted to update a single value, you could just

const config = this.logger.getConfigSnapshot();
config.level = NgxLoggerLevel.INFO;
this.logger.updateConfig(config);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Console log formatting - .NET - Microsoft Learn
Learn how to use available console log formatting, or implement custom log formatting for your .NET applications.
Read more >
Organize Your JavaScript Console Logging with a Custom ...
In Example # 2, we have created a variable named “debugMode”. This tells our custom debug function whether or not messages should be...
Read more >
Node.js Logging Tutorial - Stackify
In the built-in Node.js console log, all logging levels equate to either log ... When the output is the console or stdout/stderr, it...
Read more >
Custom log messages - Sails.js
Custom log messages ... Like console.log , data passed as arguments to the Sails logger are ... Writes log output to stderr at...
Read more >
Extending console.log without affecting log line - Stack Overflow
Some of the other answers here came close, but the trick is to have your custom logging method return the modified logger. Below...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found