Skip to content

Conversation

@spaceone
Copy link
Contributor

The logging module sets the traceback string to record.exc_text and doesn't caluclate it again.
This allows also to log exceptions, when we are not in the stack-context anymore and have no exc_info tuple.
For example, in some cases, only the textual representation of a traceback is stored because the traceback object would be a memory leak and prevent garbage collection.

Use case is therefor:
formatter.format(record) where exc_text was already created by another earlier formatter or filter.

@spaceone
Copy link
Contributor Author

value = "".join(traceback.format_exception(*exc_info)).rstrip("\n")

return cls.format_string(value)
return "".join(traceback.format_exception(*exc_info))
Copy link
Owner

Choose a reason for hiding this comment

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

This change makes it so the return value of format_exc_info is no longer formatted with cls.format_string. Why is this necessary? I would rather not have a breaking change if its not necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's also possible to use the upstream formatException() method.

I will rewrite it to be backwards compatible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hm, but exc_text shouldn't contain the escaped value.
So, I see only the possibility to leave the method in there, but unused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see 349513a

@josheppinette
Copy link
Owner

@spaceone let's just remove that format_exc_info function now that it isn't necessary, nice work!

@spaceone
Copy link
Contributor Author

okay, i'll do it.

The logging module sets the traceback string to `record.exc_text` and
doesn't caluclate it again.
This allows also to log exceptions, when we are not in the stack-context
anymore and have no `exc_info` tuple.
For example, in some cases, only the textual representation of a
traceback is stored because the traceback object would be a memory leak
and prevent garbage collection.

Use case is therefor:
`formatter.format(record)` where `exc_text` was already created by
another earlier formatter or filter.
@spaceone
Copy link
Contributor Author

done

@josheppinette josheppinette merged commit 949038b into josheppinette:main Sep 24, 2025
2 checks passed
@spaceone
Copy link
Contributor Author

@josheppinette why do you have the conventional commit message guideline, when you always squash the commits when merging? I have explicitly in multiple merge requests split the commits into logical units, in 8f3dbc1 even explaining the reasoning, which is now lost after merging it in a squashed way.

@josheppinette
Copy link
Owner

josheppinette commented Sep 24, 2025

@spaceone

My view is that a pull request should represent a single unit of change. During the development of a pull request, multiple commits may be used to generate that single unit of change. If it feels like there should be multiple commits in the main history, then it probably means the commit should be split up. However, I think all of your changes were properly sized to a single commit.

Regarding the explanation, that is my bad. I merge pull requests all day that are usually full of random stuff in there that I delete and just did the same for yours. I will make sure to review more thoroughly and properly retain that information. Great job on writing those by the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants