skip to content

Describe the LogLevel enum in Gradle and how its levels are ordered relative to each other.

level: middleimportance: must knowfreq 45%

answer

  1. six values DEBUG..ERROR
  2. LIFECYCLE + QUIET are Gradle-only
  3. threshold order = declaration order
  4. QUIET survives -q
  5. startParameter.logLevel

basics

~10 s

org.gradle.api.logging.LogLevel has six values: DEBUG, INFO, LIFECYCLE, WARN, QUIET, ERROR — from most to least verbose. Each maps to a logger method; the active level decides which messages show.

solid answer

~30 s

`org.gradle.api.logging.LogLevel` is Gradle's six-value enum: `DEBUG`, `INFO`, `LIFECYCLE`, `WARN`, `QUIET`, `ERROR`. They are ordered by *threshold*, not by intuitive severity: `DEBUG` is the most verbose (everything shows) and `ERROR` is the least. Two of these are Gradle-specific additions beyond SLF4J: `LIFECYCLE` (the default visible level for progress messages) and `QUIET` (above LIFECYCLE/WARN — still shown when the user runs with `-q`/`--quiet`, which sets the threshold to QUIET). When you select a level — via `-i`, `-d`, `-q`, or `gradle.startParameter.logLevel` — Gradle shows every message at that level or higher. `logger.log(LogLevel.LIFECYCLE, "...")` is the generic form behind the named methods.

code

kotlin · 8 lines
kotlin
tasks.register("printVersion") {
    doLast {
        // QUIET still prints even when the build is run with -q
        logger.quiet(version.toString())
        // generic form
        logger.log(LogLevel.LIFECYCLE, "Done")
    }
}

go deeper

for a junior

Recall that there are several levels and that errors/warnings/lifecycle are visible by default.

for a middle

Name all six values, the declaration/threshold order, and which two are Gradle-specific.

for a senior

Explain selecting/inspecting the active level via startParameter and isXEnabled guards, and when QUIET is appropriate.

for a principal

Set team conventions for which level carries which kind of output to keep CI logs signal-rich.

## The enum `org.gradle.api.logging.LogLevel` defines, in increasing order of threshold: 1. `DEBUG` 2. `INFO` 3. `LIFECYCLE` 4. `WARN` 5. `QUIET` 6. `ERROR` The enum's declaration order *is* the threshold order. A configured level shows messages at that level **and all levels above it** in this list. So running at `LIFECYCLE` (the default) shows LIFECYCLE, WARN, QUIET, and ERROR but hides INFO and DEBUG. ## Why LIFECYCLE and QUIET exist SLF4J only has TRACE/DEBUG/INFO/WARN/ERROR. Gradle adds two: - **LIFECYCLE** — the default-visible level for normal progress output (task names, high-signal messages). It sits between INFO and WARN, so by default INFO/DEBUG noise is hidden but lifecycle messages appear. - **QUIET** — a level that is still shown even when the user asks for minimal output with `--quiet`/`-q`. `-q` sets the threshold to QUIET, suppressing LIFECYCLE/INFO/DEBUG but still printing QUIET, WARN(? actually WARN is below QUIET so hidden by -q), and ERROR. Use QUIET for output that must appear even in quiet runs (e.g. a version string the user explicitly requested). ## SLF4J mapping When you call the SLF4J methods on a Gradle logger: - `trace` and `debug` -> DEBUG - `info` -> INFO - `warn` -> WARN - `error` -> ERROR The Gradle-only `lifecycle` and `quiet` have no SLF4J equivalent and are reached via the Gradle methods or `logger.log(LogLevel.LIFECYCLE, ...)`. ## Selecting the active level - CLI: `-d/--debug`, `-i/--info`, `-w/--warn`, `-q/--quiet` (no flag = LIFECYCLE). - Programmatically: `gradle.startParameter.logLevel` returns the current `LogLevel`. ```kotlin if (gradle.startParameter.logLevel <= LogLevel.INFO) { logger.info("Verbose run detected") } ``` ## Practical takeaway Pick the level by *who needs to see it*: ERROR/WARN for problems, LIFECYCLE for normal progress, INFO/DEBUG for diagnostics, QUIET only for output that must survive `-q`.

  • If a build runs with no logging flag, which levels are visible?
    The threshold is LIFECYCLE, so LIFECYCLE, QUIET, WARN, and ERROR are visible; INFO and DEBUG are hidden.
  • Why would you choose logger.quiet over logger.lifecycle?
    QUIET output is still shown when the user passes -q/--quiet, whereas LIFECYCLE is suppressed at the QUIET threshold. Use QUIET for output the user explicitly requested.
  • How can a plugin detect at runtime that the build is in info or debug mode?
    Inspect gradle.startParameter.logLevel and compare against LogLevel.INFO/DEBUG, or call logger.isInfoEnabled()/isDebugEnabled().

saying these in an interview costs you the question

  • Listing only the five SLF4J levels and forgetting LIFECYCLE and QUIET.
  • Claiming QUIET is the least verbose — ERROR is; QUIET sits above WARN by threshold.
  • Saying INFO is visible by default.

context