View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.slf4j;
20  
21  import org.apache.maven.logwrapper.LogLevelRecorder;
22  import org.slf4j.event.Level;
23  
24  /**
25   * A proxy which enhances the MavenSimpleLogger with functionality to track whether a logging threshold is hit.
26   * Currently only support WARN and ERROR states, since it's been used for the --fail-on-severity flag.
27   */
28  public class MavenFailOnSeverityLogger extends MavenSimpleLogger {
29      private final LogLevelRecorder logLevelRecorder;
30  
31      MavenFailOnSeverityLogger(String name, LogLevelRecorder logLevelRecorder) {
32          super(name);
33          this.logLevelRecorder = logLevelRecorder;
34      }
35  
36      /**
37       * A simple implementation which always logs messages of level WARN
38       * according to the format outlined above.
39       */
40      @Override
41      public void warn(String msg) {
42          super.warn(msg);
43          logLevelRecorder.record(Level.WARN);
44      }
45  
46      /**
47       * Perform single parameter substitution before logging the message of level
48       * WARN according to the format outlined above.
49       */
50      @Override
51      public void warn(String format, Object arg) {
52          super.warn(format, arg);
53          logLevelRecorder.record(Level.WARN);
54      }
55  
56      /**
57       * Perform double parameter substitution before logging the message of level
58       * WARN according to the format outlined above.
59       */
60      @Override
61      public void warn(String format, Object arg1, Object arg2) {
62          super.warn(format, arg1, arg2);
63          logLevelRecorder.record(Level.WARN);
64      }
65  
66      /**
67       * Perform double parameter substitution before logging the message of level
68       * WARN according to the format outlined above.
69       */
70      @Override
71      public void warn(String format, Object... argArray) {
72          super.warn(format, argArray);
73          logLevelRecorder.record(Level.WARN);
74      }
75  
76      /** Log a message of level WARN, including an exception. */
77      @Override
78      public void warn(String msg, Throwable t) {
79          super.warn(msg, t);
80          logLevelRecorder.record(Level.WARN);
81      }
82  
83      /**
84       * A simple implementation which always logs messages of level ERROR
85       * according to the format outlined above.
86       */
87      @Override
88      public void error(String msg) {
89          super.error(msg);
90          logLevelRecorder.record(Level.ERROR);
91      }
92  
93      /**
94       * Perform single parameter substitution before logging the message of level
95       * ERROR according to the format outlined above.
96       */
97      @Override
98      public void error(String format, Object arg) {
99          super.error(format, arg);
100         logLevelRecorder.record(Level.ERROR);
101     }
102 
103     /**
104      * Perform double parameter substitution before logging the message of level
105      * ERROR according to the format outlined above.
106      */
107     @Override
108     public void error(String format, Object arg1, Object arg2) {
109         super.error(format, arg1, arg2);
110         logLevelRecorder.record(Level.ERROR);
111     }
112 
113     /**
114      * Perform double parameter substitution before logging the message of level
115      * ERROR according to the format outlined above.
116      */
117     @Override
118     public void error(String format, Object... argArray) {
119         super.error(format, argArray);
120         logLevelRecorder.record(Level.ERROR);
121     }
122 
123     /** Log a message of level ERROR, including an exception. */
124     @Override
125     public void error(String msg, Throwable t) {
126         super.error(msg, t);
127         logLevelRecorder.record(Level.ERROR);
128     }
129 }