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      // static utility class
28      private VfsLog() {
29      }
30  
31      /**
32       * warning.
33       *
34       * @param vfsLog The base component Logger to use.
35       * @param commonslog The class specific Logger
36       * @param message The message to log.
37       * @param t The exception, if any.
38       */
39      public static void warn(final Log vfsLog, final Log commonslog, final String message, final Throwable t) {
40          if (vfsLog != null) {
41              vfsLog.warn(message, t);
42          } else if (commonslog != null) {
43              commonslog.warn(message, t);
44          }
45      }
46  
47      /**
48       * warning.
49       *
50       * @param vfsLog The base component Logger to use.
51       * @param commonslog The class specific Logger
52       * @param message The message to log.
53       */
54      public static void warn(final Log vfsLog, final Log commonslog, final String message) {
55          if (vfsLog != null) {
56              vfsLog.warn(message);
57          } else if (commonslog != null) {
58              commonslog.warn(message);
59          }
60      }
61  
62      /**
63       * debug.
64       *
65       * @param vfsLog The base component Logger to use.
66       * @param commonslog The class specific Logger
67       * @param message The message to log.
68       */
69      public static void debug(final Log vfsLog, final Log commonslog, final String message) {
70          if (vfsLog != null) {
71              vfsLog.debug(message);
72          } else if (commonslog != null) {
73              commonslog.debug(message);
74          }
75      }
76  
77      /**
78       * debug.
79       *
80       * @param vfsLog The base component Logger to use.
81       * @param commonsLog The class specific Logger
82       * @param message The message to log.
83       * @param t The exception, if any.
84       */
85      public static void debug(final Log vfsLog, final Log commonsLog, final String message, final Throwable t) {
86          if (vfsLog != null) {
87              vfsLog.debug(message, t);
88          } else if (commonsLog != null) {
89              commonsLog.debug(message, t);
90          }
91      }
92  
93      /**
94       * info.
95       *
96       * @param vfsLog The base component Logger to use.
97       * @param commonsLog The class specific Logger
98       * @param message The message to log.
99       * @param t The exception, if any.
100      */
101     public static void info(final Log vfsLog, final Log commonsLog, final String message, final Throwable t) {
102         if (vfsLog != null) {
103             vfsLog.info(message, t);
104         } else if (commonsLog != null) {
105             commonsLog.info(message, t);
106         }
107     }
108 
109     /**
110      * info.
111      *
112      * @param vfsLog The base component Logger to use.
113      * @param commonsLog The class specific Logger
114      * @param message The message to log.
115      */
116     public static void info(final Log vfsLog, final Log commonsLog, final String message) {
117         if (vfsLog != null) {
118             vfsLog.info(message);
119         } else if (commonsLog != null) {
120             commonsLog.info(message);
121         }
122     }
123 
124     /**
125      * error.
126      *
127      * @param vfsLog The base component Logger to use.
128      * @param commonsLog The class specific Logger
129      * @param message The message to log.
130      * @param t The exception, if any.
131      */
132     public static void error(final Log vfsLog, final Log commonsLog, final String message, final Throwable t) {
133         if (vfsLog != null) {
134             vfsLog.error(message, t);
135         } else if (commonsLog != null) {
136             commonsLog.error(message, t);
137         }
138     }
139 
140     /**
141      * error.
142      *
143      * @param vfsLog The base component Logger to use.
144      * @param commonsLog The class specific Logger
145      * @param message The message to log.
146      */
147     public static void error(final Log vfsLog, final Log commonsLog, final String message) {
148         if (vfsLog != null) {
149             vfsLog.error(message);
150         } else if (commonsLog != null) {
151             commonsLog.error(message);
152         }
153     }
154 
155     /**
156      * fatal.
157      *
158      * @param vfsLog The base component Logger to use.
159      * @param commonsLog The class specific Logger
160      * @param message The message to log.
161      * @param t The exception, if any.
162      */
163     public static void fatal(final Log vfsLog, final Log commonsLog, final String message, final Throwable t) {
164         if (vfsLog != null) {
165             vfsLog.fatal(message, t);
166         } else if (commonsLog != null) {
167             commonsLog.fatal(message, t);
168         }
169     }
170 
171     /**
172      * fatal.
173      *
174      * @param vfsLog The base component Logger to use.
175      * @param commonsLog The class specific Logger
176      * @param message The message to log.
177      */
178     public static void fatal(final Log vfsLog, final Log commonsLog, final String message) {
179         if (vfsLog != null) {
180             vfsLog.fatal(message);
181         } else if (commonsLog != null) {
182             commonsLog.fatal(message);
183         }
184     }
185 }