← All recipes
Moderne licensed

Replace the Logback condition attribute with the condition element

Recipe IDorg.openrewrite.java.logging.logback.ConditionAttributeToConditionElementArtifactorg.openrewrite.recipe:rewrite-logging-frameworks

Logback 1.5.37 removed the Janino based <if condition="..."> attribute that 1.5.20 deprecated, so configuration files still using it fail to select the intended appenders. Replaces the attribute with the <condition class="..."/> element that precedes <if>, using the conditions shipped in ch.qos.logback.core.boolex. Conditions that require custom Java logic are left unchanged and reported in a data table.

Single recipeMSAL

Add to your build

Get a download tokenThis recipe is Moderne licensed, so the token must belong to a Moderne customer. It replaces YOUR_DOWNLOAD_TOKEN below.

~/.gradle/gradle.properties

codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN

build.gradle.kts

plugins {
    id("org.openrewrite.rewrite") version("latest.release")
}

rewrite {
    activeRecipe("org.openrewrite.java.logging.logback.ConditionAttributeToConditionElement")
}

repositories {
    mavenCentral()
    maven {
        url = uri("https://artifacts.codegenomeproject.org/maven")
        credentials {
            username = providers.gradleProperty("codeGenomeUsername").get()
            password = providers.gradleProperty("codeGenomeToken").get()
        }
    }
}

dependencies {
    rewrite("org.openrewrite.recipe:rewrite-logging-frameworks:3.34.0")
}

Then run

./gradlew rewriteRun

Usage

This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.java.logging.logback.ConditionAttributeToConditionElement

If the recipe isn’t available locally, install it with:

mod config recipes jar install org.openrewrite.recipe:rewrite-logging-frameworks:RELEASE

Options

NameTypeDescription
filePatternStringA glob expression that can be used to constrain which directories or source files should be searched. Multiple patterns may be specified, separated by a semicolon ;. If multiple patterns are supplied any of the patterns matching will be interpreted as a match. When not set, **/logback*.xml is used.
e.g. **/logback-spring.xml

Data tables

Structured output this recipe can produce.

  • Unmigrated Janino conditionsJanino conditions that have no equivalent among the conditions shipped with logback-core, and so have to be migrated by hand to a custom `PropertyCondition`.org.openrewrite.java.logging.logback.table.UnmigratedJaninoConditions
  • Source files that had resultsSource files that were modified by the recipe run.org.openrewrite.table.SourcesFileResults
  • Source files that had search resultsSearch results that were found during the recipe run.org.openrewrite.table.SearchResults
  • Source files that errored on a recipeThe details of all errors produced by a recipe run.org.openrewrite.table.SourcesFileErrors
  • Recipe performanceStatistics used in analyzing the performance of recipes.org.openrewrite.table.RecipeRunStats