View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.vfs2;
18  
19  import org.apache.commons.logging.Log;
20  
21  /**
22   * This class is to keep the old logging behavior (for ant-task) and to be able to correctly use commons-logging.
23   * I hope I could remove it sometimes.
24   */
25  public final class VfsLog {
26  
27      /**
28       * debug.
29       *
30       * @param vfsLog The base component Logger to use.
31       * @param commonslog The class specific Logger
32       * @param message The message to log.
33       */
34      public static void debug(final Log vfsLog, final Log commonslog, final String message) {
35          if (vfsLog != null) {
36              vfsLog.debug(message);
37          } else if (commonslog != null) {
38              commonslog.debug(message);
39          }
40      }
41  
42      /**
43       * debug.
44       *
45       * @param vfsLog The base component Logger to use.
46       * @param commonsLog The class specific Logger
47       * @param message The message to log.
48       * @param t The exception, if any.
49       */
50      public static void debug(final Log vfsLog, final Log commonsLog, final String message, final Throwable t) {
51          if (vfsLog != null) {
52              vfsLog.debug(message, t);
53          } else if (commonsLog != null) {
54              commonsLog.debug(message, t);
55          }
56      }
57  
58      /**
59       * error.
60       *
61       * @param vfsLog The base component Logger to use.
62       * @param commonsLog The class specific Logger
63       * @param message The message to log.
64       */
65      public static void error(final Log vfsLog, final Log commonsLog, final String message) {
66          if (vfsLog != null) {
67              vfsLog.error(message);
68          } else if (commonsLog != null) {
69              commonsLog.error(message);
70          }
71      }
72  
73      /**
74       * error.
75       *
76       * @param vfsLog The base component Logger to use.
77       * @param commonsLog The class specific Logger
78       * @param message The message to log.
79       * @param t The exception, if any.
80       */
81      public static void error(final Log vfsLog, final Log commonsLog, final String message, final Throwable t) {
82          if (vfsLog != null) {
83              vfsLog.error(message, t);
84          } else if (commonsLog != null) {
85              commonsLog.error(message, t);
86          }
87      }
88  
89      /**
90       * fatal.
91       *
92       * @param vfsLog The base component Logger to use.
93       * @param commonsLog The class specific Logger
94       * @param message The message to log.
95       */
96      public static void fatal(final Log vfsLog, final Log commonsLog, final String message) {
97          if (vfsLog != null) {
98              vfsLog.fatal(message);
99          } 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 }