This is an automated email from the ASF dual-hosted git repository.
benjobs pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git
The following commit(s) were added to refs/heads/dev by this push:
new 13e25d2ca [Improve] Logger improvement (#2624)
13e25d2ca is described below
commit 13e25d2ca178ebbde2a3fd8ab0a5f83548b5d0f9
Author: benjobs <[email protected]>
AuthorDate: Fri Apr 14 14:02:49 2023 +0800
[Improve] Logger improvement (#2624)
* [Improve] Logger improvement
Co-authored-by: benjobs <[email protected]>
---
.../org/apache/streampark/common/util/Logger.scala | 32 +++++-----------------
1 file changed, 7 insertions(+), 25 deletions(-)
diff --git
a/streampark-common/src/main/scala/org/apache/streampark/common/util/Logger.scala
b/streampark-common/src/main/scala/org/apache/streampark/common/util/Logger.scala
index a2078c37b..dbfd7b982 100644
---
a/streampark-common/src/main/scala/org/apache/streampark/common/util/Logger.scala
+++
b/streampark-common/src/main/scala/org/apache/streampark/common/util/Logger.scala
@@ -31,8 +31,6 @@ import java.io.{ByteArrayInputStream, File}
import java.net.URL
import java.nio.charset.StandardCharsets
import scala.util.Try
-import scala.util.Success
-import scala.util.Failure
trait Logger {
@@ -44,12 +42,11 @@ trait Logger {
protected def logger: Slf4JLogger = {
if (_logger == null) {
- initializeLogging()
+ _logger = LoggerFactory.getLoggerFactory().getLogger(logName)
}
_logger
}
-
protected def logInfo(msg: => String) {
if (logger.isInfoEnabled) logger.info(s"$prefix $msg")
}
@@ -94,42 +91,27 @@ trait Logger {
logger.isTraceEnabled
}
- protected def initializeLogging(): Unit = {
- if (!Logger.initialized) {
- Logger.initLock.synchronized {
- if (!Logger.initialized) {
- val factory = LoggerFactory.getLoggerFactory()
- _logger = factory.getLogger(logName)
- Logger.initialized = true
- }
- }
- }
- }
-
-}
-
-private object Logger {
- @volatile private var initialized = false
- val initLock = new Object()
}
private[this] object LoggerFactory extends LoggerFactoryBinder {
private lazy val contextSelectorBinder: ContextSelectorStaticBinder = {
val defaultLoggerContext = new LoggerContext
- Try(new ContextInitializer(defaultLoggerContext).autoConfig()) match {
- case Success(s) => s
- case Failure(e) =>
+
+ Try(new ContextInitializer(defaultLoggerContext).autoConfig())
+ .recover[Unit]({ case e =>
val msg = "Failed to auto configure default logger context"
// scalastyle:off println
System.err.println(msg)
// scalastyle:off println
System.err.println("Reported exception:")
e.printStackTrace()
- }
+ })
+
if (!StatusUtil.contextHasStatusListener(defaultLoggerContext)) {
StatusPrinter.printInCaseOfErrorsOrWarnings(defaultLoggerContext)
}
+
val selectorBinder = new ContextSelectorStaticBinder()
selectorBinder.init(defaultLoggerContext, new Object())
selectorBinder