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.slf4j.event.Level;
22  
23  /**
24   * A proxy which enhances the MavenSimpleLogger with functionality to track whether a logging threshold is hit.
25   * Currently only support WARN and ERROR states, since it's been used for the --fail-on-severity flag.
26   */
27  public class MavenFailOnSeverityLogger extends MavenSimpleLogger {
28      private final DefaultLogLevelRecorder logLevelRecorder;
29  
30      MavenFailOnSeverityLogger(String name, DefaultLogLevelRecorder logLevelRecorder) {
31          super(name);
32          this.logLevelRecorder = logLevelRecorder;
33      }
34  
35      /**
36       * A simple implementation which always logs messages of level WARN
37       * according to the format outlined above.
38       */
39      @Override
40      public void warn(String msg) {
41          super.warn(msg);
42          logLevelRecorder.record(Level.WARN);
43      }
44  
45      /**
46       * Perform single parameter substitution before logging the message of level
47       * WARN according to the format outlined above.
48       */
49      @Override
50      public void warn(String format, Object arg) {
51          super.warn(format, arg);
52          logLevelRecorder.record(Level.WARN);
53      }
54  
55      /**
56       * Perform double parameter substitution before logging the message of level
57       * WARN according to the format outlined above.
58       */
59      @Override
60      public void warn(String format, Object arg1, Object arg2) {
61          super.warn(format, arg1, arg2);
62          logLevelRecorder.record(Level.WARN);
63      }
64  
65      /**
66       * Perform double parameter substitution before logging the message of level
67       * WARN according to the format outlined above.
68       */
69      @Override
70      public void warn(String format, Object... argArray) {
71          super.warn(format, argArray);
72          logLevelRecorder.record(Level.WARN);
73      }
74  
75      /** Log a message of level WARN, including an exception. */
76      @Override
77      public void warn(String msg, Throwable t) {
78          super.warn(msg, t);
79          logLevelRecorder.record(Level.WARN);
80      }
81  
82      /**
83       * A simple implementation which always logs messages of level ERROR
84       * according to the format outlined above.
85       */
86      @Override
87      public void error(String msg) {
88          super.error(msg);
89          logLevelRecorder.record(Level.ERROR);
90      }
91  
92      /**
93       * Perform single parameter substitution before logging the message of level
94       * ERROR according to the format outlined above.
95       */
96      @Override
97      public void error(String format, Object arg) {
98          super.error(format, arg);
99          logLevelRecorder.record(Level.ERROR);
100     }
101 
102     /**
103      * Perform double parameter substitution before logging the message of level
104      * ERROR according to the format outlined above.
105      */
106     @Override
107     public void error(String format, Object arg1, Object arg2) {
108         super.error(format, arg1, arg2);
109         logLevelRecorder.record(Level.ERROR);
110     }
111 
112     /**
113      * Perform double parameter substitution before logging the message of level
114      * ERROR according to the format outlined above.
115      */
116     @Override
117     public void error(String format, Object... argArray) {
118         super.error(format, argArray);
119         logLevelRecorder.record(Level.ERROR);
120     }
121 
122     /** Log a message of level ERROR, including an exception. */
123     @Override
124     public void error(String msg, Throwable t) {
125         super.error(msg, t);
126         logLevelRecorder.record(Level.ERROR);
127     }
128 }