Class: RailsCronLogger::Logger
- Inherits:
-
Logger
- Object
- Logger
- RailsCronLogger::Logger
- Defined in:
- lib/rails-cron-logger.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Logger
constructor
A new instance of Logger.
Constructor Details
#initialize(options = {}) ⇒ Logger
Returns a new instance of Logger.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rails-cron-logger.rb', line 6 def initialize(={}) if [:sync] # Flushes output on every write to avoid losing valuable output if the cron job crashes, etc. # see http://coderrr.wordpress.com/2008/12/20/automatically-flushing-redirected-or-piped-stdout/ # Note that this is obviously an interpreter-wide setting we're changing here. # Really this ought to be set at a higher level than the code calling this logger (in the crontab # or in the crontab script that calls your code perhaps) but adding an option here for convenience. $stdout.sync = true end logdev = if [:logdev].present? [:logdev] elsif Rails.env.test? # don't want log messages for tests mixed in with test output Rails.application.config.paths['log'].first else $stdout end super(logdev) @formatter = Rails.logger.formatter @level = Rails.logger.level end |