This repository was archived by the owner on May 9, 2023. It is now read-only.
forked from git-commit-id/git-commit-id-maven-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMavenLoggerBridge.java
More file actions
239 lines (204 loc) · 5.41 KB
/
MavenLoggerBridge.java
File metadata and controls
239 lines (204 loc) · 5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
* This file is part of git-commit-id-maven-plugin by Konrad 'ktoso' Malawski <konrad.malawski@java.pl>
*
* git-commit-id-maven-plugin is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* git-commit-id-maven-plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with git-commit-id-maven-plugin. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.project13.maven.log;
import org.apache.maven.plugin.Mojo;
import pl.project13.core.log.FormattingTuple;
import pl.project13.core.log.LoggerBridge;
import pl.project13.core.log.MessageFormatter;
/**
* Bridges logging to standard Maven log adhering to verbosity level.
*/
public class MavenLoggerBridge implements LoggerBridge {
private boolean verbose;
private final Mojo mojo;
public MavenLoggerBridge(Mojo mojo, boolean verbose) {
this.mojo = mojo;
this.verbose = verbose;
}
@Override
public void setVerbose(boolean verbose) {
this.verbose = verbose;
}
@Override
public boolean isVerbose() {
return verbose;
}
@Override
public boolean isDebugEnabled() {
return mojo.getLog().isDebugEnabled();
}
@Override
public boolean isInfoEnabled() {
return mojo.getLog().isInfoEnabled();
}
@Override
public boolean isWarnEnabled() {
return mojo.getLog().isWarnEnabled();
}
@Override
public boolean isErrorEnabled() {
return mojo.getLog().isErrorEnabled();
}
@Override
public void debug(String msg) {
if (verbose) {
mojo.getLog().debug(msg);
}
}
@Override
public void debug(String format, Object arg) {
if (verbose) {
debug(MessageFormatter.format(format, arg));
}
}
@Override
public void debug(String format, Object arg1, Object arg2) {
if (verbose) {
debug(MessageFormatter.format(format, arg1, arg2));
}
}
@Override
public void debug(String format, Object... arguments) {
if (verbose) {
debug(MessageFormatter.arrayFormat(format, arguments));
}
}
@Override
public void debug(String msg, Throwable t) {
if (verbose) {
mojo.getLog().debug(msg, t);
}
}
@Override
public void info(String msg) {
if (verbose) {
mojo.getLog().info(msg);
}
}
@Override
public void info(String format, Object arg) {
if (verbose) {
info(MessageFormatter.format(format, arg));
}
}
@Override
public void info(String format, Object arg1, Object arg2) {
if (verbose) {
info(MessageFormatter.format(format, arg1, arg2));
}
}
@Override
public void info(String format, Object... arguments) {
if (verbose) {
info(MessageFormatter.arrayFormat(format, arguments));
}
}
@Override
public void info(String msg, Throwable t) {
if (verbose) {
mojo.getLog().info(msg, t);
}
}
@Override
public void warn(String msg) {
if (verbose) {
mojo.getLog().warn(msg);
}
}
@Override
public void warn(String format, Object arg) {
if (verbose) {
warn(MessageFormatter.format(format, arg));
}
}
@Override
public void warn(String format, Object arg1, Object arg2) {
if (verbose) {
warn(MessageFormatter.format(format, arg1, arg2));
}
}
@Override
public void warn(String format, Object... arguments) {
if (verbose) {
warn(MessageFormatter.arrayFormat(format, arguments));
}
}
@Override
public void warn(String msg, Throwable t) {
if (verbose) {
mojo.getLog().warn(msg, t);
}
}
@Override
public void error(String msg) {
if (verbose) {
mojo.getLog().error(msg);
}
}
@Override
public void error(String format, Object arg) {
if (verbose) {
error(MessageFormatter.format(format, arg));
}
}
@Override
public void error(String format, Object arg1, Object arg2) {
if (verbose) {
error(MessageFormatter.format(format, arg1, arg2));
}
}
@Override
public void error(String format, Object... arguments) {
if (verbose) {
error(MessageFormatter.arrayFormat(format, arguments));
}
}
@Override
public void error(String msg, Throwable t) {
if (verbose) {
mojo.getLog().error(msg, t);
}
}
private void debug(FormattingTuple tuple) {
if (null == tuple.getThrowable()) {
mojo.getLog().debug(tuple.getMessage());
} else {
mojo.getLog().debug(tuple.getMessage(), tuple.getThrowable());
}
}
private void info(FormattingTuple tuple) {
if (null == tuple.getThrowable()) {
mojo.getLog().info(tuple.getMessage());
} else {
mojo.getLog().info(tuple.getMessage(), tuple.getThrowable());
}
}
private void warn(FormattingTuple tuple) {
if (null == tuple.getThrowable()) {
mojo.getLog().warn(tuple.getMessage());
} else {
mojo.getLog().warn(tuple.getMessage(), tuple.getThrowable());
}
}
private void error(FormattingTuple tuple) {
if (null == tuple.getThrowable()) {
mojo.getLog().error(tuple.getMessage());
} else {
mojo.getLog().error(tuple.getMessage(), tuple.getThrowable());
}
}
}