Class: ActiveSupport::BufferedLogger
- Includes:
- Severity
- Defined in:
- lib/active_support/buffered_logger.rb
Overview
Inspired by the buffered logger idea by Ezra
Defined Under Namespace
Modules: Severity
Constant Summary collapse
- MAX_BUFFER_SIZE =
1000
Constants included from Severity
Severity::DEBUG, Severity::ERROR, Severity::FATAL, Severity::INFO, Severity::UNKNOWN, Severity::WARN
Instance Attribute Summary collapse
-
#auto_flushing ⇒ Object
Returns the value of attribute auto_flushing.
Instance Method Summary collapse
- #add(severity, message = nil, progname = nil, &block) ⇒ Object
- #close ⇒ Object
- #flush ⇒ Object
-
#initialize(log, level = DEBUG) ⇒ BufferedLogger
constructor
A new instance of BufferedLogger.
- #level ⇒ Object
- #level=(l) ⇒ Object
- #open_log(log, mode) ⇒ Object
- #respond_to?(method, include_private = false) ⇒ Boolean
-
#silence(temporary_level = ERROR) ⇒ Object
Silences the logger for the duration of the block.
-
#silencer ⇒ Object
:singleton-method: Set to false to disable the silencer.
Constructor Details
#initialize(log, level = DEBUG) ⇒ BufferedLogger
Returns a new instance of BufferedLogger.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/active_support/buffered_logger.rb', line 47 def initialize(log, level = DEBUG) @log_dest = log unless log.respond_to?(:write) unless File.exist?(File.dirname(log)) ActiveSupport::Deprecation.warn(<<-eowarn) Automatic directory creation for '#{log}' is deprecated. Please make sure the directory for your log file exists before creating the logger. eowarn FileUtils.mkdir_p(File.dirname(log)) end end @log = open_logfile log self.level = level end |
Instance Attribute Details
#auto_flushing ⇒ Object
Returns the value of attribute auto_flushing.
44 45 46 |
# File 'lib/active_support/buffered_logger.rb', line 44 def auto_flushing @auto_flushing end |
Instance Method Details
#add(severity, message = nil, progname = nil, &block) ⇒ Object
79 80 81 |
# File 'lib/active_support/buffered_logger.rb', line 79 def add(severity, = nil, progname = nil, &block) @log.add(severity, , progname, &block) end |
#close ⇒ Object
116 117 118 |
# File 'lib/active_support/buffered_logger.rb', line 116 def close @log.close end |
#flush ⇒ Object
107 108 |
# File 'lib/active_support/buffered_logger.rb', line 107 def flush end |
#level ⇒ Object
71 72 73 |
# File 'lib/active_support/buffered_logger.rb', line 71 def level @log.level end |
#level=(l) ⇒ Object
75 76 77 |
# File 'lib/active_support/buffered_logger.rb', line 75 def level=(l) @log.level = l end |
#open_log(log, mode) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/active_support/buffered_logger.rb', line 63 def open_log(log, mode) open(log, mode).tap do |open_log| open_log.set_encoding(Encoding::BINARY) if open_log.respond_to?(:set_encoding) open_log.sync = true end end |
#respond_to?(method, include_private = false) ⇒ Boolean
111 112 113 114 |
# File 'lib/active_support/buffered_logger.rb', line 111 def respond_to?(method, include_private = false) return false if method.to_s == "flush" super end |
#silence(temporary_level = ERROR) ⇒ Object
Silences the logger for the duration of the block.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/active_support/buffered_logger.rb', line 30 def silence(temporary_level = ERROR) if silencer begin logger = self.class.new @log_dest.dup, temporary_level yield logger ensure logger.close end else yield self end end |
#silencer ⇒ Object
:singleton-method: Set to false to disable the silencer
26 |
# File 'lib/active_support/buffered_logger.rb', line 26 cattr_accessor :silencer |