-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new feature: printing the position info while printing the logs ? #145
Comments
@MienDev |
@langley-agm thank you, sorry for replaying late. sometimes we just want to log business logic errors, etc. but not throw program logic exception. |
There's a difference between log business logic errors (console.error) and throw program logic exception (throw). logger.error IS logging a business logic error, all its doing at the end is console.error which is exactly what you want to do. |
@langley-agm I think you misunderstood the question. Every line in the console has a position (please see the attached image). But logs logged by Here is the solution: class Logger {
// copied from angular2-logger
log1(message?: any, ...optionalParams: any[]) {
console.log.apply( console, arguments );
}
get log2(): Function {
return console.log.bind(console);
}
}
const logger = new Logger();
logger.log1("hello"); // give a wrong position
logger.log2("world"); // give a correct position
console.log("I'm here"); // as a reference I can create a PR if you feel ok with this solution. |
Which question? lol |
@zjx20 Yea if you add a PR I'll take a look at it, i'll do some testing and think on the implications of the change. I'm curious is there a reason for the |
Well, I think he was wanting every log to have a current position info, but you told him just to use logger.error() all the time.
Because I am returning a function.
I had already showed you: |
No I didn't. He said he wanted to log errors, and errors do show the stack trace.
Ok, I'll rephrase my question, why are you returning a function?
Yea I saw that you put it down there. I edited my message. |
First of all, And the Hope I was explaining well :) |
I know what When you call It's not a weird syntax, its just a method that returns another method: |
They are not equivalent.
|
No, that's not true. |
I was not meaning |
Their functionality is not the same. |
Well, I just meant them both can write message to the console. |
You are right, in this case the log2 is not treated as a function but as a property because of the get, except the get returns a property of type function, it's a bit confusing but it could be an interesting trick. Have you tried this change in a real project? I wonder if we should bind it to the calling object instead of to the console, does it work fine with the error stack trace and deep component trees? |
You should just try it, don't you? I don't want to create a PR any more. |
I'm asking to see if I have to test this or you had already done it. I'll consider it for a future update, thanks for the input. |
By the way I think I was wrapping it different in my head as if you were comparing bind to log, but what you were considering equivalent was the function that In my head I was seeing it as |
Hello
|
Hi @ajitsonlion thanks for the feedback, yea, I do like @zjx20's proposal but I'd have to do some testing around it. Atm i'm working in an issue with AoT, actually, an issue with rollup, after that i'll start with this one. One of the things that are needed to review is how would this work when the appenders get added? Right now they all work as if they had a console appender configured, but later on they'll be able to have other type of appenders, what will happen if some of them logs something? will they cycle? will they show the line number? will they show logger.ts in the print? is it ok that some say logger and some say the name of the class that calls the logger? we need consistency on these kind of things. |
Hi, @langley-agm
is there any plan for adding feature on printing the position info while printing the logs ?
the outputs in debugger console is only show position like
logger.ts:79
. this position info in logger.ts is useless for locating the error while debugging. but position infofile > class > function > line
such asapp.module.ts line 78
would be very very helpful, even if a function level position would be better.The text was updated successfully, but these errors were encountered: