Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright (c) 2004-2008
   * All rights reserved.
   * Permission is hereby granted, free  of charge, to any person obtaining
   * a  copy  of this  software  and  associated  documentation files  (the
   * "Software"), to  deal in  the Software without  restriction, including
   * without limitation  the rights to  use, copy, modify,  merge, publish,
   * distribute,  sublicense, and/or sell  copies of  the Software,  and to
  * permit persons to whom the Software  is furnished to do so, subject to
  * the following conditions:
  * The  above  copyright  notice  and  this permission  notice  shall  be
  * included in all copies or substantial portions of the Software.
 package org.slf4j;
 import java.util.List;
The LoggerFactory is a utility class producing Loggers for various logging APIs, most notably for log4j, logback and JDK 1.4 logging. Other implementations such as NOPLogger and SimpleLogger are also supported.

LoggerFactory is essentially a wrapper around an ILoggerFactory instance bound with LoggerFactory at compile time.

Please note that all methods in LoggerFactory are static.

Ceki Gülcü
 public final class LoggerFactory {
   static final String NO_STATICLOGGERBINDER_URL = "";
   static final String NULL_LF_URL = "";
   static final String VERSION_MISMATCH = "";
   static final String SUBSTITUTE_LOGGER_URL = "";
   static final String UNSUCCESSFUL_INIT_URL = "";
   static final String UNSUCCESSFUL_INIT_MSG = "org.slf4j.LoggerFactory could not be successfully initialized. See also "
       + ;
   static final int UNINITIALIZED = 0;
   static final int ONGOING_INITILIZATION = 1;
   static final int FAILED_INITILIZATION = 2;
   static final int SUCCESSFUL_INITILIZATION = 3;
   static final int GET_SINGLETON_INEXISTENT = 1;
   static final int GET_SINGLETON_EXISTS = 2;
   static int INITIALIZATION_STATE = ;
   static int GET_SINGLETON_METHOD = ;
It is our responsibility to track version changes and manage the compatibility list.

   static private final String[] API_COMPATIBILITY_LIST = new String[] {
       "1.5.5""1.5.6" };
   // private constructor prevents instantiation
   private LoggerFactory() {

Force LoggerFactory to consider itself uninitialized.

This method is intended to be called by classes (in the same package) for testing purposes. This method is internal. It can be modified, renamed or removed at any time without notice. You are strongly discouraged from calling this method in production code.

   static void reset() {
  private final static void performInitialization() {
  private final static void bind() {
    try {
      // the next line does the binding
    } catch (NoClassDefFoundError ncde) {
      String msg = ncde.getMessage();
      if (msg != null && msg.indexOf("org/slf4j/impl/StaticLoggerBinder") != -1) {
            .reportFailure("Failed to load class \"org.slf4j.impl.StaticLoggerBinder\".");
        Util.reportFailure("See " + 
            + " for further details.");
      throw ncde;
    } catch (Exception e) {
      // we should never get here
      Util.reportFailure("Failed to instantiate logger ["
          + getSingleton().getLoggerFactoryClassStr() + "]"e);
  private final static void emitSubstitureLoggerWarning() {
    List loggerNameList = .getLoggerNameList();
    if (loggerNameList.size() == 0) {
        .reportFailure("The following loggers will not work becasue they were created");
        .reportFailure("during the default configuration phase of the underlying logging system.");
    Util.reportFailure("See also " + );
    for (int i = 0; i < loggerNameList.size(); i++) {
      String loggerName = (StringloggerNameList.get(i);
  private final static void versionSanityCheck() {
    try {
      boolean match = false;
      for (int i = 0; i < .i++) {
        if ([i].equals(requested)) {
          match = true;
      if (!match) {
        Util.reportFailure("The requested version " + requested
            + " by your slf4j binding is not compatible with "
            + Arrays.toString());
        Util.reportFailure("See " +  + " for further details.");
    } catch (java.lang.NoSuchFieldError nsfe) {
      // given our large user base and SLF4J's commitment to backward
      // compatibility, we cannot cry here. Only for implementations
      // which willingly declare a REQUESTED_API_VERSION field do we
      // emit compatibility warnings.
    } catch (Throwable e) {
      // we should never reach here
          "Unexpected problem occured during version sanity check"e);
  private final static StaticLoggerBinder getSingleton() {
      return .;
      return StaticLoggerBinder.getSingleton();
    try  {
      StaticLoggerBinder singleton = StaticLoggerBinder.getSingleton();
      return singleton;
    } catch(NoSuchMethodError nsme) {
      return .;
Return a logger named according to the name parameter using the statically bound ILoggerFactory instance.

name The name of the logger.
  public static Logger getLogger(String name) {
    ILoggerFactory iLoggerFactory = getILoggerFactory();
    return iLoggerFactory.getLogger(name);

Return a logger named corresponding to the class passed as parameter, using the statically bound ILoggerFactory instance.

clazz the returned logger will be named after clazz
  public static Logger getLogger(Class clazz) {
    return getLogger(clazz.getName());

Return the ILoggerFactory instance in use.

ILoggerFactory instance is bound with this class at compile time.

the ILoggerFactory instance in use
  public static ILoggerFactory getILoggerFactory() {
    switch () {
      return getSingleton().getLoggerFactory();
      // support re-entrant behavior.
      // See also
      return ;
    throw new IllegalStateException("Unreachable code");
New to GrepCode? Check out our FAQ X