org.gridgain.grid.logger.jboss.GridJbossLogger Maven / Gradle / Ivy
Show all versions of gridgain-hadoop2 Show documentation
/*
Copyright (C) GridGain Systems. All Rights Reserved.
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.gridgain.grid.logger.jboss;
import org.gridgain.grid.logger.*;
import org.gridgain.grid.resources.*;
import org.gridgain.grid.util.lang.*;
import org.jboss.logging.*;
import org.jetbrains.annotations.*;
/**
* Logger to use in JBoss loaders. Implementation simply delegates to
* JBoss logging.
*
* It's recommended to use GridGain logger injection instead of using/instantiating
* logger in your task/job code. See {@link GridLoggerResource} annotation about logger
* injection.
*/
public class GridJbossLogger extends GridMetadataAwareAdapter implements GridLogger {
/** Log4j implementation proxy. */
private Logger impl;
/**
* Creates new logger with given implementation.
*/
public GridJbossLogger() {
this(Logger.getLogger("root"));
}
/**
* Creates new logger with given implementation.
*
* @param impl Log4j implementation to use.
*/
public GridJbossLogger(Logger impl) {
assert impl != null;
this.impl = impl;
}
/** {@inheritDoc} */
@Override public GridJbossLogger getLogger(Object ctgr) {
return new GridJbossLogger(Logger.getLogger(ctgr.toString()));
}
/** {@inheritDoc} */
@Override public void trace(String msg) {
if (!impl.isTraceEnabled())
warning("Logging at TRACE level without checking if TRACE level is enabled: " + msg);
impl.trace(msg);
}
/** {@inheritDoc} */
@Override public void debug(String msg) {
if (!impl.isDebugEnabled())
warning("Logging at DEBUG level without checking if DEBUG level is enabled: " + msg);
impl.debug(msg);
}
/** {@inheritDoc} */
@Override public void info(String msg) {
if (!impl.isInfoEnabled())
warning("Logging at INFO level without checking if INFO level is enabled: " + msg);
impl.info(msg);
}
/** {@inheritDoc} */
@Override public void warning(String msg) {
impl.warn(msg);
}
/** {@inheritDoc} */
@Override public void warning(String msg, @Nullable Throwable e) {
impl.warn(msg, e);
}
/** {@inheritDoc} */
@Override public void error(String msg) {
impl.error(msg);
}
/** {@inheritDoc} */
@Override public void error(String msg, @Nullable Throwable e) {
impl.error(msg, e);
}
/** {@inheritDoc} */
@Override public boolean isQuiet() {
return !isInfoEnabled() && !isDebugEnabled();
}
/** {@inheritDoc} */
@Override public boolean isTraceEnabled() {
return impl.isTraceEnabled();
}
/** {@inheritDoc} */
@Override public boolean isDebugEnabled() {
return impl.isDebugEnabled();
}
/** {@inheritDoc} */
@Override public boolean isInfoEnabled() {
return impl.isInfoEnabled();
}
}