如何使用Ember.Logger获取与console.log相同的输出?

时间:2021-09-21 16:56:55

I'm trying to get an understanding of why I would use Ember.Logger instead of just using console.log directly. The problem is, no matter where I log from (from any file), the output shows the log as emanating from:

我试图了解为什么我会使用Ember.Logger而不是直接使用console.log。问题是,无论我从哪里登录(从任何文件),输出都显示日志来自:

ember.js?body=1:15359

Whereas, if I use console.log, I get a more helpful log location, including the file that logged and where in the file:

然而,如果我使用console.log,我会得到一个更有用的日志位置,包括记录的文件和文件中的位置:

application.js?body=1:9

Is there a way to use Ember.Logger that would show the location and information? The docs indicate that one should "[o]verride this to provide more robust logging functionality." Should I just assume that this is supposed to be for overriding and making something really fancy and not just for basic logs to the console?

有没有办法使用Ember.Logger来显示位置和信息?文档表明,应该“[o]对此进行改进以提供更强大的日志记录功能。”我是否应该假设这应该是为了覆盖并制作一些非常奇特的东西,而不仅仅是基本日志到控制台?

1 个解决方案

#1


1  

To answer your question directly, no, I don't think there is a way to have the Ember logger report the correct line numbers. Logging to the console is just a commonly implemented API, it's not a Javascript standard. Because of this, the browser automatically determines where a log statement came from and makes it pretty much impossible to wrap a layer of indirection around it. There might be some clever ticks out there, but none that I know of.

要直接回答您的问题,不,我认为没有办法让Ember记录器报告正确的行号。登录到控制台只是一个常用的API,它不是Javascript标准。因此,浏览器会自动确定日志语句的来源,并且几乎不可能在其周围包含一层间接。可能会有一些巧妙的滴答声,但我所知道的都没有。

But more importantly, I don't think Ember's logger is really meant for third party consumption. It's mostly used internally by Ember, so the main reason you would override it is to redirect Ember's logging to a different location. In my opinion, it seems like a fairly poor way to handle your own application logging.

但更重要的是,我不认为Ember的记录器真正意味着第三方消费。它主要由Ember内部使用,因此您覆盖它的主要原因是将Ember的日志记录重定向到其他位置。在我看来,处理自己的应用程序日志记录似乎是一种相当差的方法。

#1


1  

To answer your question directly, no, I don't think there is a way to have the Ember logger report the correct line numbers. Logging to the console is just a commonly implemented API, it's not a Javascript standard. Because of this, the browser automatically determines where a log statement came from and makes it pretty much impossible to wrap a layer of indirection around it. There might be some clever ticks out there, but none that I know of.

要直接回答您的问题,不,我认为没有办法让Ember记录器报告正确的行号。登录到控制台只是一个常用的API,它不是Javascript标准。因此,浏览器会自动确定日志语句的来源,并且几乎不可能在其周围包含一层间接。可能会有一些巧妙的滴答声,但我所知道的都没有。

But more importantly, I don't think Ember's logger is really meant for third party consumption. It's mostly used internally by Ember, so the main reason you would override it is to redirect Ember's logging to a different location. In my opinion, it seems like a fairly poor way to handle your own application logging.

但更重要的是,我不认为Ember的记录器真正意味着第三方消费。它主要由Ember内部使用,因此您覆盖它的主要原因是将Ember的日志记录重定向到其他位置。在我看来,处理自己的应用程序日志记录似乎是一种相当差的方法。