Class: Logit::Logger
- Inherits:
-
Logger
- Object
- Logger
- Logit::Logger
- Defined in:
- lib/logit.rb
Overview
Instance Method Summary collapse
- #add(severity, message = nil, progname = nil, &block) ⇒ Object
-
#flush ⇒ Object
flushes any buffered content to the log.
- #format_message(severity, timestamp, progname, msg) ⇒ Object
-
#initialize(log_path, opts = DEFAULT_OPTS) ⇒ Logger
constructor
A new instance of Logger.
Constructor Details
#initialize(log_path, opts = DEFAULT_OPTS) ⇒ Logger
Returns a new instance of Logger.
133 134 135 136 137 138 139 140 |
# File 'lib/logit.rb', line 133 def initialize(log_path, opts = DEFAULT_OPTS) @opts = DEFAULT_OPTS.merge(opts) f = File.open(log_path, @opts[:write_mode]) if (opts[:flush_mode] == :immediate) f.sync = true end super f end |
Instance Method Details
#add(severity, message = nil, progname = nil, &block) ⇒ Object
150 151 152 |
# File 'lib/logit.rb', line 150 def add(severity, = nil, progname = nil, &block) super(severity, , progname, &block) end |
#flush ⇒ Object
flushes any buffered content to the log
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/logit.rb', line 155 def flush # get a handle to the actual file and then synchronize on the mutex # that LogDevice is using (so we don't have the file closed or # swapped out from under us) if @logdev mutex = @logdev.instance_variable_get('@mutex') if (mutex) mutex.synchronize do dev = @logdev.dev if (dev and !dev.closed?) dev.flush() end end end end true end |
#format_message(severity, timestamp, progname, msg) ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/logit.rb', line 142 def (severity, , progname, msg) name = (progname) ? " [#{progname}]" : "" = "#{.strftime('%m-%d-%Y %H:%M:%S')} #{severity.ljust(6)}#{name}: #{msg}\n" puts if @opts[:stdout] end |