Custom Rails Application Logging

I am trying to add custom logging to my rails app via a ‘.rb’ module
file in the ‘/lib’ directory and then call it from my models via
CallBacks (ie: before_save, after_save, etc).

It loads the module just fine in my class and the CallBack executes the
module’s code. However, my module (remember it’s in the ‘/lib’
directory) doesn’t have access to the application’s ‘session’ variable.

There are two ways I can see I can go about solving this (neither of
which I know how to do).

One, I find a way to specify parameters to my method I reference in my
call back ie: “before_save :log_user_save(session[:user], self)”
(syntax??)

Two, I put my module somewhere else so that my models can access it and
the module has access to the ‘session’ variable (probably what I am
going to have to do).

It would be nice if I can keep it in the ‘/lib’ directory so that if I
ever want to call it from a controller or view (for whatever reason) I
can do so.

Thanks for your help.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs