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