Module: SLF4J::JUL

Defined in:
lib/slf4j/jul.rb,
lib/slf4j/jul-to-slf4j.rb

Overview

Utilities for finer grain control of the JDK java.util.logging (JUL). In particular, unlike other logging API’s reimplemented by slf4j adapters, JUL log levels remain significant for enabling output or avoiding log message generation cycles. For a particular level to be output, both JUL and the destination SLF4J output adapter must enable it.

Usage

Adjust JUL levels (in conjunction with ‘slf4j/jul-to-slf4j’ or ‘slf4j/jdk14’, see SLF4J.)

require 'slf4j/jul'
SLF4J::JUL[ "my.jul.logger" ].level = SLF4J::JUL::FINER

Direct all output to SLF4J (output adapter != ‘jdk14’)

require 'slf4j/jul-to-slf4j'
SLF4J::JUL.replace_root_handlers

Constant Summary collapse

LogManager =
Java::java.util.logging.LogManager
Logger =
Java::java.util.logging.Logger
Level =
Java::java.util.logging.Level
SEVERE =
Level::SEVERE
WARNING =
Level::WARNING
INFO =
Level::INFO
CONFIG =
Level::CONFIG
FINE =
Level::FINE
FINER =
Level::FINER
FINEST =
Level::FINEST
ALL =
Level::ALL

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object

Get java.util.logging.Logger by name (responds to level=, etc.)



68
69
70
# File 'lib/slf4j/jul.rb', line 68

def self.[]( name )
  Logger.get_logger( name )
end

.replace_root_handlersObject

Replace any existing configured root java.util.Logger Handlers with the org.slf4j.bridge.SLF4JBridgeHandler



10
11
12
13
14
15
16
17
18
# File 'lib/slf4j/jul-to-slf4j.rb', line 10

def self.replace_root_handlers
  root_logger = root
  root_logger.handlers.each do |handler|
    root_logger.remove_handler( handler )
  end
  handler = Java::org.slf4j.bridge.SLF4JBridgeHandler.new

  root_logger.add_handler( handler )
end

.resetObject

Global java.util.logging.LogManager reset: close any handlers and set root level to INFO.



63
64
65
# File 'lib/slf4j/jul.rb', line 63

def self.reset
  LogManager.log_manager.reset
end

.rootObject

Get the root logger (empty string name)



73
74
75
# File 'lib/slf4j/jul.rb', line 73

def self.root
  Logger.get_logger( "" )
end