View Javadoc
1   /*
2    * Licensed under the Apache License, Version 2.0 (the "License");
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    *
6    * http://www.apache.org/licenses/LICENSE-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the License for the specific language governing permissions and
12   * limitations under the License.
13   */
14  
15  package org.basepom.mojo.repack;
16  
17  import static com.google.common.base.Preconditions.checkNotNull;
18  import static java.lang.String.format;
19  
20  import org.apache.maven.shared.utils.logging.MessageBuilder;
21  import org.apache.maven.shared.utils.logging.MessageUtils;
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  
25  final class PluginLog {
26  
27      private final Logger logger;
28  
29      PluginLog(final Class<?> clazz) {
30          checkNotNull(clazz, "clazz is null");
31          this.logger = LoggerFactory.getLogger(clazz);
32      }
33  
34      public void debug(final String fmt, final Object... args) {
35          checkNotNull(fmt, "fmt is null");
36          synchronized (logger) {
37              logger.debug(format(fmt, args));
38          }
39      }
40  
41      public void debug(final Throwable t, final String fmt, final Object... args) {
42          checkNotNull(fmt, "fmt is null");
43          checkNotNull(t, "t is null");
44          synchronized (logger) {
45              logger.debug(format(fmt, args), t);
46          }
47      }
48  
49      public void info(final String fmt, final Object... args) {
50          checkNotNull(fmt, "fmt is null");
51          synchronized (logger) {
52              logger.info(format(fmt, args));
53          }
54      }
55  
56      public void info(final Throwable t, final String fmt, final Object... args) {
57          checkNotNull(fmt, "fmt is null");
58          checkNotNull(t, "t is null");
59          synchronized (logger) {
60              logger.info(format(fmt, args), t);
61          }
62      }
63  
64      public void warn(final String fmt, final Object... args) {
65          checkNotNull(fmt, "fmt is null");
66          MessageBuilder mb = MessageUtils.buffer();
67          synchronized (logger) {
68              logger.warn(mb.warning(format(fmt, args)).toString());
69          }
70      }
71  
72      public void warn(final Throwable t, final String fmt, final Object... args) {
73          checkNotNull(fmt, "fmt is null");
74          checkNotNull(t, "t is null");
75          MessageBuilder mb = MessageUtils.buffer();
76          synchronized (logger) {
77              logger.warn(mb.warning(format(fmt, args)).toString(), t);
78          }
79      }
80  
81      public void error(final String fmt, final Object... args) {
82          checkNotNull(fmt, "fmt is null");
83          MessageBuilder mb = MessageUtils.buffer();
84          synchronized (logger) {
85              logger.error(mb.failure(format(fmt, args)).toString());
86          }
87      }
88  
89      public void error(final Throwable t, final String fmt, final Object... args) {
90          checkNotNull(fmt, "fmt is null");
91          checkNotNull(t, "t is null");
92          MessageBuilder mb = MessageUtils.buffer();
93          synchronized (logger) {
94              logger.error(mb.failure(format(fmt, args)).toString(), t);
95          }
96      }
97  
98      public void report(final boolean quiet, final String fmt, final Object... args) {
99          if (quiet) {
100             debug(fmt, args);
101         } else {
102             info(fmt, args);
103         }
104     }
105 }