All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.slf4j.impl.Slf4jAdapter Maven / Gradle / Ivy

There is a newer version: 7.0.3
Show newest version
/**
 * Copyright (C) 2014-2015 Philip Helger (www.helger.com)
 * philip[at]helger[dot]com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.slf4j.impl;

import org.apache.maven.plugin.logging.Log;
import org.slf4j.helpers.FormattingTuple;
import org.slf4j.helpers.MarkerIgnoringBase;
import org.slf4j.helpers.MessageFormatter;

/**
 * Implementation of {@link org.slf4j.Logger} transforming SLF4J messages to
 * Maven log messages.
 * 

* The class has too many methods, but we can't do anything with this since the * parent class requires us to implement them all. *

* The class is thread-safe. * * @author Yegor Bugayenko ([email protected]) * @version $Id$ * @since 0.1.6 * @see SLF4J FAQ */ final class Slf4jAdapter extends MarkerIgnoringBase { /** * Serialization ID. */ public static final long serialVersionUID = 0x12C0976798AB5439L; /** * The log to use. */ private transient Log m_aMavenLog; /** * Set Maven log. *

* Class variable is used as a synchronization lock, mostly because only one * instance of this class may exist. * * @param log * The log to set */ public void setMavenLog (final Log log) { synchronized (Slf4jAdapter.class) { m_aMavenLog = log; } } /** * {@inheritDoc} */ @Override public String getName () { return getClass ().getName (); } /** * {@inheritDoc} */ public boolean isTraceEnabled () { return false; } /** * {@inheritDoc} */ public void trace (final String msg) { _log ().debug (msg); } /** * {@inheritDoc} */ public void trace (final String format, final Object arg) { _log ().debug (_format (format, arg)); } /** * {@inheritDoc} */ public void trace (final String format, final Object first, final Object second) { _log ().debug (_format (format, first, second)); } /** * {@inheritDoc} */ public void trace (final String format, final Object... array) { _log ().debug (_format (format, array)); } /** * {@inheritDoc} */ public void trace (final String msg, final Throwable thr) { _log ().debug (msg, thr); } /** * {@inheritDoc} */ public boolean isDebugEnabled () { return _log ().isDebugEnabled (); } /** * {@inheritDoc} */ public void debug (final String msg) { _log ().debug (msg); } /** * {@inheritDoc} */ public void debug (final String format, final Object arg) { _log ().debug (_format (format, arg)); } /** * {@inheritDoc} */ public void debug (final String format, final Object first, final Object second) { _log ().debug (_format (format, first, second)); } /** * {@inheritDoc} */ public void debug (final String format, final Object... array) { _log ().debug (_format (format, array)); } /** * {@inheritDoc} */ public void debug (final String msg, final Throwable thr) { _log ().debug (msg, thr); } /** * {@inheritDoc} */ public boolean isInfoEnabled () { return true; } /** * {@inheritDoc} */ public void info (final String msg) { _log ().info (msg); } /** * {@inheritDoc} */ public void info (final String format, final Object arg) { _log ().info (_format (format, arg)); } /** * {@inheritDoc} */ public void info (final String format, final Object first, final Object second) { _log ().info (_format (format, first, second)); } /** * {@inheritDoc} */ public void info (final String format, final Object... array) { _log ().info (_format (format, array)); } /** * {@inheritDoc} */ public void info (final String msg, final Throwable thr) { _log ().info (msg, thr); } /** * {@inheritDoc} */ public boolean isWarnEnabled () { return true; } /** * {@inheritDoc} */ public void warn (final String msg) { _log ().warn (msg); } /** * {@inheritDoc} */ public void warn (final String format, final Object arg) { _log ().warn (_format (format, arg)); } /** * {@inheritDoc} */ public void warn (final String format, final Object... array) { _log ().warn (_format (format, array)); } /** * {@inheritDoc} */ public void warn (final String format, final Object first, final Object second) { _log ().warn (_format (format, first, second)); } /** * {@inheritDoc} */ public void warn (final String msg, final Throwable thr) { _log ().warn (msg, thr); } /** * {@inheritDoc} */ public boolean isErrorEnabled () { return true; } /** * {@inheritDoc} */ public void error (final String msg) { _log ().error (msg); } /** * {@inheritDoc} */ public void error (final String format, final Object arg) { _log ().error (_format (format, arg)); } /** * {@inheritDoc} */ public void error (final String format, final Object first, final Object second) { _log ().error (_format (format, first, second)); } /** * {@inheritDoc} */ public void error (final String format, final Object... array) { _log ().error (_format (format, array)); } /** * {@inheritDoc} */ public void error (final String msg, final Throwable thr) { _log ().error (msg, thr); } /** * Get Maven Log. * * @return The log from Maven plugin */ private Log _log () { if (m_aMavenLog == null) throw new IllegalStateException ("initialize StaticLoggerBinder with #setMavenLog() first"); return m_aMavenLog; } /** * Format with one object. * * @param format * Format to use * @param arg * One argument * @return The message */ private String _format (final String format, final Object arg) { final FormattingTuple tuple = MessageFormatter.format (format, arg); return tuple.getMessage (); } /** * Format with two objects. * * @param format * Format to use * @param first * First argument * @param second * Second argument * @return The message */ private String _format (final String format, final Object first, final Object second) { final FormattingTuple tuple = MessageFormatter.format (format, first, second); return tuple.getMessage (); } /** * Format with array. * * @param format * Format to use * @param array * List of arguments * @return The message */ private String _format (final String format, final Object [] array) { final FormattingTuple tuple = MessageFormatter.format (format, array); return tuple.getMessage (); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy