Skip to content

Implement SLF4Jm JUL, and Log4J2 providers for Java SDK#68725

Merged
uranusjr merged 21 commits into
apache:mainfrom
astronomer:java-sdk-logging-providers
Jun 22, 2026
Merged

Implement SLF4Jm JUL, and Log4J2 providers for Java SDK#68725
uranusjr merged 21 commits into
apache:mainfrom
astronomer:java-sdk-logging-providers

Conversation

@uranusjr

Copy link
Copy Markdown
Member

Additional mechanism is added Logger in sdk.execution to support sending arbitrary log messages to LogSender. Once that's in place, we can implement various adapters to support common Java logging providers with a bit boilerplate code for each.

Those providers are implemented in separate artifacts since nobody needs all of them at once. The user can choose what they want. Documentation is added to describe how to do it.

I changed examples to prefer the Java Platform Logging interface instead of SLF4J too. This is built-in since Java 9. All the logging tools are more or less the same, so users should adapt pretty easily.

@uranusjr uranusjr mentioned this pull request Jun 18, 2026
1 task
@uranusjr uranusjr added the AIP-108: java-sdk Change this to an 'area:' label after AIP acceptance. label Jun 18, 2026
@uranusjr uranusjr added this to the Java SDK 1.0 milestone Jun 18, 2026
@uranusjr uranusjr force-pushed the java-sdk-logging-providers branch 3 times, most recently from 3ac5294 to d48fe00 Compare June 18, 2026 21:05
@uranusjr

Copy link
Copy Markdown
Member Author

Don’t know if it makes sense… since Airflow uses structlog, and the log forwarder actually works best with structured arguments, trying out intentionally NOT rendering the message but put the arguments in the dict instead

image

Is this too weird?

Comment thread airflow-core/docs/authoring-and-scheduling/language-sdks/java.rst
Comment thread java-sdk/sdk/src/main/kotlin/org/apache/airflow/sdk/execution/Logger.kt Outdated

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall. Thanks for supporting different logging backend for Java-SDK, I have never thought about this part, really nice feature.

Here're some nits caught by claude with the local checked-out branch that make sense to me.

Comment thread airflow-core/docs/authoring-and-scheduling/language-sdks/java.rst Outdated
@jason810496

Copy link
Copy Markdown
Member

Is this too weird?

I prefer the log format of previous version (though the log level was wrong) as it's quite difficult for human to interpret the {0}=val... {1}=val... in the same line for the new version. No sure would it be too difficult to restore the previous format? No strong opinion for this.

Image

@uranusjr uranusjr force-pushed the java-sdk-logging-providers branch from d48fe00 to aa70845 Compare June 22, 2026 08:29
@uranusjr

Copy link
Copy Markdown
Member Author

I switched back to use “normal” rendered messages.

uranusjr added 9 commits June 22, 2026 17:57
A new airflow-sdk-slf4j artifact is added to allow SLF4J to be
seamlessly forwarded to Airflow's task log infrastructure.

Use 'org.apache.airflow:airflow-sdk-slf4j' to enable this.
This allows log4j users to write logs into Airflow directly. Note that
this uses Java since the appender is registered with an annotation, and
the annotation processor can only handle Java. (There's a Kotlin bridge,
but the class is small enough it doesn't make much sense to pull it in.)
uranusjr added 12 commits June 22, 2026 17:57
This is too fancy for the spell checker. Use Dumb English instead.
Systen.log annoyingly pass a null as an array to a vararg method
implemented in Kotlin. This breaks Kotlin since it expects an empty
array instead.

Fortunately, there seems to be a way to work around this, according to
Claude? Let's hope this works.
This implements an incremental NamespaceLevels parser that progressively
split the input raw value, parse each entry, report any errors as it
goes (to the regular Airflow logging channel), and keep parsed entries
with best effort (instead of crashing out entirely).
The previous implementation incorrectly uses the marker's name to
identify the logger. Switch to use the logger's name instead.
This matches the more familiar logging behavior, where the log message
is a template, and the full message rendered with extra arguments.

The JPL implementation has an extra feature. If rendering fails, the
unrendered template is sent as-is with un-renderable arguments attached
in extra metadata keys. This is possible since JPL surfaces the
exception during rendering transparently. Other loggins platforms do not
make the same easy, so we simply use whatever mechanism provided
natively.
@uranusjr uranusjr force-pushed the java-sdk-logging-providers branch from d138bc1 to 20bc567 Compare June 22, 2026 09:58
@uranusjr uranusjr merged commit f24c5b0 into apache:main Jun 22, 2026
86 checks passed
@uranusjr uranusjr deleted the java-sdk-logging-providers branch June 22, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIP-108: java-sdk Change this to an 'area:' label after AIP acceptance. kind:documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants