Docs request - when should I use hit, and when should I use dam?
Thanks vm for this project which seems like it will really help me with log analysis. I'm trying to get to grips with what hit and dam do. I can see that they both create a Dam object and add it into the list of defined dams. I am trying to work out, why there are 2 methods here, and when should I use 1, and when should I use the other?
I tried the following script, and it seems that hit is able to match each request for some given filter conditions.
Beaver.stream(Rails.configuration.paths['log']) do
hit :posts, :method => :post do |thing|
p thing
end
end
# calls back with a `Beaver::Parsers::Rails` for each post request which makes perfect sense
From the examples, it seems like dam is used to 'batch up' the previously matched requests, maybe at the end, once all the requests have been parsed? Is this right? Would another name for this method be all_hits(:posts) returning an array (with additional methods) of matched hits?
Any guidance would be appreciated.
This is long after your info request, but, here is some information for future seekers:
The block in the hit method executes in a context where only the data for the current matching hit is exposed. You have these methods you can use to get parsed data: << date final! final? ip method params params_str path skip! status time to_s.
The block in the dam method executes in a context where all the collected hits are exposed. It is, as you suspected, a place to analyze the entire collection of hits. You pretty much only have the hits array with which to work.