GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Tags · openrewrite/rewrite-logging-frameworks
Tags
v3.62.0Add recipe migrating `org.fissore:slf4j-fluent` to SLF4J 2.x (#342) * Add recipe to migrate Fissore slf4j-fluent to SLF4J 2.x * Flag reused builders and non-Java usages in Slf4jFluentToSlf4j * Cover slf4j-api versions managed outside the module in Slf4jFluentToSlf4jTest * Migrate SLF4J 1.x providers and flag Object-typed arguments in Slf4jFluentToSlf4j * Flag arguments that can hide a Supplier in SLF4J fluent migration * Flag nested suppliers in Fissore lazy logging arguments v3.61.0Add recipe migrating `org.fissore:slf4j-fluent` to SLF4J 2.x (#342) * Add recipe to migrate Fissore slf4j-fluent to SLF4J 2.x * Flag reused builders and non-Java usages in Slf4jFluentToSlf4j * Cover slf4j-api versions managed outside the module in Slf4jFluentToSlf4jTest * Migrate SLF4J 1.x providers and flag Object-typed arguments in Slf4jFluentToSlf4j * Flag arguments that can hide a Supplier in SLF4J fluent migration * Flag nested suppliers in Fissore lazy logging arguments v3.60.0Add recipe migrating `org.fissore:slf4j-fluent` to SLF4J 2.x (#342) * Add recipe to migrate Fissore slf4j-fluent to SLF4J 2.x * Flag reused builders and non-Java usages in Slf4jFluentToSlf4j * Cover slf4j-api versions managed outside the module in Slf4jFluentToSlf4jTest * Migrate SLF4J 1.x providers and flag Object-typed arguments in Slf4jFluentToSlf4j * Flag arguments that can hide a Supplier in SLF4J fluent migration * Flag nested suppliers in Fissore lazy logging arguments v3.59.0Add recipe to pass Log4j parameters and composed messages as lambda s… …uppliers (#330) * Add recipe to pass Log4j parameters as lambda suppliers Log4j 2 evaluates the arguments of `logger.debug(String, Object...)` and the other level methods before it checks whether the level is enabled. The new `ParameterizedLoggingToLambdaSuppliers` rewrites these calls to the `Supplier<?>...` overloads, e.g. `logger.debug("{}", compute())` to `logger.debug("{}", () -> compute())`, so the arguments are only evaluated when the statement is logged. It covers `trace` through `fatal`, `log(Level, ..)` and the `Marker` variants. By default a call is only converted when at least one argument does real work; `convertSimpleArguments` converts calls with only literals, variables, field accesses and simple getters too. `logLevels` limits the recipe to some levels, e.g. `trace, debug`. Calls are kept when there is no matching overload or the lambda would not compile or would change behaviour: a trailing `Throwable`, an explicit `Object[]`, captured locals that are not effectively final, arguments with assignments or increments, and calls that throw checked exceptions. * Keep line breaks in converted log calls and convert variable levels The replaced call kept only the template's formatting, so log statements spread over several lines were joined into one. The arguments of the converted call now keep their original prefixes. Without `logLevels`, `log(level, ..)` with a level that is not a `Level` constant is converted too. No-change tests are grouped in a nested class. * Wrap `Supplier.get()` and keep arguments that are suppliers `supplier.get()` was treated as a simple getter, so a call such as `logger.debug("{}", supplier.get())` was only converted with `convertSimpleArguments`. It now counts as an argument that does real work, for both the Log4j and the `java.util.function` supplier. An argument that is a supplier itself resolves to the `Object` overload and is logged as an object. Wrapping it produced code such as `() -> (Supplier<?>) this::compute` without deferring anything, so these statements are now left unchanged. Tests cover lambdas, method references, supplier variables, supplier arrays, casts and suppliers as the message. * Keep comments and line breaks after converted log arguments A comment after an argument, such as `compute() /* total */`, was dropped, and a closing parenthesis on its own line was pulled up, because the new lambdas replaced the arguments together with the space that follows them. The converted arguments now keep that space. The comment on the trailing `Throwable` check no longer claims that there is no matching overload: Log4j logs a `Throwable` returned by the last supplier with its stack trace as well, so these calls are kept out of caution only. * Pass composed log messages as suppliers A message without parameters that is put together at the call, such as `logger.debug("Hello " + name)`, was left unchanged because there was nothing to wrap. The string is still built before Log4j checks the level, so such a message is now passed as a supplier: `logger.debug(() -> "Hello " + name)`. A trailing `Throwable` stays as it is. Constant messages, including literals joined with `+`, messages that are a plain variable and messages that are not a `String` are left unchanged. The checks for side effects, checked exceptions and captured locals that are not effectively final apply to the message as well. * Skip Kotlin and Groovy sources and narrow composed messages On a Kotlin file the recipe produced invalid code such as `logger.debug("Name {}", { () -> name.trim()})`, because the lambdas come from a Java template. Kotlin and Groovy sources are now skipped, as `ParameterizedLogging` does. A message was treated as composed whenever it was not a literal, variable or field access, so a ternary, a cast or an array access was wrapped in a lambda although nothing is put together. Only concatenations and method calls are converted now. The display name mentions composed messages, and the Javadoc on a private helper is a plain comment. * Use the shared expensive-argument check for Log4j suppliers The Log4j recipe had its own copy of the check for arguments worth deferring, which treated any cast, array access or ternary as expensive, and narrowed composed messages to concatenations and method calls to compensate. It now uses `LogArguments.isExpensive`, so a message or parameter is converted when some part of it does real work, such as `flag ? "a" : compute()`. * Keep side effects and checked exceptions out of deferred log arguments `WrapExpensiveLogStatementsInConditionals` moved an argument that throws a checked exception into a supplier lambda, as in `logger.atInfo().addArgument(() -> load())`, which does not compile. It also deferred arguments such as `String.valueOf(count++)`, so the increment only ran when the level was enabled. A call whose expensive arguments may throw a checked exception is now wrapped in a level check instead of converted to the fluent API, and a call with an assignment or increment in an argument is left unchanged. The checks live in `LogArguments` so the Log4j supplier recipe can share them. * Use the shared lambda checks for Log4j suppliers The side-effect and checked-exception checks now come from `LogArguments`, and whether a lambda can capture the locals an argument reads from `Scope.lambdaCanCapture`, as in `WrapExpensiveLogStatementsInConditionals`. * Drop the option to convert simple arguments A boolean option doubles the combinations to reason about and test. Wrapping arguments that are all cheap only adds a lambda allocation, so a statement is now always left unchanged unless at least one argument does real work. * Only convert Java sources The lambdas come from a Java template, so a `JavaFileChecker` precondition states what the recipe supports directly, rather than ruling out Kotlin and Groovy one by one. * Add Log4j 2.x best practices SLF4J and JBoss Logging have a best practices composite, Log4j 2.x had none. It runs the recipes that support Log4j 2.x, and passes trace and debug arguments that do real work as suppliers. `ParameterizedLogging` runs first, so a concatenated message becomes placeholders and only the arguments that do real work are deferred. * Split the selected levels test into converted and unchanged statements * Separate converted and unchanged statements in the selected levels test Keep a single test, with the statements of the selected levels in one method and those of other levels in another, instead of two tests. * Inline the preconditions of the Log4j supplier recipe * Put the precondition and the visitor of the Log4j supplier recipe on their own lines * Inline single-use type and side-effect helpers in the Log4j supplier recipe --------- Co-authored-by: Tim te Beek <[email protected]> v3.58.0Add `slf4j-api` when migrating Log4j to SLF4J 1.x (#341) `Log4j1ToSlf4j1` and `Log4j2ToSlf4j1` rewrite sources to `org.slf4j.Logger` and `LoggerFactory` but added no dependency on `org.slf4j:slf4j-api`, so a project that did not already declare it stopped compiling. Seen on a multi-module Maven project using Log4j 1. Both recipes now add `slf4j-api` 1.x to each module whose sources use the logging API they migrate. `Log4j1ToSlf4j1` needs its own entry because `onlyIfUsing` sees the sources before the Log4j 1 to Log4j 2 step has run. v3.57.0Add `slf4j-api` when migrating Log4j to SLF4J 1.x (#341) `Log4j1ToSlf4j1` and `Log4j2ToSlf4j1` rewrite sources to `org.slf4j.Logger` and `LoggerFactory` but added no dependency on `org.slf4j:slf4j-api`, so a project that did not already declare it stopped compiling. Seen on a multi-module Maven project using Log4j 1. Both recipes now add `slf4j-api` 1.x to each module whose sources use the logging API they migrate. `Log4j1ToSlf4j1` needs its own entry because `onlyIfUsing` sees the sources before the Log4j 1 to Log4j 2 step has run. v3.56.0Keep the indentation of a logger field whose modifiers ChangeLoggersT… …oPrivate changes (#338) `ChangeLoggersToPrivate` formatted the field whose modifiers it changes with `autoFormat`, which gives the declaration's line the indentation of a file formatted from scratch. In a file indented by hand, or with tabs among spaces, that moves a line the recipe only edited. `maybeAutoFormat` formats the same way, and with openrewrite/rewrite#10089 it keeps the indentation of the line where a declaration it changes stays. Until that is released, the output is unchanged. Found by running the tests of `ChangeLoggersToPrivate` and `Slf4jBestPractices` with one more space at the start of each indented line that opens nothing, the opt-in shifted-input mode of openrewrite/rewrite#10090. With openrewrite/rewrite#10089 the mode flagged 7 of those tests before this change and none after. The tests pass with the published rewrite snapshot and with both of those changes. v3.55.0Only count an `if` that checks the log level as a guard in `WrapExpen… …siveLogStatementsInConditionals` (#333) * Only count an `if` that checks the log level as a guard `WrapExpensiveLogStatementsInConditionals` skipped a log call with an expensive argument whenever the nearest enclosing `if` had a condition without side effects, such as `if (flag)`, because the check for "every side effect is a log level check" holds for an empty list. The same shortcut also covered `flag || logger.isInfoEnabled()`. A call now counts as guarded when any enclosing `if` has a condition that implies the level is enabled: the `isXEnabled()` call itself, either operand of `&&`, or both operands of `||`. Looking at every enclosing `if` and at either operand of `&&` also stops a second check from being added below `if (logger.isInfoEnabled())` when another `if` sits in between, or when the guard is combined with a side-effecting condition. * Do not count the `else` branch of a log level check as guarded A log call in the `else` branch of `if (logger.isInfoEnabled() && flag)` runs when the level is disabled, so the `if` only guards calls in its then-part. v3.54.0Remove unneeded TypeValidation opt-outs (#329) Found with -Dorg.openrewrite.test.failOnUnneededOptOuts=all. - Remove four per-test opt-outs that were not needed (JulToSlf4jTest x3, Slf4jToLog4jTest) and one that is replaced by a quality check (CommonsLoggingToSlf4j1Test). - Narrow Log4j2ToSlf4j1Test to identifiers(false), saying that Lombok's generated log field has no type. - JulToLog4jTest: parserTypedTrees relaxed only to Erasure. - CommonsLoggingToSlf4j1Test: parserTypedTrees(false) with the reason. v3.53.0Remove unneeded TypeValidation opt-outs (#329) Found with -Dorg.openrewrite.test.failOnUnneededOptOuts=all. - Remove four per-test opt-outs that were not needed (JulToSlf4jTest x3, Slf4jToLog4jTest) and one that is replaced by a quality check (CommonsLoggingToSlf4j1Test). - Narrow Log4j2ToSlf4j1Test to identifiers(false), saying that Lombok's generated log field has no type. - JulToLog4jTest: parserTypedTrees relaxed only to Erasure. - CommonsLoggingToSlf4j1Test: parserTypedTrees(false) with the reason. PreviousNext
|
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |