001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.vfs2;
018
019import org.apache.commons.logging.Log;
020
021/**
022 * This class is to keep the old logging behaviour (for ant-task) and to be able to correctly use commons-logging.<br>
023 * I hope i could remove it sometimes.
024 */
025public final class VfsLog {
026    // static utility class
027    private VfsLog() {
028    }
029
030    /**
031     * warning.
032     *
033     * @param vfslog The base component Logger to use.
034     * @param commonslog The class specific Logger
035     * @param message The message to log.
036     * @param t The exception, if any.
037     */
038    public static void warn(final Log vfslog, final Log commonslog, final String message, final Throwable t) {
039        if (vfslog != null) {
040            vfslog.warn(message, t);
041        } else if (commonslog != null) {
042            commonslog.warn(message, t);
043        }
044    }
045
046    /**
047     * warning.
048     *
049     * @param vfslog The base component Logger to use.
050     * @param commonslog The class specific Logger
051     * @param message The message to log.
052     */
053    public static void warn(final Log vfslog, final Log commonslog, final String message) {
054        if (vfslog != null) {
055            vfslog.warn(message);
056        } else if (commonslog != null) {
057            commonslog.warn(message);
058        }
059    }
060
061    /**
062     * debug.
063     *
064     * @param vfslog The base component Logger to use.
065     * @param commonslog The class specific Logger
066     * @param message The message to log.
067     */
068    public static void debug(final Log vfslog, final Log commonslog, final String message) {
069        if (vfslog != null) {
070            vfslog.debug(message);
071        } else if (commonslog != null) {
072            commonslog.debug(message);
073        }
074    }
075
076    /**
077     * debug.
078     *
079     * @param vfslog The base component Logger to use.
080     * @param commonslog The class specific Logger
081     * @param message The message to log.
082     * @param t The exception, if any.
083     */
084    public static void debug(final Log vfslog, final Log commonslog, final String message, final Throwable t) {
085        if (vfslog != null) {
086            vfslog.debug(message, t);
087        } else if (commonslog != null) {
088            commonslog.debug(message, t);
089        }
090    }
091
092    /**
093     * info.
094     *
095     * @param vfslog The base component Logger to use.
096     * @param commonslog The class specific Logger
097     * @param message The message to log.
098     * @param t The exception, if any.
099     */
100    public static void info(final Log vfslog, final Log commonslog, final String message, final Throwable t) {
101        if (vfslog != null) {
102            vfslog.info(message, t);
103        } else if (commonslog != null) {
104            commonslog.info(message, t);
105        }
106    }
107
108    /**
109     * info.
110     *
111     * @param vfslog The base component Logger to use.
112     * @param commonslog The class specific Logger
113     * @param message The message to log.
114     */
115    public static void info(final Log vfslog, final Log commonslog, final String message) {
116        if (vfslog != null) {
117            vfslog.info(message);
118        } else if (commonslog != null) {
119            commonslog.info(message);
120        }
121    }
122
123    /**
124     * error.
125     *
126     * @param vfslog The base component Logger to use.
127     * @param commonslog The class specific Logger
128     * @param message The message to log.
129     * @param t The exception, if any.
130     */
131    public static void error(final Log vfslog, final Log commonslog, final String message, final Throwable t) {
132        if (vfslog != null) {
133            vfslog.error(message, t);
134        } else if (commonslog != null) {
135            commonslog.error(message, t);
136        }
137    }
138
139    /**
140     * error.
141     *
142     * @param vfslog The base component Logger to use.
143     * @param commonslog The class specific Logger
144     * @param message The message to log.
145     */
146    public static void error(final Log vfslog, final Log commonslog, final String message) {
147        if (vfslog != null) {
148            vfslog.error(message);
149        } else if (commonslog != null) {
150            commonslog.error(message);
151        }
152    }
153
154    /**
155     * fatal.
156     *
157     * @param vfslog The base component Logger to use.
158     * @param commonslog The class specific Logger
159     * @param message The message to log.
160     * @param t The exception, if any.
161     */
162    public static void fatal(final Log vfslog, final Log commonslog, final String message, final Throwable t) {
163        if (vfslog != null) {
164            vfslog.fatal(message, t);
165        } else if (commonslog != null) {
166            commonslog.fatal(message, t);
167        }
168    }
169
170    /**
171     * fatal.
172     *
173     * @param vfslog The base component Logger to use.
174     * @param commonslog The class specific Logger
175     * @param message The message to log.
176     */
177    public static void fatal(final Log vfslog, final Log commonslog, final String message) {
178        if (vfslog != null) {
179            vfslog.fatal(message);
180        } else if (commonslog != null) {
181            commonslog.fatal(message);
182        }
183    }
184}