Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add Parser logging #130

Merged
merged 10 commits into from
Feb 12, 2024
Merged

Add Parser logging #130

merged 10 commits into from
Feb 12, 2024

Conversation

dabico
Copy link
Member

@dabico dabico commented Feb 12, 2024

This PR introduces two new instance methods to Parser:

  • Parser#getLogger
  • Parser#setLogger

It relies on the SLF4J logging facade to forward the information from tree-sitter to a Logger instance. While writing logs to the DEBUG level, it will also include the appropriate log event type in the form of a Marker.

Both `jclass` global references will be `NULL` if the dependency classes
are not present. This makes them safe to load globally. Although loading
`Logger` is a no-brainer, the reason we also need a `MarkerFactory` is
because we want to distinguish the `TSLogType` values. Each value,
`TSLogTypeLex` and `TSLogTypeParse` will have their respective markers.
The function signature aligns with what is required by `TSLogger.log`.
It first checks if the `payload` is defined, which in our case is an
instance of a `Logger` class. We then obtain the current JVM environment
while attaching the current thread if necessary. We then construct an
instance of `Marker` through the `MarkerFactory#getMarker`, its value
based on the `TSLogType`. Finally, we call the `Logger#debug` method,
passing the constructed `Marker` and a `String` from the character
pointer. Although I'm quite happy with this implementation, we do
restrict all logging to the `DEBUG` level.
This introduces two new native instance methods:
- `Parser#getLogger`
- `Parser#setLogger`
@dabico dabico merged commit bcdd658 into master Feb 12, 2024
2 checks passed
@dabico dabico deleted the feature/logger branch February 12, 2024 21:24
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant