Class: Tengine::Support::Config::Logger

Inherits:
Object
  • Object
show all
Includes:
Definition
Defined in:
lib/tengine/support/config/logger.rb

Instance Attribute Summary collapse

Attributes included from Definition

#__name__, #__parent__, #children

Instance Method Summary collapse

Methods included from Definition

#[], #[]=, #accept_visitor, #action?, #child_by_name, #find, #get_value, included, #instantiate_children, #load, #long_opt, #name_array, #root, #separator?, #short_opt, #to_hash

Instance Attribute Details

#formatterObject

formatterにはprocしか設定できないので特別設定ファイルやコマンドラインオプションで指定することはできません。 もしformatteを指す名前を指定したい場合は、別途定義したfieldをから求めたformatterの値を、 オーバーライドしたnew_loggerで設定するようにしてください。



45
46
47
# File 'lib/tengine/support/config/logger.rb', line 45

def formatter
  @formatter
end

Instance Method Details

#new_logger(options = {}) ⇒ Object

field :formatter, ‘Logging formatter, as a Proc that will take four arguments and return the formatted message.’,

:type => :proc, :hidden => true


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/tengine/support/config/logger.rb', line 49

def new_logger(options = {})
  options = ActiveSupport::HashWithIndifferentAccess.new(to_hash).update(options || {})
  case output = options[:output]
  when "NULL" then return Tengine::Support::NullLogger.new
  when "STDOUT" then dev = STDOUT
  when "STDERR" then dev = STDERR
  else dev = output
  end
  rotation = options[:rotation]
  shift_age = (rotation =~ /\A\d+\Z/) ? rotation.to_i : rotation
  dtf = options[:datetime_format]
  result = ::Logger.new(dev, shift_age, options[:rotation_size])
  result.formatter = (options[:formatter] || dtf) ? Logger::Formatter.new : nil
  result.datetime_format = dtf if dtf
  result.level = ::Logger.const_get(options[:level].to_s.upcase)
  progname = options[:progname]
  result.progname = progname if progname
  result
end