Class: Wx::LogNull

Inherits:
Object
  • Object
show all
Defined in:
lib/wx/doc/gen/log.rb,
lib/wx/doc/log.rb

Overview

Note:

This class is untracked and should not be derived from nor instances extended!

This class allows you to temporarily suspend logging.

All calls to the log functions during the life time of an object of this class are just ignored. In particular, it can be used to suppress the log messages given by wxWidgets itself but it should be noted that it is rarely the best way to cope with this problem as all log messages are suppressed, even if they indicate a completely different error than the one the programmer wanted to suppress. For instance, the example of the overview:

mime_type = ... # retrieved from somewhere
  img = Wx::Image.new
  Wx::LogNull.no_log do     # suspend logging 

    # Wx::Image#load_stream will complain if there is no handler for the given mimetype and fail
    if !img.load_stream(File.open('file.img'), mime_type)
      # handle problem
    end

  end # old log sink restored
  
  Wx.log_message('...') # ok

would be better written as:

mime_type = ... # retrieved from somewhere

  # check the condition that makes your code complain
  if Wx::Image.mime_types.include?(mime_type)
    img.load_stream(File.open('file.img'), mime_type)
    ...
  else
    # do something else
    ...
  end

Category: Logging

Requires:

  • USE_LOG

Class Method Summary collapse

Class Method Details

.no_log(&block) ⇒ Object

Suspends logging before executing the given block and restarts logging when the block returns.



30
# File 'lib/wx/doc/log.rb', line 30

def self.no_log(&block) end