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

ActiveJob extension for preserving logs #733

Closed
wants to merge 2 commits into from

Conversation

NeimadTL
Copy link

@NeimadTL NeimadTL commented Oct 27, 2022

This draft allows me to have an idea of what the logging module will look like. It consists of the execution id, the logger info and the logger debug. Those three data, could be added into a model and would have a belong_to relationship with the Execution model on one end; and on the other end, the Excecution would have ahas_one relationship with this model. And then, at each execution, a record of this model would be saved in the database.

Connects to #710

This draft allows me to have an idea of what the logging module
will look like. It consists of the execution id, the logger info
and the logger debug. Those three data, could be added into a
model and would have a belong_to relationship with the Execution
 model on one end; and on the other end, the Excution would have a
has_one relationship with this model. And then, at each execution,
a record of this model would be saved in the database.
@NeimadTL NeimadTL marked this pull request as draft October 28, 2022 12:27
@bensheldon bensheldon changed the title Draft logs for job ActiveJob extension for preserving logs Oct 28, 2022
@bensheldon
Copy link
Owner

@NeimadTL this looks great! I pushed up some changes so that the logs are split and stored in a Concurrent::Array. I think this hits Checkpoint 1 👍🏻

Do you want to try for Checkpoint 2?

@NeimadTL
Copy link
Author

@NeimadTL this looks great! I pushed up some changes so that the logs are split and stored in a Concurrent::Array. I think this hits Checkpoint 1 👍🏻

Do you want to try for Checkpoint 2?

Thanks @bensheldon. I'm definitely up for checkpoint 2. Let's discuss tomorrow.

Copy link
Author

@NeimadTL NeimadTL left a comment

Choose a reason for hiding this comment

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

@bensheldon, just left some questions. Could you clarify them to me please?

included do
around_perform do |job, block|
original_logger = job.logger
job.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(LogDevice.new(job)).extend(ActiveSupport::Logger.broadcast(original_logger)))
Copy link
Author

Choose a reason for hiding this comment

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

@bensheldon , the around_perform hook above makes sense to me but what do L10 and L11 do exactly please ?

Copy link
Owner

Choose a reason for hiding this comment

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

This is creating a new logger that outputs to the custom LogDevice, and then teeing the output via broadcast so that the output still goes to the old logger too.

I could probably break this up into multiple lines. e.g.

custom_logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(LogDevice.new(job))
custom.logger.extend(ActiveSupport::Logger.broadcast(original_logger))

ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(LogDevice.new(job)).extend(ActiveSupport::Logger.broadcast(original_logger)))

end

class LogDevice
cattr_accessor :logs, default: Concurrent::Array.new
Copy link
Author

@NeimadTL NeimadTL Nov 1, 2022

Choose a reason for hiding this comment

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

@bensheldon is the c in cattr_accessor to indicate that this is a class attribute

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, it's a class attribute. By living on the class it becomes a singleton that can be access globally.

self.class.logs << [@job.provider_job_id, message.strip]
end

def close
Copy link
Author

@NeimadTL NeimadTL Nov 1, 2022

Choose a reason for hiding this comment

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

I don't think #close and #reopen are overrode method but I might be wrong here. Are those methods mandatory or you think we'll be using them in the future ?

Copy link
Owner

Choose a reason for hiding this comment

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

I'm trying to match the interface of Ruby's LogDevice:

https://github.com/ruby/ruby/blob/9001e53e68d282493f513ed67824e4014fd01d57/lib/logger/log_device.rb

That said, I wonder if it would be better to inherit from LogDevice to be clear that I'm trying to match/override the interface, rather than just be an implicit duck-type.

@bensheldon
Copy link
Owner

@NeimadTL thank you for the awesome Code Review! You raised some great questions about how this could be clearer. I can make those changes 👍

@bensheldon
Copy link
Owner

I'm going to close this for now and revisit in the future.

@bensheldon bensheldon closed this Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

2 participants