I
Iain Barnett
Hi,
I want to log what's happening when a class method is called, using a =
Logger instance. The code resembles this:=20
=20
module Helpers
def self.included(klass)
klass.extend ClassMethods
end
=20
module ClassMethods
=20
def my_classy_method( arg1, arg2 )
#I want to log in here
...
end
end#ClassMethods
end#Helpers
class User
=20
include Helpers
#boring stuff...
end
#called as such
User.my_classy_method( "blah", "plop" )
I've no idea where I should send the logger instance to that I've =
already set up in the rest of the app. Would someone be good enough to =
enlighten me? Should I perhaps alter the method signature to send the =
logger in as an argument on the end like this:
def my_classy_method( arg1, arg2, options=3D{} )
options[:logger].debug ...
User.my_classy_method( "blah", "plop", {logger: @logger} )
or would that be bad form?
Any help on the matter is much appreciated.
Regards,
Iain=
I want to log what's happening when a class method is called, using a =
Logger instance. The code resembles this:=20
=20
module Helpers
def self.included(klass)
klass.extend ClassMethods
end
=20
module ClassMethods
=20
def my_classy_method( arg1, arg2 )
#I want to log in here
...
end
end#ClassMethods
end#Helpers
class User
=20
include Helpers
#boring stuff...
end
#called as such
User.my_classy_method( "blah", "plop" )
I've no idea where I should send the logger instance to that I've =
already set up in the rest of the app. Would someone be good enough to =
enlighten me? Should I perhaps alter the method signature to send the =
logger in as an argument on the end like this:
def my_classy_method( arg1, arg2, options=3D{} )
options[:logger].debug ...
User.my_classy_method( "blah", "plop", {logger: @logger} )
or would that be bad form?
Any help on the matter is much appreciated.
Regards,
Iain=