/
log4j.yml
277 lines (276 loc) · 12.3 KB
/
log4j.yml
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#
# Copyright 2021 the original author or authors.
# <p>
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# <p>
# https://www.apache.org/licenses/LICENSE-2.0
# <p>
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.logging.log4j.ParameterizedLogging
displayName: Parameterize Log4j 2.x logging statements
description: Use Log4j 2.x parameterized logging, which can significantly boost performance for messages that
otherwise would be assembled with String concatenation. Particularly impactful when the log level is not enabled, as
no work is done to assemble the message.
tags:
- logging
- log4j
recipeList:
- org.openrewrite.java.logging.ParameterizedLogging:
methodPattern: org.apache.logging.log4j.Logger info(..)
- org.openrewrite.java.logging.ParameterizedLogging:
methodPattern: org.apache.logging.log4j.Logger trace(..)
- org.openrewrite.java.logging.ParameterizedLogging:
methodPattern: org.apache.logging.log4j.Logger debug(..)
- org.openrewrite.java.logging.ParameterizedLogging:
methodPattern: org.apache.logging.log4j.Logger info(..)
- org.openrewrite.java.logging.ParameterizedLogging:
methodPattern: org.apache.logging.log4j.Logger warn(..)
- org.openrewrite.java.logging.ParameterizedLogging:
methodPattern: org.apache.logging.log4j.Logger error(..)
- org.openrewrite.java.logging.ParameterizedLogging:
methodPattern: org.apache.logging.log4j.Logger fatal(..)
## included because in Log4j2, org.apache.log4j.Category is not convinced it becomes org.apache.logging.log4j.Logger todo
- org.openrewrite.java.logging.ParameterizedLogging:
methodPattern: org.apache.logging.log4j.Category info(..)
- org.openrewrite.java.logging.ParameterizedLogging:
methodPattern: org.apache.logging.log4j.Logger trace(..)
- org.openrewrite.java.logging.ParameterizedLogging:
methodPattern: org.apache.logging.log4j.Category debug(..)
- org.openrewrite.java.logging.ParameterizedLogging:
methodPattern: org.apache.logging.log4j.Category info(..)
- org.openrewrite.java.logging.ParameterizedLogging:
methodPattern: org.apache.logging.log4j.Category warn(..)
- org.openrewrite.java.logging.ParameterizedLogging:
methodPattern: org.apache.logging.log4j.Category error(..)
- org.openrewrite.java.logging.ParameterizedLogging:
methodPattern: org.apache.logging.log4j.Category fatal(..)
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.logging.log4j.Log4j1ToLog4j2
displayName: Migrate Log4j 1.x to Log4j 2.x
description: >
Migrates Log4j 1.x to Log4j 2.x.
This remediates the [Log4Shell](https://www.cisa.gov/news-events/cybersecurity-advisories/aa21-356a) vulnerability
by upgrading to latest version of Log4j 2.
tags:
- logging
- log4j
- CVE-2021-44228
- Log4Shell
recipeList:
- org.openrewrite.java.logging.ChangeLombokLogAnnotation:
loggingFramework: Log4J2
- org.openrewrite.java.ChangePackage:
oldPackageName: org.apache.log4j
newPackageName: org.apache.logging.log4j
- org.openrewrite.java.ChangeMethodTargetToStatic:
methodPattern: org.apache.logging.log4j.Logger getLogger(..)
fullyQualifiedTargetTypeName: org.apache.logging.log4j.LogManager
- org.openrewrite.java.ChangeMethodTargetToStatic:
methodPattern: org.apache.logging.log4j.Logger getRootLogger()
fullyQualifiedTargetTypeName: org.apache.logging.log4j.LogManager
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.apache.logging.log4j.Category getEffectiveLevel()
newMethodName: getLevel
- org.openrewrite.java.logging.log4j.ParameterizedLogging
- org.openrewrite.java.dependencies.AddDependency:
groupId: org.apache.logging.log4j
artifactId: log4j-api
version: 2.x
onlyIfUsing: org.apache.log4j.*
- org.openrewrite.java.dependencies.AddDependency:
groupId: org.apache.logging.log4j
artifactId: log4j-core
version: 2.x
onlyIfUsing: org.apache.log4j.*
- org.openrewrite.java.dependencies.RemoveDependency:
groupId: log4j
artifactId: log4j
- org.openrewrite.java.dependencies.RemoveDependency:
groupId: ch.qos.reload4j
artifactId: reload4j
- org.openrewrite.java.dependencies.AddDependency:
groupId: org.apache.logging.log4j
artifactId: log4j-api
version: 2.x
onlyIfUsing: org.apache.logging.log4j.*
- org.openrewrite.java.dependencies.AddDependency:
groupId: org.apache.logging.log4j
artifactId: log4j-core
version: 2.x
onlyIfUsing: org.apache.logging.log4j.*
- org.openrewrite.java.dependencies.ChangeDependency:
oldGroupId: org.slf4j
oldArtifactId: slf4j-log4j12
newGroupId: org.apache.logging.log4j
newArtifactId: log4j-slf4j-impl
newVersion: 2.x
- org.openrewrite.java.dependencies.ChangeDependency:
oldGroupId: org.slf4j
oldArtifactId: slf4j-reload4j
newGroupId: org.apache.logging.log4j
newArtifactId: log4j-slf4j-impl
newVersion: 2.x
- org.openrewrite.java.dependencies.UpgradeDependencyVersion:
groupId: org.apache.logging.log4j
artifactId: '*'
newVersion: 2.x
overrideManagedVersion: true
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.logging.log4j.CommonsLoggingToLog4j
displayName: Migrate JCL to Log4j 2.x API.
description: Transforms code written using Apache Commons Logging to use Log4j 2.x API.
tags:
- logging
- commons-logging
- log4j
recipeList:
- org.openrewrite.java.SimplifyMethodChain:
methodPatternChain:
- org.apache.commons.logging.LogFactory getFactory()
- org.apache.commons.logging.LogFactory getInstance(..)
newMethodName: getLogger
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.apache.commons.logging.LogFactory getLog(..)
newMethodName: getLogger
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.apache.commons.logging.LogFactory
newFullyQualifiedTypeName: org.apache.logging.log4j.LogManager
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.apache.commons.logging.Log
newFullyQualifiedTypeName: org.apache.logging.log4j.Logger
- org.openrewrite.java.logging.ChangeLombokLogAnnotation:
loggingFramework: Log4j2
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.logging.log4j.JulToLog4j
displayName: Migrate JUL to Log4j 2.x API.
description: Transforms code written using `java.util.logging` to use Log4j 2.x API.
tags:
- logging
- java-util-logging
- log4j
recipeList:
- org.openrewrite.java.ChangeMethodTargetToStatic:
methodPattern: java.util.logging.Logger getLogger(..)
fullyQualifiedTargetTypeName: org.apache.logging.log4j.LogManager
# Change method names.
# The levels that do not have an equivalent are rounded up (less specific)
- org.openrewrite.java.ChangeMethodName:
methodPattern: java.util.logging.Logger config(..)
newMethodName: info
- org.openrewrite.java.ChangeMethodName:
methodPattern: java.util.logging.Logger fine(..)
newMethodName: debug
- org.openrewrite.java.ChangeMethodName:
methodPattern: java.util.logging.Logger finer(..)
newMethodName: trace
- org.openrewrite.java.ChangeMethodName:
methodPattern: java.util.logging.Logger finest(..)
newMethodName: trace
- org.openrewrite.java.ChangeMethodName:
methodPattern: java.util.logging.Logger severe(..)
newMethodName: error
- org.openrewrite.java.ChangeMethodName:
methodPattern: java.util.logging.Logger warning(..)
newMethodName: warn
# entering/exiting calls
- org.openrewrite.java.logging.log4j.ConvertJulEntering
- org.openrewrite.java.logging.log4j.ConvertJulExiting
# Change logger type
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: java.util.logging.Logger
newFullyQualifiedTypeName: org.apache.logging.log4j.Logger
- org.openrewrite.java.logging.ChangeLombokLogAnnotation:
loggingFramework: Log4j2
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.logging.log4j.Slf4jToLog4j
displayName: Migrate SLF4J to Log4j 2.x API.
description: Transforms code written using SLF4J to use Log4j 2.x API.
tags:
- logging
- slf4j
- log4j
recipeList:
- org.openrewrite.java.ChangeMethodTargetToStatic:
methodPattern: org.slf4j.LoggerFactory getLogger(..)
fullyQualifiedTargetTypeName: org.apache.logging.log4j.LogManager
# We intentionally don't rewrite `getDetachedMarker` to cause a compilation error.
# A common usage of detached markers is to "extend" SLF4J to accept objects as messages,
# The Log4j API neither supports nor recommends such a usage. A manual rewrite is required:
# https://github.com/apache/logging-log4j2/pull/770#issuecomment-1072954499
- org.openrewrite.java.ChangeMethodTargetToStatic:
methodPattern: org.slf4j.MarkerFactory getMarker(..)
fullyQualifiedTargetTypeName: org.apache.logging.log4j.MarkerManager
# MDC calls
# The target class of this one is an exception
- org.openrewrite.java.ChangeMethodTargetToStatic:
methodPattern: org.slf4j.MDC putCloseable(..)
fullyQualifiedTargetTypeName: org.apache.logging.log4j.CloseableThreadContext
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.apache.logging.log4j.CloseableThreadContext putCloseable(..)
newMethodName: put
- org.openrewrite.java.ChangeMethodTargetToStatic:
methodPattern: org.slf4j.MDC clear(..)
fullyQualifiedTargetTypeName: org.apache.logging.log4j.ThreadContext
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.apache.logging.log4j.ThreadContext clear(..)
newMethodName: clearAll
- org.openrewrite.java.ChangeMethodTargetToStatic:
methodPattern: org.slf4j.MDC put(..)
fullyQualifiedTargetTypeName: org.apache.logging.log4j.ThreadContext
- org.openrewrite.java.ChangeMethodTargetToStatic:
methodPattern: org.slf4j.MDC get(..)
fullyQualifiedTargetTypeName: org.apache.logging.log4j.ThreadContext
- org.openrewrite.java.ChangeMethodTargetToStatic:
methodPattern: org.slf4j.MDC remove(..)
fullyQualifiedTargetTypeName: org.apache.logging.log4j.ThreadContext
# Method name changes:
# - No change required for Logger's methods `debug`, `error`, `info`, `trace`,
# `warn`, `getName`, `at*` and `is*Enabled`.
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.slf4j.spi.LoggingEventBuilder addMarker(..)
newMethodName: withMarker
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.slf4j.spi.LoggingEventBuilder setCause(..)
newMethodName: withThrowable
# Change types
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.slf4j.Logger
newFullyQualifiedTypeName: org.apache.logging.log4j.Logger
# The types are different: SLF4J's is an enum, Log4j's is a class,
# but they are source-compatible.
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.slf4j.event.Level
newFullyQualifiedTypeName: org.apache.logging.log4j.Level
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.slf4j.spi.LoggingEventBuilder
newFullyQualifiedTypeName: org.apache.logging.log4j.LogBuilder
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.slf4j.Marker
newFullyQualifiedTypeName: org.apache.logging.log4j.Marker
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.slf4j.MDC.MDCCloseable
newFullyQualifiedTypeName: org.apache.logging.log4j.CloseableThreadContext.Instance
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.slf4j.MDC
newFullyQualifiedTypeName: org.apache.logging.log4j.CloseableThreadContext
- org.openrewrite.java.dependencies.ChangeDependency:
oldGroupId: org.slf4j
oldArtifactId: slf4j-api
newGroupId: org.apache.logging.log4j
newArtifactId: log4j-api
newVersion: latest.release
- org.openrewrite.java.logging.ChangeLombokLogAnnotation:
loggingFramework: Log4j2