Module: Logback

Defined in:
lib/logback.rb,
lib/logback/base.rb

Overview

– Copyright © 2008 David Kellum

Logback Ruby is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Logback Ruby is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. ++

Defined Under Namespace

Modules: AppenderUtil, Util Classes: ConsoleAppender, FileAppender, Logger, PatternLayout

Constant Summary collapse

Level =

ch.qos.logback.classic.Level

Java::ch.qos.logback.classic.Level
TRACE =

Level::TRACE

Level::TRACE
DEBUG =

Level::DEBUG

Level::DEBUG
INFO =

Level::INFO

Level::INFO
WARN =

Level::WARN

Level::WARN
ERROR =

Level::ERROR

Level::ERROR
DEFAULT_PATTERN =

:nodoc:

"%date [%thread] %-5level %logger{35} - %msg %ex%n"
JoranConfigurator =

ch.qos.logback.classic.joran.JoranConfigurator

Java::ch.qos.logback.classic.joran.JoranConfigurator
JPatternLayout =

ch.qos.logback.classic.PatternLayout

Java::ch.qos.logback.classic.PatternLayout
JConsoleAppender =

ch.qos.logback.core.ConsoleAppender

Java::ch.qos.logback.core.ConsoleAppender
JFileAppender =

ch.qos.logback.core.FileAppender

Java::ch.qos.logback.core.FileAppender
LOGBACK_VERSION =

Logback java version

'0.9.15'
VERSION =

Logback gem version

LOGBACK_VERSION + '.2'
LOGBACK_DIR =

:nodoc:

File.dirname(__FILE__)
@@context =
SLF4J.linked_factory

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object

Synonym for logger(name)



295
296
297
# File 'lib/logback.rb', line 295

def self.[](name)
  logger( name )
end

.config_console(options = {}) ⇒ Object

Configure a single ConsoleAppender using options hash.

Options

:stderr

Output to standard error? (default: false)

:full

Output full date? (default: false, milliseconds)

:thread

Output thread name? (default: false)

:level<Level>

Set root level (default: INFO)

:lwidth<~to_s>

Logger width (default: :full ? 35 : 30)



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/logback.rb', line 270

def self.config_console( options = {} )
  configure do
    console = Logback::ConsoleAppender.new do |a|
      a.target = "System.err" if options[ :stderr ]
      a.layout = Logback::PatternLayout.new do |layout|
        pat = [ options[ :full ] ? '%date' : '%-4r' ]
        pat << '[%thread]' if options[ :thread ]
        pat << '%-5level'
        w = ( options[ :lwidth ] || ( options[ :full ] ? 35 : 30 ) )
        pat << "%logger{#{w}}"
        pat += [ '-', '%msg' '%ex%n' ]
        layout.pattern = pat.join( ' ' )
      end
    end
    Logback.root.add_appender( console )
    Logback.root.level = options[ :level ] || INFO
  end
end

.configure {|context| ... } ⇒ Object

Configure Logback with the specified block. The Logback context is reset, yielded to block, and then started after return from the block.

Yields:



254
255
256
257
258
259
260
261
# File 'lib/logback.rb', line 254

def self.configure
  @@context.reset

  yield context

  Util.start( context )
  nil
end

.contextObject

Returns the LoggerContext



114
115
116
# File 'lib/logback.rb', line 114

def self.context
  @@context
end

.load_xml_config(file) ⇒ Object

Load the specified Logback (Joran) XML configuration file. Should be called within a configure … block.



161
162
163
164
165
# File 'lib/logback.rb', line 161

def self.load_xml_config( file )
  cfger = JoranConfigurator.new
  cfger.context = @@context
  cfger.doConfigure( file )
end

.logger(name) ⇒ Object

Returns the named Logger



290
291
292
# File 'lib/logback.rb', line 290

def self.logger( name )
  Logger.new( @@context.getLogger( name ) )
end

.require_jar(name) ⇒ Object

Load logback jar.



84
85
86
# File 'lib/logback.rb', line 84

def self.require_jar( name )
  require File.join( LOGBACK_DIR, "#{name}-#{ LOGBACK_VERSION }.jar" )
end

.rootObject

Returns the special “root” Logger



300
301
302
# File 'lib/logback.rb', line 300

def self.root
  logger( "root" )
end