Skip to content
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

[BUG] - slog.Any can cause infinite loop if there is circular pointers in the struct #25

Open
OrHayat opened this issue Dec 7, 2023 · 2 comments

Comments

@OrHayat
Copy link

OrHayat commented Dec 7, 2023

type Vertex struct {
	ID int
	This *Vertex  
}
//try to use logger to log it when there is circular pointer
{
....
	g1 := Vetex{ID: 55}
	g.This  &g
	logger := slog.New(handler)
	logger.LogAttrs(context.Background(), slog.LevelError, "a", slog.Any("test", g))
}
@david-littlefarmer
Copy link
Collaborator

Here is fix with limitation, to prevent infinite loop #28.
Please let me know, if it works for you.

@OrHayat
Copy link
Author

OrHayat commented Dec 25, 2023

this is one way to solve the infinite loops issue
other way is to also to add opt-in cache
map[uinptr]string thats map pointer to field to the path to the field
and when you handle pointer/struct you can check if that pointer is in the cache and if it is you can format the log field from the stored path.

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

No branches or pull requests

2 participants