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

Extend custom logger to allow taking the notifications directly and generate it's own string. #57

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

technicalpickles
Copy link
Contributor

@technicalpickles technicalpickles commented Feb 10, 2023

We have a custom logger, but in order to inspect the callstack and customize the message, we end up throwing out the notification_str and reaching into Thread.current[:prosopite_notifications] directly to get it.

We also have to do our own filtering and cleaning because they haven't been cleaned yet.

I'm proposing this change to let the customer logger take the notifications keyword that gets the notifications OR a single argument that is the generated string. In support of that, I clean the callstacks before calling the custom logger.

cc @geshwho who wrote our custom logger. Hoping we can refactor it to be smaller with these changes 😁

… support custom logger taking the notifications directly

We have a custom logger, but in order to inspect the callstack and
customize the message, we end up throwing out the notification_str and
reaching into Thread.current[:prosopite_notifications] directly to get
it.

We also have to do our own filtering and cleaning because they haven't
been cleaned yet.

I'm proposing this change to let the customer logger take the
`notifications` keyword that gets the notifications OR a single argument
that is the generated string. In support of that, I clean the callstacks
before calling the custom logger.
Copy link
Owner

@charkost charkost left a comment

Choose a reason for hiding this comment

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

Thank you @technicalpickles! This is really useful :)
I think that an example of getting access to the notifications from the custom logger (from the new notifications keyword argument) in the README would be helpful too.

lib/prosopite.rb Outdated Show resolved Hide resolved
Prosopite.custom_logger = MyLogger.new
```

Additionally, you can further customize how notifications are displayed by makni ga `warn` method that takes a `notifications` keyword:
Copy link
Owner

Choose a reason for hiding this comment

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

Typo: by makni ga

```ruby
class FancifulLogger
def warn(notifications:)
notification.each do |queries, kaller|
Copy link
Owner

Choose a reason for hiding this comment

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

notification vs notifications - the singular form doesn't exist.

class FancifulLogger
def warn(notifications:)
notification.each do |queries, kaller|
# queries is an array of strings of santitized queries
Copy link
Owner

Choose a reason for hiding this comment

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

typo santitized - however what do you mean by sanitized queries?
I would write this as The SQL queries that constitute the N+1 case

def warn(notifications:)
notification.each do |queries, kaller|
# queries is an array of strings of santitized queries
# kaller is the callstack where it was called, and has been cleaned by Prosopite.backtrace_cleaner
Copy link
Owner

Choose a reason for hiding this comment

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

I think they were called is more appropriate since we are referring to multiple queries.

@raise ||= false
def clean_notifications(notifications)
notifications.map do |queries, kaller|
kaller = backtrace_cleaner.clean(kaller)
Copy link
Owner

Choose a reason for hiding this comment

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

backtrace_cleaner is also called in the generate_notification_message - should be removed from there

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