The logging initialization and internals may differ, but (insofar as it-works-for-me) they both call the same methods to actually log data.
I currently hook all Rails and DM related logging with one object that derives from Logger. If you simply assign a Logger.new (or anything that implements its methods) instead of calling DM logger initialization (set_log), it'll work. With Rails, in config/environment.rb, after boot.rb but before the initializer block, I hand it a STDOUT logger: require 'delegate' RAILS_DEFAULT_LOGGER = SimpleDelegator.new(Logger.new(STDOUT)) after the initialization block (rails is loaded) I set it to my own Logger-derived class: RAILS_DEFAULT_LOGGER.__setobj__($LOG) The SimpleDelegate trick allows you to redefine RAILS_DEFAULT_LOGGER at will while avoiding any const-redefined warnings -- letting you prevent Rails from setting its own, forcing Rails to use yours, while still letting you redefine it to something else later. With DM, for initialization, instead of calling set_log I set the logger directly (no need for SimpleDelegate since DM isn't using a "constant"): # $LOG is, again, a Logger-derived class ::DataMapper.logger = $LOG if $LOG ::DataMapper.setup(:default, config) and that's it. So define your own Logger-derived class, hook Logger#<< (), and you should be good to go for both Rails and DM. cheers, --jordan On Sep 3, 2009, at 2:28 PM, Ken Mayer wrote: > > We're working on a DataMapper class that is used by a Rails app > (alongside ActiveRecord, no less) and in a daemon that doesn't use > Rails at all. Both have their own logging infrastructure (that differ) > that we want to hook into. So far, we've had lots of luck, none if > good. Any suggestions? > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "DataMapper" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/datamapper?hl=en -~----------~----~----~----~------~----~------~--~---
