Skip to content

feat(core): introduce Logger service - #14308

Closed
DzmitryShylovich wants to merge 1 commit into
angular:masterfrom
DzmitryShylovich:gh/5458
Closed

DzmitryShylovich wants to merge 1 commit into
angular:masterfrom
DzmitryShylovich:gh/5458

Conversation

@DzmitryShylovich

@DzmitryShylovich DzmitryShylovich commented Feb 5, 2017 •

Copy link
Copy Markdown
Contributor

Closes #5458

@FrozenPandaz

Copy link
Copy Markdown
Contributor

Thoughts on implementing Logger.time as console.time?

https://developer.mozilla.org/en-US/docs/Web/API/Console/time

@chunghha

chunghha commented Feb 8, 2017

Copy link
Copy Markdown

console.group as well please.

https://developer.mozilla.org/en-US/docs/Web/API/Console/group

@mhevery

mhevery commented Feb 9, 2017

Copy link
Copy Markdown
Contributor

I believe all JavaScript platforms have console. I that is the case we should move Logger into core and the default implementation should just do console.log

What do you think?

@gkalpak

gkalpak commented Feb 9, 2017 •

Copy link
Copy Markdown
Member

IE9 might need special treatment, because console is only available when DevTools are open (and has some quirks, like console.log not inheriting from Function.prototype).

(Just pointing out that special treatment might be needed, not implying that it shouldn't be done.)

@DzmitryShylovich

Copy link
Copy Markdown
Contributor Author

@gkalpak it's already handled here. Basically it's a function from ng1. If console is not available it will be noop.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've been discussing about removing this method from AngularJS.
Stringifying the error, breaks source map supports (see angular/angular.js#15590 (comment) for more info).

@mgol mgol Feb 9, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm in the process of removing this function for AngularJS 1.7 for all the browsers with the exception of IE/Edge (as their error logging is far from ideal). Chrome/Safari apply source maps to logged errors, Firefox is in a process of implementing that as well. By adding this function you'll break it and if you use Webpack - which many people will as that's what Angular CLI uses - you'll just see references to app.bundle.js or vendor.bundle.js which makes making sense out of the stack virtually impossible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this method is not used.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. Can it just be removed then?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

Comment thread modules/@angular/core/src/logger.ts Outdated

@DzmitryShylovich DzmitryShylovich Feb 10, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need this check? afaik ng2 doesn't officially support ie8

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, try-catch shouldn't be needed any more. Guarding against missing console.log.apply is as IE 9 has console method not inheriting from Function.prototype.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@DzmitryShylovich

Copy link
Copy Markdown
Contributor Author

@mhevery you're right, console is available on on supported platforms.
Moved Logger into core.

Also added group and groupEnd because these methods are used by the router.

@mhevery mhevery added the action: merge The PR is ready for merge by the caretaker label Feb 10, 2017
@mhevery

mhevery commented Feb 10, 2017

Copy link
Copy Markdown
Contributor

rebase please

@DzmitryShylovich

DzmitryShylovich commented Feb 10, 2017 •

Copy link
Copy Markdown
Contributor Author

@mhevery rebased

@mhevery mhevery removed the action: merge The PR is ready for merge by the caretaker label Feb 13, 2017
@mhevery

mhevery commented Feb 13, 2017

Copy link
Copy Markdown
Contributor

We decided to not merge this in as at is a new feature and @IgorMinar and I need to debate whether we want to add and support this kind of features.

Comment thread modules/@angular/core/src/logger.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove @param args and make comment 1 liners

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread modules/@angular/core/src/logger.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private _getConsoleMethod(method, args) and remove all the private wrappers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but in this case we will need to make unnecessary checks on every invocation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the comments are necessary on the Logs prop

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a similar comments in ng1. I thought it would be useful for generated api docs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@vicb

vicb commented Feb 14, 2017

Copy link
Copy Markdown
Contributor

@mhevery @IgorMinar Yep, it would be good to have it, we use a mic of console.log, Console service today.

@trumbitta

Copy link
Copy Markdown

I'm puzzled and can't figure out why a framework wouldn't have a logging system :-/

@alastair-todd

Copy link
Copy Markdown

So, 2 months on 1 million people have introduced a nigh-on identical but independent "custom" LoggingService into their apps.

C'mon what's to consider here?

@chuckjaz chuckjaz added area: core Issues related to the framework runtime feature Label used to distinguish feature request from other issues labels May 23, 2017
@Toxicable Toxicable mentioned this pull request Jun 10, 2017
2 of 3 tasks

@IgorMinar IgorMinar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My primary issue with this PR is that logging typically becomes very expensive (in terms of payload-size) very quickly. Until we have a design that can safely strip non-critical logs and minify the critical ones I think everyone is better off rolling their own solution. The api above would likely need to be changed to achieve these properties, and doing so after these apis are heavily used would be very disruptive and painful for everyone.

The cross-cutting concern of logging and necessity to provide a solution that works well for 3rd party components makes this a much harder problem than what it looks like on the surface and we are better off deferring tackling this problem rather than providing a solution that would send everyone down the wrong path.

@splincode

Copy link
Copy Markdown
Contributor

@IgorMinar Should we close this task?

@splincode

splincode commented Jul 26, 2018 •

Copy link
Copy Markdown
Contributor

@DzmitryShylovich @mhevery Is the PR is relevant?

@mhevery

mhevery commented Jul 27, 2018

Copy link
Copy Markdown
Contributor

Closing per @IgorMinar's comment.

@mhevery mhevery closed this Jul 27, 2018
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: core Issues related to the framework runtime cla: yes feature Label used to distinguish feature request from other issues state: blocked

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add $log like functionality to Angular 2