uranusjr commented on code in PR #68725: URL: https://github.com/apache/airflow/pull/68725#discussion_r3450372295
########## java-sdk/jpl/src/main/kotlin/org/apache/airflow/sdk/jpl/AirflowSystemLoggerFinder.kt: ########## @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ + +package org.apache.airflow.sdk.jpl + +import org.apache.airflow.sdk.execution.Level +import org.apache.airflow.sdk.execution.Log +import java.util.MissingResourceException +import java.util.ResourceBundle +import kotlin.collections.set + +/** + * [System.LoggerFinder] that routes [System.Logger] calls to the Airflow task log store. + * + * Registered via [META-INF/services/java.lang.System$LoggerFinder][System.LoggerFinder]. + * All loggers share a single implementation regardless of the requesting module. + */ +class AirflowSystemLoggerFinder : System.LoggerFinder() { + override fun getLogger( + name: String, + module: Module, + ): System.Logger = AirflowSystemLogger(name) +} + +internal class AirflowSystemLogger( + private val name: String, +) : System.Logger { + override fun getName(): String = name + + override fun isLoggable(level: System.Logger.Level): Boolean = + level != System.Logger.Level.OFF && Log.isEnabledForLevel(level.convert(), name) + + override fun log( + level: System.Logger.Level, + bundle: ResourceBundle?, + msg: String?, + thrown: Throwable, + ) { + if (!isLoggable(level)) return + Log.send(level.convert(), name, bundle.resolve(msg)) { + put("exception", thrown.toString()) Review Comment: > The JDK contract for System.Logger.log(Level, ResourceBundle, String, Throwable) allows thrown == null Fuck Java… -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
