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