001/*
002 * ModeShape (http://www.modeshape.org)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *       http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.modeshape.web.jcr;
018
019import org.modeshape.common.i18n.TextI18n;
020import org.modeshape.common.logging.Logger;
021
022/**
023 * Implementation of the {@link org.modeshape.jcr.api.Logger} interface which delegates the logging operations to an I18n based
024 * {@link org.modeshape.common.logging.Logger} implementation, using pass-through {@link TextI18n} objects.
025 *
026 * This should be used in ModeShape's server-side web modules.
027 *
028 * @author Horia Chiorean
029 */
030public final class WebLogger implements org.modeshape.jcr.api.Logger {
031
032    private final Logger logger;
033
034    private WebLogger( Logger logger ) {
035        this.logger = logger;
036    }
037
038    public static org.modeshape.jcr.api.Logger getLogger(Class<?> clazz) {
039        return new WebLogger(Logger.getLogger(clazz));
040    }
041
042    @Override
043    public void debug( String message,
044                       Object... params ) {
045        logger.debug(message, params);
046    }
047
048    @Override
049    public void debug( Throwable t,
050                       String message,
051                       Object... params ) {
052        logger.debug(t, message, params);
053    }
054
055    @Override
056    public void error( String message,
057                       Object... params ) {
058        if (logger.isErrorEnabled()) {
059            logger.error(new TextI18n(message), params);
060        }
061    }
062
063    @Override
064    public void error( Throwable t,
065                       String message,
066                       Object... params ) {
067        if (logger.isErrorEnabled()) {
068            logger.error(t, new TextI18n(message), params);
069        }
070    }
071
072    @Override
073    public void info( String message,
074                      Object... params ) {
075        if (logger.isInfoEnabled()) {
076            logger.info(new TextI18n(message), params);
077        }
078    }
079
080    @Override
081    public void info( Throwable t,
082                      String message,
083                      Object... params ) {
084        if (logger.isInfoEnabled()) {
085            logger.info(t, new TextI18n(message), params);
086        }
087    }
088
089    @Override
090    public void trace( String message,
091                       Object... params ) {
092        logger.trace(message, params);
093    }
094
095    @Override
096    public void trace( Throwable t,
097                       String message,
098                       Object... params ) {
099        logger.trace(t, message, params);
100    }
101
102    @Override
103    public void warn( String message,
104                      Object... params ) {
105        if (logger.isWarnEnabled()) {
106            logger.warn(new TextI18n(message), params);
107        }
108    }
109
110    @Override
111    public void warn( Throwable t,
112                      String message,
113                      Object... params ) {
114        if (logger.isWarnEnabled()) {
115            logger.warn(t, new TextI18n(message), params);
116        }
117    }
118
119    @Override
120    public boolean isInfoEnabled() {
121        return logger.isInfoEnabled();
122    }
123
124    @Override
125    public boolean isWarnEnabled() {
126        return logger.isWarnEnabled();
127    }
128
129    @Override
130    public boolean isErrorEnabled() {
131        return logger.isErrorEnabled();
132    }
133
134    @Override
135    public boolean isDebugEnabled() {
136        return logger.isDebugEnabled();
137    }
138
139    @Override
140    public boolean isTraceEnabled() {
141        return logger.isTraceEnabled();
142    }
143}