vendor/gems/logging-0.9.7/lib/logging.rb
def logger( *args )
      opts = args.pop if args.last.instance_of?(Hash)
      opts ||= Hash.new

      dev = args.shift
      keep = age = args.shift
      size = args.shift

      name = case dev
             when String; dev
             when File; dev.path
             else dev.object_id.to_s end

      repo = ::Logging::Repository.instance
      return repo[name] if repo.has_logger? name

      l_opts = {
        :pattern => "%.1l, [%d #%p] %#{::Logging::MAX_LEVEL_LENGTH}l : %m\n",
        :date_pattern => '%Y-%m-%dT%H:%M:%S.%s'
      }
      [:pattern, :date_pattern, :date_method].each do |o|
        l_opts[o] = opts.delete(o) if opts.has_key? o
      end
      layout = ::Logging::Layouts::Pattern.new(l_opts)

      a_opts = Hash.new
      a_opts[:size] = size if size.instance_of?(Fixnum)
      a_opts[:age]  = age  if age.instance_of?(String)
      a_opts[:keep] = keep if keep.instance_of?(Fixnum)
      a_opts[:filename] = dev if dev.instance_of?(String)
      a_opts[:layout] = layout
      a_opts.merge! opts

      appender =
          case dev
          when String
            ::Logging::Appenders::RollingFile.new(name, a_opts)
          else 
            ::Logging::Appenders::IO.new(name, dev, a_opts)
          end

      logger = ::Logging::Logger.new(name)
      logger.add_appenders appender
      logger.additive = false

      class << logger
        def close
          @appenders.each {|a| a.close}
          h = ::Logging::Repository.instance.instance_variable_get :@h
          h.delete(@name)
          class << self; undef :close; end
        end
      end

      logger
    end
# call-seq:
#    Logging.logger( device, age = 7, size = 1048576 )
#    Logging.logger( device, age = 'weekly' )
#
# This convenience method returns a Logger instance configured to behave
# similarly to a core Ruby Logger instance.
#
# The _device_ is the logging destination. This can be a filename
# (String) or an IO object (STDERR, STDOUT, an open File, etc.). The
# _age_ is the number of old log files to keep or the frequency of
# rotation (+daily+, +weekly+, or +monthly+). The _size_ is the maximum
# logfile size and is only used when _age_ is a number.
#
# Using the same _device_ twice will result in the same Logger instance
# being returned. For example, if a Logger is created using STDOUT then
# the same Logger instance will be returned the next time STDOUT is
# used. A new Logger instance can be obtained by closing the previous
# logger instance.
#
#    log1 = Logging.logger(STDOUT)
#    log2 = Logging.logger(STDOUT)
#    log1.object_id == log2.object_id  #=> true
#
#    log1.close
#    log2 = Logging.logger(STDOUT)
#    log1.object_id == log2.object_id  #=> false
#
# The format of the log messages can be changed using a few optional
# parameters. The <tt>:pattern</tt> can be used to change the log
# message format. The <tt>:date_pattern</tt> can be used to change how
# timestamps are formatted. 
#
#    log = Logging.logger(STDOUT,
#              :pattern => "[%d] %-5l : %m\n",
#              :date_pattern => "%Y-%m-%d %H:%M:%S.%s")
#
# See the documentation for the Logging::Layouts::Pattern class for a
# full description of the :pattern and :date_pattern formatting strings.
#
call-seq:
Logging.logger( device, age = 7, size = 1048576 )
Logging.logger( device, age = 'weekly' )

This convenience method returns a Logger instance configured to behave
similarly to a core Ruby Logger instance.

The _device_ is the logging destination. This can be a filename
(String) or an IO object (STDERR, STDOUT, an open File, etc.).

Using the same _device_ twice will result in the same Logger instance
being returned. For example, if a Logger is created using STDOUT then
the same Logger instance will be returned the next time STDOUT is
used. A new Logger instance can be obtained by closing the previous
logger instance.





The format of the log messages can be changed using a few optional
parameters. The :pattern can be used to change the log
message format. The :date_pattern can be used to change how
timestamps are formatted.




call - seq : Logging . logger ( device age = 7 size = 1048576 ) Logging . logger ( device age = ' weekly ' ) This convenience method returns a Logger instance configured to behave similarly to a core Ruby Logger instance . The _device_ is the logging destination . This can be a filename ( String ) or an IO object ( STDERR STDOUT an open File etc . ) . Using the same _device_ twice will result in the same Logger instance being returned . For example if a Logger is created using STDOUT then the same Logger instance will be returned the next time STDOUT is used . A new Logger instance can be obtained by closing the previous logger instance . The format of the log messages can be changed using a few optional parameters . The : pattern can be used to change the log message format . The : date_pattern can be used to change how timestamps are formatted .
def logger( *args )
      opts = args.pop if args.last.instance_of?(Hash)
      opts ||= Hash.new
      dev = args.shift
      keep = age = args.shift
      size = args.shift
      name = case dev
             when String; dev
             when File; dev.path
             else dev.object_id.to_s end
      repo = ::Logging::Repository.instance
      return repo[name] if repo.has_logger? name
      l_opts = {
        :pattern => "%.1l, [%d #%p] %#{::Logging::MAX_LEVEL_LENGTH}l : %m\n",
        :date_pattern => '%Y-%m-%dT%H:%M:%S.%s'
      }
      [:pattern, :date_pattern, :date_method].each do |o|
        l_opts[o] = opts.delete(o) if opts.has_key? o
      end
      layout = ::Logging::Layouts::Pattern.new(l_opts)
      a_opts = Hash.new
      a_opts[:size] = size if size.instance_of?(Fixnum)
      a_opts[:age]  = age  if age.instance_of?(String)
      a_opts[:keep] = keep if keep.instance_of?(Fixnum)
      a_opts[:filename] = dev if dev.instance_of?(String)
      a_opts[:layout] = layout
      a_opts.merge! opts
      appender =
          case dev
          when String
            ::Logging::Appenders::RollingFile.new(name, a_opts)
          else 
            ::Logging::Appenders::IO.new(name, dev, a_opts)
          end
      logger = ::Logging::Logger.new(name)
      logger.add_appenders appender
      logger.additive = false
      class << logger
        def close
          @appenders.each {|a| a.close}
          h = ::Logging::Repository.instance.instance_variable_get :@h
          h.delete(@name)
          class << self; undef :close; end
        end
      end
      logger
    end
def logger ( * args ) opts = args . pop if args . last . instance_of? ( Hash ) opts ||= Hash . new dev = args . shift keep = age = args . shift size = args . shift name = case dev when String ; dev when File ; dev . path else dev . object_id . to_s end repo = :: Logging :: Repository . instance return repo [ name ] if repo . has_logger? name l_opts = { :pattern => "%.1l, [%d #%p] %#{::Logging::MAX_LEVEL_LENGTH}l : %m\n" , :date_pattern => '%Y-%m-%dT%H:%M:%S.%s' } [ :pattern , :date_pattern , :date_method ] . each do | o | l_opts [ o ] = opts . delete ( o ) if opts . has_key? o end layout = :: Logging :: Layouts :: Pattern . new ( l_opts ) a_opts = Hash . new a_opts [ :size ] = size if size . instance_of? ( Fixnum ) a_opts [ :age ] = age if age . instance_of? ( String ) a_opts [ :keep ] = keep if keep . instance_of? ( Fixnum ) a_opts [ :filename ] = dev if dev . instance_of? ( String ) a_opts [ :layout ] = layout a_opts . merge! opts appender = case dev when String :: Logging :: Appenders :: RollingFile . new ( name , a_opts ) else :: Logging :: Appenders :: IO . new ( name , dev , a_opts ) end logger = :: Logging :: Logger . new ( name ) logger . add_appenders appender logger . additive = false class << logger def close @appenders . each { | a | a . close } h = :: Logging :: Repository . instance . instance_variable_get :@h h . delete ( @name ) class << self ; undef :close ; end end end logger end
call-seq:
Logging.logger( device, age = 7, size = 1048576 )
Logging.logger( device, age = 'weekly' )
call - seq : Logging . logger ( device age = 7 size = 1048576 ) Logging . logger ( device age = ' weekly ' )
args