ngx-logger: File name/line-numbers no longer show accurately

I recently upgraded my app to Angular 6 and ngx-logger 3.0.0-rc1.

Unfortunately the logger no longer shows the file name/line number of the log - instead it shows main.js:<line num>.

Previous behavior

2018-06-11T19:06:58.864Z DEBUG [demo.component.ts:155] loading api       ngx-logger.js:386

Current behavior

2018-06-11T19:06:58.864Z DEBUG [main.js:2164] loading api       ngx-logger.js:386

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 9
  • Comments: 43 (14 by maintainers)

Commits related to this issue

Most upvoted comments

I just tested on Angular 9.0.0-rc.3 as adviced here https://stackoverflow.com/a/56669585/1392277 but still getting main.js in logs So on 9.0 only works with --evalSourceMap=true for now.

Anyone any ideas please? Or someone more lucky on 9.0?

Looks like I found a solution to make this work

  loggerConfig: {
    level: environment.production ? NgxLoggerLevel.WARN : NgxLoggerLevel.DEBUG,
    // serverLoggingUrl: '/api/logs',
    // serverLogLevel: NgxLoggerLevel.OFF,
    enableSourceMaps: true, // <-- THIS IS REQUIRED, to make "line-numbers" work in SourceMap Object defition (without evalSourceMap)
    disableConsoleLogging: environment.production
  }

@JavierFuentes, If you’re going to comment, please try to stay constructive and positive. There is no need for negative comments. The people that support this project are sacrificing time and energy to provide you with a service at no cost to you, and they get no benefit from it themselves. Please be respectful.

@bniedermeyer, It’s not that the file line number is inaccurate, but that they are no longer using the the js maps. if you pull up main.js:<line num> in your browser, you’ll see the line where the call to the logger was made. It’s just showing the JS instead of the TS.

Since no changes in the logger were made around this, I believe it has something to do with how the maps are being generated in the latest version of angular. I don’t believe it has anything to do with NGX Logger itself, but I’ll have to do some research to confirm.

@ghiscoding @dbfannin note that --sourceMap=true is deprecated/doesn’t work at all.
See my answer here https://stackoverflow.com/a/56669585/1392277

@ghiscoding, Great Feedback! I’ll add that to the readme.

@ghiscoding, it relies on the source maps existing, so yes, sourceMap: true is necessary in your angular.json. The change here is to manually pull in and parse the source map to find the correct file name and number.

Thanks for the update @ghiscoding and @TeXnicians!

I just updated the version to the latest available (3.0.4) and sadly view the problem persists…

Curiously, console.log does correctly indicate the line and my Typescript file instead of main.js

I’m afraid that a logger that has stopped doing his work is not very useful, isn’t it?