Class: TorqueBox::Logger

Inherits:
Object
  • Object
show all
Defined in:
core/lib/torquebox/logger.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Logger) initialize(name = nil)

Returns a new instance of Logger



63
64
65
66
67
# File 'core/lib/torquebox/logger.rb', line 63

def initialize name = nil
  category = name || (TORQUEBOX_APP_NAME if defined? TORQUEBOX_APP_NAME) || "TorqueBox"
  @logger = org.jboss.logging::Logger.getLogger( category.to_s.gsub('::','.') )
  @formatter = ::Logger::Formatter.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method, *args, &block)



108
109
110
111
112
113
114
115
116
117
118
# File 'core/lib/torquebox/logger.rb', line 108

def method_missing(method, *args, &block)
  delegate = method
  self.class.class_eval do
    define_method(method) do |*a, &b|
      params = params_for_logger(a, b)
      params = [""] if params.empty?
      @logger.send(delegate, *params)
    end
  end
  self.send(method, *args, &block)
end

Instance Attribute Details

- (Object) :formatter

Returns the value of attribute :formatter



61
62
63
# File 'core/lib/torquebox/logger.rb', line 61

def :formatter
  @:formatter
end

- (Object) :level

Returns the value of attribute :level



87
88
89
# File 'core/lib/torquebox/logger.rb', line 87

def :level
  @:level
end

Instance Method Details

- (Object) add(severity, message, progname, &block)



89
90
91
92
93
94
95
96
# File 'core/lib/torquebox/logger.rb', line 89

def add(severity, message, progname, &block)
  severities = ['debug', 'info', 'warn', 'error', 'fatal']
  # default to warn for unknown log level since jboss logger
  # doesn't support unknown
  delegate = severity > (severities.length - 1) ? 'warn' : severities[severity]
  params = params_for_logger([message, progname], block)
  @logger.send(delegate, *params)
end

- (Boolean) debug?

Returns:

  • (Boolean)


77
78
79
# File 'core/lib/torquebox/logger.rb', line 77

def debug?
  @logger.debug_enabled?
end

- (Object) flush



127
128
# File 'core/lib/torquebox/logger.rb', line 127

def flush
end

- (Boolean) info?

Returns:

  • (Boolean)


73
74
75
# File 'core/lib/torquebox/logger.rb', line 73

def info?
  @logger.info_enabled?
end

- (Object) params_for_logger(args, block)



132
133
134
# File 'core/lib/torquebox/logger.rb', line 132

def params_for_logger(args, block)
  [ args[0] || (block && block.call) ].compact
end

- (Object) puts(message)



121
122
123
# File 'core/lib/torquebox/logger.rb', line 121

def puts(message)
  info message.to_s
end

- (Boolean) trace?

Returns:

  • (Boolean)


81
82
83
# File 'core/lib/torquebox/logger.rb', line 81

def trace?
  @logger.trace_enabled?
end

- (Object) write(message)



124
125
126
# File 'core/lib/torquebox/logger.rb', line 124

def write(message)
  info message.strip
end