Example usage for org.apache.commons.logging LogFactory getInstance

List of usage examples for org.apache.commons.logging LogFactory getInstance

Introduction

In this page you can find the example usage for org.apache.commons.logging LogFactory getInstance.

Prototype

@Deprecated
public Log getInstance(String name) 

Source Link

Document

Convenience method to return a named logger.

Usage

From source file:org.acmsl.commons.logging.UniqueLogFactory.java

/**
 * Convenience method to derive a name from the specified class and
 * call <code>getInstance(String)</code> with it.
 * @param clazz Class for which a suitable Log name will be derived
 * @param log the cached log instance./*  w  w w  .  ja  v a2s  .  c o m*/
 * @throws LogConfigurationException if a suitable <code>Log</code>
 * instance cannot be returned
 * @param <T> the type.
 * @return the instance.
 */
@Nullable
protected <T> Log getInstance(@NotNull final Class<T> clazz, @Nullable final Log log)
        throws LogConfigurationException {
    @Nullable
    final Log result;

    @Nullable
    final LogFactory t_LogFactory = LogFactory.getFactory();

    if (t_LogFactory != null) {
        result = t_LogFactory.getInstance(clazz);
    } else {
        result = log;
    }

    return result;
}

From source file:org.acmsl.commons.logging.UniqueLogFactory.java

/**
 * <p>Construct (if necessary) and return a <code>Log</code> instance,
 * using the factory's current set of configuration attributes.</p>
 * <p><strong>NOTE</strong> - Depending upon the implementation of
 * the <code>LogFactory</code> you are using, the <code>Log</code>
 * instance you are returned may or may not be local to the current
 * application, and may or may not be returned again on a subsequent
 * call with the same name argument.</p>
 * @param name Logical name of the <code>Log</code> instance to be
 * returned (the meaning of this name is only known to the underlying
 * logging implementation that is being wrapped)
 * @param log the possibly cached log instance.
 * @throws LogConfigurationException if a suitable <code>Log</code>
 * instance cannot be returned/*from   w  ww .  j  ava  2s.  com*/
 * @return the log instance.
 */
@Nullable
public Log getInstance(@NotNull final String name, @Nullable final Log log) throws LogConfigurationException {
    @Nullable
    final Log result;

    if (log == null) {
        @Nullable
        final LogFactory t_LogFactory = LogFactory.getFactory();

        if (t_LogFactory != null) {
            result = t_LogFactory.getInstance(name);
        } else {
            result = null;
        }
    } else {
        result = log;
    }

    return result;
}

From source file:org.acmsl.queryj.tools.logging.QueryJLogFactory.java

/**
 * Convenience method to derive a name from the specified class and
 * call <code>getInstance(String)</code> with it.
 * @param clazz Class for which a suitable Log name will be derived
 * @param log the cached log instance.// ww w  . j a va 2  s .co  m
 * @return the {@link Log} instance.
 */
@Nullable
protected Log getInstance(@NotNull final Class<?> clazz, @Nullable final Log log)
        throws LogConfigurationException {
    @Nullable
    Log result = log;

    @Nullable
    final LogFactory t_LogFactory = LogFactory.getFactory();

    if (t_LogFactory != null) {
        result = t_LogFactory.getInstance(clazz);
    }

    return result;
}

From source file:org.acmsl.queryj.tools.logging.QueryJLogFactory.java

/**
 * <p>Construct (if necessary) and return a <code>Log</code> instance,
 * using the factory's current set of configuration attributes.</p>
 * <p><strong>NOTE</strong> - Depending upon the implementation of
 * the <code>LogFactory</code> you are using, the <code>Log</code>
 * instance you are returned may or may not be local to the current
 * application, and may or may not be returned again on a subsequent
 * call with the same name argument.</p>
 * @param name Logical name of the <code>Log</code> instance to be
 * returned (the meaning of this name is only known to the underlying
 * logging implementation that is being wrapped)
 * @param log the possibly cached log instance.
 * @return the {@link Log} instance.//w w  w  . j  ava  2  s.  c o m
 * @throws LogConfigurationException in case of misconfiguration.
 */
@Nullable
public Log getInstance(@NotNull final String name, @Nullable final Log log) throws LogConfigurationException {
    @Nullable
    Log result = log;

    if (result == null) {
        @Nullable
        final LogFactory t_LogFactory = LogFactory.getFactory();

        if (t_LogFactory != null) {
            result = t_LogFactory.getInstance(name);
        }
    }

    return result;
}

From source file:org.apache.ftpserver.ConnectionManagerImpl.java

/**
 * Set the log factory.
 */
public void setLogFactory(LogFactory factory) {
    m_log = factory.getInstance(getClass());
}

From source file:org.apache.ftpserver.filesystem.OSVirualFileSystemView.java

/**
 * Constructor - set the user object.//from   w w w  .  j a v a 2 s  .  c o  m
 */
public OSVirualFileSystemView(User user, LogFactory factory) throws FtpException {

    m_log = factory.getInstance(getClass());
    try {
        File root = new File(user.getHomeDirectory());
        m_rootName = root.getCanonicalPath();
        m_rootName = OSVirtualFileObject.normalizeSeparateChar(m_rootName);
        if (!m_rootName.endsWith("/")) {
            m_rootName += '/';
        }

        m_hasWritePermission = user.getWritePermission();
        m_currDir = new OSVirtualFileObject(root, m_rootName, m_hasWritePermission);
    } catch (IOException ex) {
        m_log.warn("OSVirualFileSystemView.OSVirualFileSystemView()", ex);
        throw new FtpException("OSVirualFileSystemView.OSVirualFileSystemView()", ex);
    }
}

From source file:org.cache2k.benchmark.impl2015.util.Log.java

public static synchronized Log getLog(String s) {
    Log l = loggers.get(s);//from  w ww .  ja  v  a 2s.co m
    if (l != null) {
        return l;
    }
    if (logFactory != null) {
        l = logFactory.getLog(s);
        loggers.put(s, l);
        return l;
    }
    ServiceLoader<LogFactory> loader = ServiceLoader.load(LogFactory.class);
    for (LogFactory lf : loader) {
        logFactory = lf;
        getLog(Log.class.getName()).debug("New instance, using: " + logFactory);
        return getLog(s);
    }
    try {
        final org.apache.commons.logging.LogFactory cl = org.apache.commons.logging.LogFactory.getFactory();
        logFactory = new LogFactory() {
            @Override
            public Log getLog(String s) {
                return new CommonsLogger(cl.getInstance(s));
            }
        };
        getLog(Log.class.getName()).debug("New instance, using: " + logFactory);
        return getLog(s);
    } catch (NoClassDefFoundError ignore) {
    }
    logFactory = new LogFactory() {
        @Override
        public Log getLog(String s) {
            return new JdkLogger(Logger.getLogger(s));
        }
    };
    getLog(Log.class.getName()).debug("New instance, using: " + logFactory);
    return getLog(s);
}

From source file:org.cache2k.core.util.Log.java

/**
 * Finds a logger we can use. First we start with looking for a registered
 * service provider. Then apache commons logging. As a fallback we use JDK logging.
 *//*from   w  w  w .  ja  v a  2  s  . co m*/
private static void initializeLogFactory() {
    ServiceLoader<LogFactory> loader = ServiceLoader.load(LogFactory.class);
    for (LogFactory lf : loader) {
        logFactory = lf;
        log("New instance, using: " + logFactory.getClass().getName());
        return;
    }
    try {
        final org.slf4j.ILoggerFactory lf = org.slf4j.LoggerFactory.getILoggerFactory();
        if (!(lf instanceof NOPLoggerFactory)) {
            logFactory = new LogFactory() {
                @Override
                public Log getLog(String s) {
                    return new Slf4jLogger(lf.getLogger(s));
                }
            };
            log("New instance, using SLF4J logging");
            return;
        }
    } catch (NoClassDefFoundError ignore) {
    }
    try {
        final org.apache.commons.logging.LogFactory cl = org.apache.commons.logging.LogFactory.getFactory();
        logFactory = new LogFactory() {
            @Override
            public Log getLog(String s) {
                return new CommonsLogger(cl.getInstance(s));
            }
        };
        log("New instance, using commons logging");
        return;
    } catch (NoClassDefFoundError ignore) {
    }
    logFactory = new LogFactory() {
        @Override
        public Log getLog(String s) {
            return new JdkLogger(Logger.getLogger(s));
        }
    };
    log("New instance, using JDK logging");
}