-
Notifications
You must be signed in to change notification settings - Fork 712
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
Use separate option to control exception formatting #49
Comments
Hello @thebigmunch. Yes you are right, I had this same concern "What if user want to display whole traceback without the variables" (or the opposite), but I didn't know how to handle this in the API. I guess I could make the |
This is a rather poor API design. There you're overloading the value of backtrace as well as the meaning of it. The ideal solution is to add a If you were to overload the option value, you should go with an Enum instead. That would be a clearer API than bool or tuple of bools. You'll get people constantly forgetting which order the tuple represents. But, then you'd be breaking the API as well and should probably just add a separate option. |
After taking a quick look at the code, it may be even better to use the separate option to accept kwargs to pass to the What I also see is that the |
Alright, after having a chance to read all the relevant code, I believe I have the best solution for both controlling the output of variable values as well as the colorization issue. I think it would be best to add a This way the By the way, I'm willing to do the work on this, if desired. |
For reference, this is what a simple exception looks like with This is what it could look like with And this it could look like with Setting I believe all these options are quite valuable and desirable. |
Disclaimer: I wrote this before reading your last messages Thanks a lot for helping me investigating the best API! Improvements and suggestions are much welcome, as Loguru did not yet reach v1.0 as you said. I was afraid of adding another parameter to the Maybe we could go with the
The thing is that the colorization of exceptions is handled by the
I agree this may be useful for the user to have more control over exception formatting. Passing About your last messages So it seems we reached the same conclusion:
Your investment is much appreciated, really. ❤️ The thing is that during the last weeks I started to merge some of my changes made in
If Also, I think if |
And this is another case of overloading options. If you don't want Personally, I think it's fine for On the name Edit: On the topic of documentation, the exception parameters could be sectioned off like the file sink parameters to maybe ease the parameter list length in the docs. |
Oh yeah, I totally agree with you. What I meant is that, if
Oops, I proposed
Yes, absolutely, but I think that I still don't know which solution I prefer / is the more elegant. We have some time to think about it, waiting to see if |
The reason it currently isn't the case is that with backtrace disabled, the better_exceptions formatter isn't used. This is, in my opinion, something to be fixed. I agree that the format shouldn't change, but not that it should be the standard Python format. The package is called better_exceptions for a reason. The implementation update I'm thinking of would mean that all the exception formatting would pass through the better_exceptions
Except this issue is entirely about the fact that it can't be handled by one option. And, after looking deeper, I found that ideally it requires 3 to configure the features loguru wants to expose: colorization, traceback depth, and variable value display. These are 3 very separate concerns each requiring a way to configure. If you mean that the option would be a dict of kwargs to pass to the
It also mirrors the functionality and intent of the vars builtin : P PS Didn't say this before, but loguru is the first Python logging library that I've actually enjoyed using to any degree. Everything else is a true nightmare. |
What would you expect the format to be if
I don't understand why you think exception colorization requires an extra parameter. As you said, either the user wants colors for its whole logs (including stacktrace), either he won't. So, the exception colorization should depend on the I was indeed suggesting to pass a Also, here I'm entirely discussing about the api. I ignore implementation details, if this requires modifying how
Good point in favor of
Glad to here that, this means that Loguru reached its point! |
For one, the example chosen actually doesn't show any difference with What you're saying is exactly what I want. When you say format, you may or may not be speaking of something different than I am. When I talk about format, I'm speaking about how the first example, which is not passed to better_exceptions, displays the traceback exactly like it would with standard logging/exception. The second example is the same thing but passed to the better_exceptions formatter, resulting in blank lines being inserted for readability and adding the When you said you wanted it like the first one, I thought you meant a colored log message with an uncolored, standard traceback formatting. What will happen in my implementation for your case of
I don't. In fact, I said I didn't think there needed to be: "Personally, I think it's fine for colorize to control the colorization of both the log message and exception.". But multiple things you said made it sound as if you might've thought otherwise. I said I wasn't against it, in case that was a sticking point. But I think there were just some misunderstandings.
Yes, that's what I've been talking about, too. I'm big on API design and usability. I've brought up some implementation details as they currently are only because those implementation details are actually part of the problem with the current API (e.g. |
To put it in simplest terms, my ideal API proposal was and is:
|
Ok, so it seems it was mainly an issue of understanding each other. 🙂 Except for one thing that I'm still missing:
Then, what would be your expected output if Line 138 in 3b3be56
Every frame that is above the > mark is part of a stacktrace that has been re-built by Loguru: Line 80 in 3b3be56
And this is actually the whole point of backtrace=True : show the entire stacktrace as if the exception had not been caught so user can see the callstack from top to bottom.
This is what I want too. |
Yeah, I hadn't looked too far into the actual backtrace implementation. I probably didn't have everything modified to display the correct example there (it was early, early AM after a sleepless night). But, the backtrace implementation wouldn't change. It would still control what it controls separate of the better_exceptions formatting and other options. |
Ok, perfect then. Thanks for your patience. 👍 I will implement several changes to |
Hey @thebigmunch. I hope you are recovering little by little and wish this is not too painful. I imagine not being able to code is frustrating, in the meantime here are some updates about exception formatting in Loguru. I implemented a bunch of modifications about what we discussed and other stuff in #76. Exceptions coloration now depends solely of the I'm not entirely satisfied with the name "diagnose", but I chosen this over "show_vars" because I realized the entire Loguru API uses plain verbs without "_" in it, and I would like to keep this like that. I'm totally open to other suggestions if you have ones, it should ideally be a one-word verb which somehow evokes exceptions formatting ("diagnose" => "something is wrong (the exception), explain me why (the variable values)", but it's dubious I admit it). |
Yeah. I saw the additions as they were being made but haven't tried them out yet. Super excited about vendorizing the exception formatting. I agree that keeping with the style of the rest of the API is fine. I haven't really thought about a better option than diagnose yet. I also feel it isn't quite right but would work if it came down to it. My computer time is still limited, much of which is taken by my job. But it is looking like I should be getting back to my projects' backlog soon so long as I continue to heed my limits. Yay! |
Some other name options I have come up with to think about: examine or inspect. I think I have seen inspect used for this functionality or similar in an IDE or other programs before. |
Also, inspect would draw a parallel to the stdlib inspect module. |
@thebigmunch Yeah, glad to hear that you are going better. 👍 I had also thought about "inspect" but I was not entirely convinced as I thought it was too general. It describes quite perfectly what the option is doing, but it lacks a conotation related to error management. It's far less abstract than "diagnose", though. |
I kept the This new argument is now available in the |
Currently, the
backtrace
option is overloaded to control both displaying more of the traceback as well as formatting with better_exceptions. Semantically, those two things should be separate. Having them tied together prevents users from logging just the caught frame with better_exceptions formatting (unless I'm missing something). That's actually how I want most of my exception logging to be.The text was updated successfully, but these errors were encountered: