Class: Lumberjack::Logger

Inherits:
Object
  • Object
show all
Includes:
Severity
Defined in:
lib/lumberjack/logger.rb

Overview

Logger is a thread safe logging object. It has a compatible API with the Ruby standard library Logger class, the Log4r gem, and ActiveSupport::BufferedLogger.

Example

logger = Lumberjack::Logger.new
logger.info("Starting processing")
logger.debug("Processing options #{options.inspect}")
logger.fatal("OMG the application is on fire!")

Log entries are written to a logging Device if their severity meets or exceeds the log level.

Devices may use buffers internally and the log entries are not guaranteed to be written until you call the flush method. Sometimes this can result in problems when trying to track down extraordinarily long running sections of code since it is likely that none of the messages logged before the long running code will appear in the log until the entire process finishes. You can set the :flush_seconds option on the constructor to force the device to be flushed periodically. This will create a new monitoring thread, but its use is highly recommended.

Each log entry records the log message and severity along with the time it was logged, the program name, process id, and an optional hash of tags. The message will be converted to a string, but otherwise, it is up to the device how these values are recorded. Messages are converted to strings using a Formatter associated with the logger.

Constant Summary

Constants included from Severity

Severity::DEBUG, Severity::ERROR, Severity::FATAL, Severity::INFO, Severity::SEVERITY_LABELS, Severity::UNKNOWN, Severity::WARN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Severity

coerce, label_to_level, level_to_label

Constructor Details

#initialize(device = $stdout, options = {}) ⇒ Logger

Create a new logger to log to a Device.

The device argument can be in any one of several formats.

If it is a Device object, that object will be used. If it has a write method, it will be wrapped in a Device::Writer class. If it is :null, it will be a Null device that won’t record any output. Otherwise, it will be assumed to be file path and wrapped in a Device::LogFile class.

All other options are passed to the device constuctor.

Parameters:

  • device (Lumberjack::Device, Object, Symbol, String) (defaults to: $stdout)

    The device to log to.

  • options (Hash) (defaults to: {})

    The options for the logger.

Options Hash (options):

  • :level (Integer, Symbol, String)

    The logging level below which messages will be ignored.

  • :formatter (Lumberjack::Formatter)

    The formatter to use for outputting messages to the log.

  • :datetime_format (String)

    The format to use for log timestamps.

  • :message_formatter (Lumberjack::Formatter)

    The MessageFormatter to use for formatting log messages.

  • :tag_formatter (Lumberjack::TagFormatter)

    The TagFormatter to use for formatting tags.

  • :progname (String)

    The name of the program that will be recorded with each log entry.

  • :flush_seconds (Numeric)

    The maximum number of seconds between flush calls.

  • :roll (Boolean)

    If the log device is a file path, it will be a Device::DateRollingLogFile if this is set.

  • :max_size (Integer)

    If the log device is a file path, it will be a Device::SizeRollingLogFile if this is set.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/lumberjack/logger.rb', line 67

def initialize(device = $stdout, options = {})
  options = options.dup
  self.level = options.delete(:level) || INFO
  self.progname = options.delete(:progname)
  max_flush_seconds = options.delete(:flush_seconds).to_f

  @logdev = open_device(device, options) if device
  self.formatter = (options[:formatter] || Formatter.new)
  @message_formatter = options[:message_formatter] || Formatter.empty
  @tag_formatter = options[:tag_formatter] || TagFormatter.new
  time_format = options[:datetime_format] || options[:time_format]
  self.datetime_format = time_format if time_format
  @last_flushed_at = Time.now
  @silencer = true
  @tags = {}
  @closed = false

  create_flusher_thread(max_flush_seconds) if max_flush_seconds > 0
end

Instance Attribute Details

#last_flushed_atObject (readonly)

The time that the device was last flushed.



31
32
33
# File 'lib/lumberjack/logger.rb', line 31

def last_flushed_at
  @last_flushed_at
end

#message_formatterObject

The Formatter used only for log entry messages.



40
41
42
# File 'lib/lumberjack/logger.rb', line 40

def message_formatter
  @message_formatter
end

#prognameString

Get the program name associated with log messages.

Returns:

  • (String)


497
498
499
# File 'lib/lumberjack/logger.rb', line 497

def progname
  thread_local_value(:lumberjack_logger_progname) || @progname
end

#silencerObject

Set silencer to false to disable silencing the log.



34
35
36
# File 'lib/lumberjack/logger.rb', line 34

def silencer
  @silencer
end

#tag_formatterObject

The TagFormatter used for formatting tags for output



43
44
45
# File 'lib/lumberjack/logger.rb', line 43

def tag_formatter
  @tag_formatter
end

Instance Method Details

#<<(msg) ⇒ void

This method returns an undefined value.

Add a message when the severity is not known.

Parameters:

  • msg (Object)

    The message to log.



437
438
439
# File 'lib/lumberjack/logger.rb', line 437

def <<(msg)
  add_entry(UNKNOWN, msg)
end

#add(severity, message = nil, progname = nil, &block) ⇒ void Also known as: log

This method returns an undefined value.

::Logger compatible method to add a log entry.

Parameters:

  • severity (Integer, Symbol, String)

    The severity of the message.

  • message (Object) (defaults to: nil)

    The message to log.

  • progname (String) (defaults to: nil)

    The name of the program that is logging the message.



249
250
251
252
253
254
255
256
257
258
259
# File 'lib/lumberjack/logger.rb', line 249

def add(severity, message = nil, progname = nil, &block)
  if message.nil?
    if block
      message = block
    else
      message = progname
      progname = nil
    end
  end
  add_entry(severity, message, progname)
end

#add_entry(severity, message, progname = nil, tags = nil) ⇒ void

This method returns an undefined value.

Add a message to the log with a given severity. The message can be either passed in the message argument or supplied with a block. This method is not normally called. Instead call one of the helper functions fatal, error, warn, info, or debug.

The severity can be passed in either as one of the Severity constants, or as a Severity label.

Examples:


logger.add_entry(Logger::ERROR, exception)
logger.add_entry(Logger::INFO, "Request completed")
logger.add_entry(:warn, "Request took a long time")
logger.add_entry(Logger::DEBUG){"Start processing with options #{options.inspect}"}

Parameters:

  • severity (Integer, Symbol, String)

    The severity of the message.

  • message (Object)

    The message to log.

  • progname (String) (defaults to: nil)

    The name of the program that is logging the message.

  • tags (Hash) (defaults to: nil)

    The tags to add to the log entry.



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/lumberjack/logger.rb', line 202

def add_entry(severity, message, progname = nil, tags = nil)
  severity = Severity.label_to_level(severity) unless severity.is_a?(Integer)
  return true unless device && severity && severity >= level
  return true if Thread.current[:lumberjack_logging]

  begin
    Thread.current[:lumberjack_logging] = true # Prevent circular calls to add_entry

    time = Time.now

    message = message.call if message.is_a?(Proc)
    msg_class_formatter = message_formatter&.formatter_for(message.class)
    if msg_class_formatter
      message = msg_class_formatter.call(message)
    elsif formatter
      message = formatter.format(message)
    end
    message_tags = nil
    if message.is_a?(Formatter::TaggedMessage)
      message_tags = message.tags
      message = message.message
    end

    progname ||= self.progname
    message_tags = Utils.flatten_tags(message_tags) if message_tags

    current_tags = self.tags
    tags = nil unless tags.is_a?(Hash)
    tags = merge_tags(current_tags, tags)
    tags = merge_tags(tags, message_tags) if message_tags
    tags = Tags.expand_runtime_values(tags)
    tags = tag_formatter.format(tags) if tag_formatter

    entry = LogEntry.new(time, severity, message, progname, Process.pid, tags)
    write_to_device(entry)
  ensure
    Thread.current[:lumberjack_logging] = nil
  end
  true
end

#closevoid

This method returns an undefined value.

Close the logging device.



275
276
277
278
279
# File 'lib/lumberjack/logger.rb', line 275

def close
  flush
  device.close if device.respond_to?(:close)
  @closed = true
end

#closed?Boolean

Returns true if the logging device is closed.

Returns:

  • (Boolean)

    true if the logging device is closed.



284
285
286
# File 'lib/lumberjack/logger.rb', line 284

def closed?
  @closed
end

#context(&block) {|TagContext| ... } ⇒ TagContext

Set up a context block for the logger. All tags added within the block will be cleared when the block exits.

Parameters:

  • block (Proc)

    The block to execute with the tag context.

Yields:

  • (TagContext)

    If a block is passed, it will be yielded a TagContext object that can be used to add or remove tags within the context.

Returns:

  • (TagContext)

    If no block is passed, then a Lumberjack::TagContext is returned that can be used to interact with the tags (add, remove, etc.).



534
535
536
537
538
539
540
541
542
543
544
# File 'lib/lumberjack/logger.rb', line 534

def context(&block)
  if block
    thread_tags = thread_local_value(:lumberjack_logger_tags)&.dup
    thread_tags ||= {}
    push_thread_local_value(:lumberjack_logger_tags, thread_tags) do
      block.call(TagContext.new(thread_tags))
    end
  else
    TagContext.new(thread_local_value(:lumberjack_logger_tags) || {})
  end
end

#datetime_formatString?

Get the timestamp format on the device if it has one.

Returns:

  • (String, nil)

    The timestamp format or nil if the device doesn’t support it.



105
106
107
# File 'lib/lumberjack/logger.rb', line 105

def datetime_format
  device.datetime_format if device.respond_to?(:datetime_format)
end

#datetime_format=(format) ⇒ void

This method returns an undefined value.

Set the timestamp format on the device if it is supported.

Parameters:

  • format (String)

    The timestamp format.



113
114
115
116
117
# File 'lib/lumberjack/logger.rb', line 113

def datetime_format=(format)
  if device.respond_to?(:datetime_format=)
    device.datetime_format = format
  end
end

#debug(message_or_progname_or_tags = nil, progname_or_tags = nil, &block) ⇒ void

This method returns an undefined value.

Log a DEBUG message. The message can be passed in either the message argument or in a block.

Parameters:

  • message_or_progname_or_tags (Object) (defaults to: nil)

    The message to log or progname if the message is passed in a block.

  • progname_or_tags (String, Hash) (defaults to: nil)

    The name of the program that is logging the message or tags if the message is passed in a block.



403
404
405
# File 'lib/lumberjack/logger.rb', line 403

def debug(message_or_progname_or_tags = nil, progname_or_tags = nil, &block)
  call_add_entry(DEBUG, message_or_progname_or_tags, progname_or_tags, &block)
end

#debug!void

This method returns an undefined value.

Set the log level to debug.



417
418
419
# File 'lib/lumberjack/logger.rb', line 417

def debug!
  self.level = DEBUG
end

#debug?Boolean

Return true if DEBUG messages are being logged.

Returns:

  • (Boolean)


410
411
412
# File 'lib/lumberjack/logger.rb', line 410

def debug?
  level <= DEBUG
end

#deviceLumberjack::Device

Get the logging device that is used to write log entries.

Returns:



90
91
92
# File 'lib/lumberjack/logger.rb', line 90

def device
  @logdev
end

#device=(device) ⇒ void

This method returns an undefined value.

Set the logging device to a new device.

Parameters:



98
99
100
# File 'lib/lumberjack/logger.rb', line 98

def device=(device)
  @logdev = device.nil? ? nil : open_device(device, {})
end

#error(message_or_progname_or_tags = nil, progname_or_tags = nil, &block) ⇒ void

This method returns an undefined value.

Log an ERROR message. The message can be passed in either the message argument or in a block.

Parameters:

  • message_or_progname_or_tags (Object) (defaults to: nil)

    The message to log or progname if the message is passed in a block.

  • progname_or_tags (String, Hash) (defaults to: nil)

    The name of the program that is logging the message or tags if the message is passed in a block.



328
329
330
# File 'lib/lumberjack/logger.rb', line 328

def error(message_or_progname_or_tags = nil, progname_or_tags = nil, &block)
  call_add_entry(ERROR, message_or_progname_or_tags, progname_or_tags, &block)
end

#error!void

This method returns an undefined value.

Set the log level to error.



342
343
344
# File 'lib/lumberjack/logger.rb', line 342

def error!
  self.level = ERROR
end

#error?Boolean

Return true if ERROR messages are being logged.

Returns:

  • (Boolean)


335
336
337
# File 'lib/lumberjack/logger.rb', line 335

def error?
  level <= ERROR
end

#fatal(message_or_progname_or_tags = nil, progname_or_tags = nil, &block) ⇒ void

This method returns an undefined value.

Log a FATAL message. The message can be passed in either the message argument or in a block.

Parameters:

  • message_or_progname_or_tags (Object) (defaults to: nil)

    The message to log or progname if the message is passed in a block.

  • progname_or_tags (String, Hash) (defaults to: nil)

    The name of the program that is logging the message or tags if the message is passed in a block.



303
304
305
# File 'lib/lumberjack/logger.rb', line 303

def fatal(message_or_progname_or_tags = nil, progname_or_tags = nil, &block)
  call_add_entry(FATAL, message_or_progname_or_tags, progname_or_tags, &block)
end

#fatal!void

This method returns an undefined value.

Set the log level to fatal.



317
318
319
# File 'lib/lumberjack/logger.rb', line 317

def fatal!
  self.level = FATAL
end

#fatal?Boolean

Return true if FATAL messages are being logged.

Returns:

  • (Boolean)


310
311
312
# File 'lib/lumberjack/logger.rb', line 310

def fatal?
  level <= FATAL
end

#flushvoid

This method returns an undefined value.

Flush the logging device. Messages are not guaranteed to be written until this method is called.



266
267
268
269
270
# File 'lib/lumberjack/logger.rb', line 266

def flush
  device.flush
  @last_flushed_at = Time.now
  nil
end

#formatterLumberjack::Formatter

Get the Lumberjack::Formatter used to format objects for logging as messages.

Returns:



159
160
161
162
163
164
165
166
# File 'lib/lumberjack/logger.rb', line 159

def formatter
  if respond_to?(:tagged)
    # Wrap in an object that supports ActiveSupport::TaggedLogger API
    TaggedLoggerSupport::Formatter.new(logger: self, formatter: @_formatter)
  else
    @_formatter
  end
end

#formatter=(value) ⇒ void

This method returns an undefined value.

Set the Lumberjack::Formatter used to format objects for logging as messages.

Parameters:



152
153
154
# File 'lib/lumberjack/logger.rb', line 152

def formatter=(value)
  @_formatter = (value.is_a?(TaggedLoggerSupport::Formatter) ? value.__formatter : value)
end

#in_tag_context?Boolean

Return true if the thread is currently in a Lumberjack::Context block. When the logger is in a context block, tagging will only apply to that block.

Returns:

  • (Boolean)


613
614
615
# File 'lib/lumberjack/logger.rb', line 613

def in_tag_context?
  !!thread_local_value(:lumberjack_logger_tags)
end

#info(message_or_progname_or_tags = nil, progname_or_tags = nil, &block) ⇒ void

This method returns an undefined value.

Log an INFO message. The message can be passed in either the message argument or in a block.

Parameters:

  • message_or_progname_or_tags (Object) (defaults to: nil)

    The message to log or progname if the message is passed in a block.

  • progname_or_tags (String) (defaults to: nil)

    The name of the program that is logging the message or tags if the message is passed in a block.



378
379
380
# File 'lib/lumberjack/logger.rb', line 378

def info(message_or_progname_or_tags = nil, progname_or_tags = nil, &block)
  call_add_entry(INFO, message_or_progname_or_tags, progname_or_tags, &block)
end

#info!void

This method returns an undefined value.

Set the log level to info.



392
393
394
# File 'lib/lumberjack/logger.rb', line 392

def info!
  self.level = INFO
end

#info?Boolean

Return true if INFO messages are being logged.

Returns:

  • (Boolean)


385
386
387
# File 'lib/lumberjack/logger.rb', line 385

def info?
  level <= INFO
end

#levelInteger Also known as: sev_threshold

Get the level of severity of entries that are logged. Entries with a lower severity level will be ignored.

Returns:

  • (Integer)

    The severity level.



123
124
125
# File 'lib/lumberjack/logger.rb', line 123

def level
  thread_local_value(:lumberjack_logger_level) || @level
end

#level=(value) ⇒ void Also known as: sev_threshold=

This method returns an undefined value.

Set the log level using either an integer level like Logger::INFO or a label like :info or “info”

Parameters:

  • value (Integer, Symbol, String)

    The severity level.



134
135
136
# File 'lib/lumberjack/logger.rb', line 134

def level=(value)
  @level = Severity.coerce(value)
end

#log_at(level, &block) ⇒ Object

Provided for compatibility with ActiveSupport::LoggerThreadSafeLevel to temporarily set the log level.

Parameters:

  • level (Integer, String, Symbol)

    The log level to use inside the block.

Returns:

  • (Object)

    The result of the block.



468
469
470
# File 'lib/lumberjack/logger.rb', line 468

def log_at(level, &block)
  with_level(level, &block)
end

#remove_tag(*tag_names) ⇒ void

This method returns an undefined value.

Remove a tag from the current tag context. If this is called inside a tag context, the tags will only be removed for the duration of that block. Otherwise they will be removed from the global tags.

Parameters:

  • tag_names (Array<String, Symbol>)

    The tags to remove.



561
562
563
564
# File 'lib/lumberjack/logger.rb', line 561

def remove_tag(*tag_names)
  tags = thread_local_value(:lumberjack_logger_tags) || @tags
  TagContext.new(tags).delete(*tag_names)
end

#reopen(logdev = nil) ⇒ Object

Reopen the logging device.

Parameters:

  • logdev (Object) (defaults to: nil)

    passed through to the logging device.



291
292
293
294
# File 'lib/lumberjack/logger.rb', line 291

def reopen(logdev = nil)
  @closed = false
  device.reopen(logdev) if device.respond_to?(:reopen)
end

#set_progname(value, &block) ⇒ void

This method returns an undefined value.

Set the program name that is associated with log messages. If a block is given, the program name will be valid only within the block.

Parameters:

  • value (String)

    The program name to use.



477
478
479
480
481
482
483
# File 'lib/lumberjack/logger.rb', line 477

def set_progname(value, &block)
  if block
    push_thread_local_value(:lumberjack_logger_progname, value, &block)
  else
    self.progname = value
  end
end

#silence(temporary_level = ERROR, &block) ⇒ Object

Silence the logger by setting a new log level inside a block. By default, only ERROR or FATAL messages will be logged.

Examples:


logger.level = Logger::INFO
logger.silence do
  do_something   # Log level inside the block is +ERROR+
end

Parameters:

  • temporary_level (Integer, String, Symbol) (defaults to: ERROR)

    The log level to use inside the block.

Returns:

  • (Object)

    The result of the block.



453
454
455
456
457
458
459
460
461
462
# File 'lib/lumberjack/logger.rb', line 453

def silence(temporary_level = ERROR, &block)
  if silencer
    unless temporary_level.is_a?(Integer)
      temporary_level = Severity.label_to_level(temporary_level)
    end
    push_thread_local_value(:lumberjack_logger_level, temporary_level, &block)
  else
    yield
  end
end

#tag(tags, &block) ⇒ void

This method returns an undefined value.

Set a hash of tags on logger. If a block is given, the tags will only be set for the duration of the block. Otherwise the tags will be applied on the current logger context for the duration of that context.

If there is no block or context, the tags will be applied to the global context. This behavior is deprecated. Use the ‘tag_globally` method to set global tags instead.

Parameters:

  • tags (Hash)

    The tags to set.



510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
# File 'lib/lumberjack/logger.rb', line 510

def tag(tags, &block)
  thread_tags = thread_local_value(:lumberjack_logger_tags)
  if block
    merged_tags = (thread_tags ? thread_tags.dup : {})
    TagContext.new(merged_tags).tag(tags)
    push_thread_local_value(:lumberjack_logger_tags, merged_tags, &block)
  elsif thread_tags
    TagContext.new(thread_tags).tag(tags)
    nil
  else
    Utils.deprecated("Lumberjack::Logger#tag", "Lumberjack::Logger#tag must be called with a block or inside a context block. In version 2.0 it will no longer be used for setting global tags. Use Lumberjack::Logger#tag_globally instead.") do
      tag_globally(tags)
    end
  end
end

#tag_globally(tags) ⇒ void

This method returns an undefined value.

Add global tags to the logger that will appear on all log entries.

Parameters:

  • tags (Hash)

    The tags to set.



550
551
552
553
# File 'lib/lumberjack/logger.rb', line 550

def tag_globally(tags)
  TagContext.new(@tags).tag(tags)
  nil
end

#tag_value(name) ⇒ Object?

Get the value of a tag by name from the current tag context.

Parameters:

  • name (String, Symbol)

    The name of the tag to get.

Returns:

  • (Object, nil)

    The value of the tag or nil if the tag does not exist.



584
585
586
587
# File 'lib/lumberjack/logger.rb', line 584

def tag_value(name)
  name = name.join(".") if name.is_a?(Array)
  TagContext.new(tags)[name]
end

#tagged_logger!Lumberjack::Logger

Enable this logger to function like an ActiveSupport::TaggedLogger. This will make the logger API compatible with ActiveSupport::TaggedLogger and is provided as a means of compatibility with other libraries that assume they can call the ‘tagged` method on a logger to add tags.

The tags added with this method are just strings so they are stored in the logger tags in an array under the “tagged” tag. So calling ‘logger.tagged(“foo”, “bar”)` will result in tags `=> [“foo”, “bar”]`.

Returns:



177
178
179
180
# File 'lib/lumberjack/logger.rb', line 177

def tagged_logger!
  extend(TaggedLoggerSupport)
  self
end

#tagsHash

Return all tags in scope on the logger including global tags set on the Lumberjack context, tags set on the logger, and tags set on the current block for the logger.

Returns:

  • (Hash)


570
571
572
573
574
575
576
577
578
# File 'lib/lumberjack/logger.rb', line 570

def tags
  tags = {}
  context_tags = Lumberjack.context_tags
  tags.merge!(context_tags) if context_tags && !context_tags.empty?
  tags.merge!(@tags) if !@tags.empty? && !thread_local_value(:lumberjack_logger_untagged)
  scope_tags = thread_local_value(:lumberjack_logger_tags)
  tags.merge!(scope_tags) if scope_tags && !scope_tags.empty?
  tags
end

#unknown(message_or_progname_or_tags = nil, progname_or_tags = nil, &block) ⇒ void

This method returns an undefined value.

Log a message when the severity is not known. Unknown messages will always appear in the log. The message can be passed in either the message argument or in a block.

Parameters:

  • message_or_progname_or_tags (Object) (defaults to: nil)

    The message to log or progname if the message is passed in a block.

  • progname_or_tags (String, Hash) (defaults to: nil)

    The name of the program that is logging the message or tags if the message is passed in a block.



429
430
431
# File 'lib/lumberjack/logger.rb', line 429

def unknown(message_or_progname_or_tags = nil, progname_or_tags = nil, &block)
  call_add_entry(UNKNOWN, message_or_progname_or_tags, progname_or_tags, &block)
end

#untagged(&block) ⇒ void

This method returns an undefined value.

Remove all tags on the current logger and logging context within a block. You can still set new block scoped tags within theuntagged block and provide tags on individual log methods.



594
595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'lib/lumberjack/logger.rb', line 594

def untagged(&block)
  Lumberjack.use_context(nil) do
    scope_tags = thread_local_value(:lumberjack_logger_tags)
    untagged = thread_local_value(:lumberjack_logger_untagged)
    begin
      set_thread_local_value(:lumberjack_logger_untagged, true)
      set_thread_local_value(:lumberjack_logger_tags, nil)
      tag({}, &block)
    ensure
      set_thread_local_value(:lumberjack_logger_untagged, untagged)
      set_thread_local_value(:lumberjack_logger_tags, scope_tags)
    end
  end
end

#warn(message_or_progname_or_tags = nil, progname_or_tags = nil, &block) ⇒ void

This method returns an undefined value.

Log a WARN message. The message can be passed in either the message argument or in a block.

Parameters:

  • message_or_progname_or_tags (Object) (defaults to: nil)

    The message to log or progname if the message is passed in a block.

  • progname_or_tags (String, Hash) (defaults to: nil)

    The name of the program that is logging the message or tags if the message is passed in a block.



353
354
355
# File 'lib/lumberjack/logger.rb', line 353

def warn(message_or_progname_or_tags = nil, progname_or_tags = nil, &block)
  call_add_entry(WARN, message_or_progname_or_tags, progname_or_tags, &block)
end

#warn!void

This method returns an undefined value.

Set the log level to warn.



367
368
369
# File 'lib/lumberjack/logger.rb', line 367

def warn!
  self.level = WARN
end

#warn?Boolean

Return true if WARN messages are being logged.

Returns:

  • (Boolean)


360
361
362
# File 'lib/lumberjack/logger.rb', line 360

def warn?
  level <= WARN
end

#with_level(severity, &block) ⇒ Object

Adjust the log level during the block execution for the current Fiber only.

Parameters:

  • severity (Integer, Symbol, String)

    The severity level.

Returns:

  • (Object)

    The result of the block.



144
145
146
# File 'lib/lumberjack/logger.rb', line 144

def with_level(severity, &block)
  push_thread_local_value(:lumberjack_logger_level, Severity.coerce(severity), &block)
end

#with_progname(value) {|Object| ... } ⇒ Object

Set the logger progname for the duration of the block.

Parameters:

  • value (String)

    The program name to use.

Yields:

  • (Object)

    The block to execute with the program name set.

Returns:

  • (Object)

    The result of the block.



490
491
492
# File 'lib/lumberjack/logger.rb', line 490

def with_progname(value, &block)
  set_progname(value, &block)
end