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
023 * correctly use commons-logging.<br>
024 * I hope i could remove it sometimes.
025 */
026public final class VfsLog
027{
028    // static utility class
029    private VfsLog()
030    {
031    }
032
033    /**
034     * warning.
035     * @param vfslog The base component Logger to use.
036     * @param commonslog The class specific Logger
037     * @param message The message to log.
038     * @param t The exception, if any.
039     */
040    public static void warn(final Log vfslog, final Log commonslog, final String message, final Throwable t)
041    {
042        if (vfslog != null)
043        {
044            vfslog.warn(message, t);
045        }
046        else if (commonslog != null)
047        {
048            commonslog.warn(message, t);
049        }
050    }
051
052    /**
053     * warning.
054     * @param vfslog The base component Logger to use.
055     * @param commonslog The class specific Logger
056     * @param message The message to log.
057     */
058    public static void warn(final Log vfslog, final Log commonslog, final String message)
059    {
060        if (vfslog != null)
061        {
062            vfslog.warn(message);
063        }
064        else if (commonslog != null)
065        {
066            commonslog.warn(message);
067        }
068    }
069
070    /**
071     * debug.
072     * @param vfslog The base component Logger to use.
073     * @param commonslog The class specific Logger
074     * @param message The message to log.
075     */
076    public static void debug(final Log vfslog, final Log commonslog, final String message)
077    {
078        if (vfslog != null)
079        {
080            vfslog.debug(message);
081        }
082        else if (commonslog != null)
083        {
084            commonslog.debug(message);
085        }
086    }
087
088    /**
089     * debug.
090     * @param vfslog The base component Logger to use.
091     * @param commonslog The class specific Logger
092     * @param message The message to log.
093     * @param t The exception, if any.
094     */
095    public static void debug(final Log vfslog, final Log commonslog, final String message, final Throwable t)
096    {
097        if (vfslog != null)
098        {
099            vfslog.debug(message, t);
100        }
101        else if (commonslog != null)
102        {
103            commonslog.debug(message, t);
104        }
105    }
106
107    /**
108     * info.
109     * @param vfslog The base component Logger to use.
110     * @param commonslog The class specific Logger
111     * @param message The message to log.
112     * @param t The exception, if any.
113     */
114    public static void info(final Log vfslog, final Log commonslog, final String message, final Throwable t)
115    {
116        if (vfslog != null)
117        {
118            vfslog.info(message, t);
119        }
120        else if (commonslog != null)
121        {
122            commonslog.info(message, t);
123        }
124    }
125
126    /**
127     * info.
128     * @param vfslog The base component Logger to use.
129     * @param commonslog The class specific Logger
130     * @param message The message to log.
131     */
132    public static void info(final Log vfslog, final Log commonslog, final String message)
133    {
134        if (vfslog != null)
135        {
136            vfslog.info(message);
137        }
138        else if (commonslog != null)
139        {
140            commonslog.info(message);
141        }
142    }
143
144    /**
145     * error.
146     * @param vfslog The base component Logger to use.
147     * @param commonslog The class specific Logger
148     * @param message The message to log.
149     * @param t The exception, if any.
150     */
151    public static void error(final Log vfslog, final Log commonslog, final String message, final Throwable t)
152    {
153        if (vfslog != null)
154        {
155            vfslog.error(message, t);
156        }
157        else if (commonslog != null)
158        {
159            commonslog.error(message, t);
160        }
161    }
162
163    /**
164     * error.
165     * @param vfslog The base component Logger to use.
166     * @param commonslog The class specific Logger
167     * @param message The message to log.
168     */
169    public static void error(final Log vfslog, final Log commonslog, final String message)
170    {
171        if (vfslog != null)
172        {
173            vfslog.error(message);
174        }
175        else if (commonslog != null)
176        {
177            commonslog.error(message);
178        }
179    }
180
181    /**
182     * fatal.
183     * @param vfslog The base component Logger to use.
184     * @param commonslog The class specific Logger
185     * @param message The message to log.
186     * @param t The exception, if any.
187     */
188    public static void fatal(final Log vfslog, final Log commonslog, final String message, final Throwable t)
189    {
190        if (vfslog != null)
191        {
192            vfslog.fatal(message, t);
193        }
194        else if (commonslog != null)
195        {
196            commonslog.fatal(message, t);
197        }
198    }
199
200    /**
201     * fatal.
202     * @param vfslog The base component Logger to use.
203     * @param commonslog The class specific Logger
204     * @param message The message to log.
205     */
206    public static void fatal(final Log vfslog, final Log commonslog, final String message)
207    {
208        if (vfslog != null)
209        {
210            vfslog.fatal(message);
211        }
212        else if (commonslog != null)
213        {
214            commonslog.fatal(message);
215        }
216    }
217}