You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by GitBox <gi...@apache.org> on 2022/08/16 09:40:01 UTC
[GitHub] [incubator-kyuubi] cxzl25 opened a new pull request, #3243: Moved trait Logging#initializeLogging to object Logging
cxzl25 opened a new pull request, #3243:
URL: https://github.com/apache/incubator-kyuubi/pull/3243
### _Why are the changes needed?_
If we use scala enumeration, we need to use logging, and an error will be reported in an environment where log4j2 is not packaged.
This PR just moved the `initializeLogging` method of trait Logging to object Logging.
```scala
XX extends Enumeration with Logging
```
```
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetPublicMethods(Class.java:2902)
at java.lang.Class.privateGetPublicMethods(Class.java:2911)
at java.lang.Class.getMethods(Class.java:1615)
at scala.Enumeration.populateNameMap(Enumeration.scala:193)
at scala.Enumeration.$anonfun$nameOf$1(Enumeration.scala:212)
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.Level
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
```
Scala enumeration uses reflection, resulting in class not found in some scenarios.
scala.Enumeration#populateNameMap
https://github.com/scala/scala/blob/685017051a2dacf40ee7d8d2636721c1bf00182b/src/library/scala/Enumeration.scala#L188-L193
### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible
- [ ] Add screenshots for manual tests if appropriate
- [ ] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request
--
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: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] pan3793 commented on pull request #3243: Move trait Logging#initializeLogging to object Logging
Posted by GitBox <gi...@apache.org>.
pan3793 commented on PR #3243:
URL: https://github.com/apache/incubator-kyuubi/pull/3243#issuecomment-1216901578
Thanks, merging to master for 1.6
--
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: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] pan3793 closed pull request #3243: Move trait Logging#initializeLogging to object Logging
Posted by GitBox <gi...@apache.org>.
pan3793 closed pull request #3243: Move trait Logging#initializeLogging to object Logging
URL: https://github.com/apache/incubator-kyuubi/pull/3243
--
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: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] pan3793 commented on a diff in pull request #3243: Moved trait Logging#initializeLogging to object Logging
Posted by GitBox <gi...@apache.org>.
pan3793 commented on code in PR #3243:
URL: https://github.com/apache/incubator-kyuubi/pull/3243#discussion_r946608841
##########
kyuubi-common/src/main/scala/org/apache/kyuubi/Logging.scala:
##########
@@ -88,13 +88,55 @@ trait Logging {
if (!Logging.initialized) {
Logging.initLock.synchronized {
if (!Logging.initialized) {
- initializeLogging(isInterpreter)
+ Logging.initializeLogging(isInterpreter, loggerName, () => logger)
}
}
}
}
+}
+
+object Logging {
+ @volatile private var useDefault = false
+ @volatile private var defaultRootLevel: String = _
+ @volatile private var initialized = false
+ val initLock = new Object()
+
+ private[kyuubi] def isLog4j12: Boolean = {
+ // This distinguishes the log4j 1.2 binding, currently
+ // org.slf4j.impl.Log4jLoggerFactory, from the log4j 2.0 binding, currently
+ // org.apache.logging.slf4j.Log4jLoggerFactory
+ val binderClass = StaticLoggerBinder.getSingleton.getLoggerFactoryClassStr
+ "org.slf4j.impl.Log4jLoggerFactory".equals(binderClass)
+ }
+
+ private[kyuubi] def isLog4j2: Boolean = {
+ // This distinguishes the log4j 1.2 binding, currently
+ // org.slf4j.impl.Log4jLoggerFactory, from the log4j 2.0 binding, currently
+ // org.apache.logging.slf4j.Log4jLoggerFactory
+ val binderClass = StaticLoggerBinder.getSingleton.getLoggerFactoryClassStr
+ "org.apache.logging.slf4j.Log4jLoggerFactory".equals(binderClass)
+ }
+
+ /**
+ * Return true if log4j2 is initialized by default configuration which has one
+ * appender with error level. See `org.apache.logging.log4j.core.config.DefaultConfiguration`.
+ */
+ private def isLog4j2DefaultConfigured(): Boolean = {
+ val rootLogger = LogManager.getRootLogger.asInstanceOf[Log4jLogger]
+ // If Log4j 2 is used but is initialized by default configuration,
+ // load a default properties file
+ // (see org.apache.logging.log4j.core.config.DefaultConfiguration)
+ rootLogger.getAppenders.isEmpty ||
+ (rootLogger.getAppenders.size() == 1 &&
+ rootLogger.getLevel == Level.ERROR &&
+ LogManager.getContext.asInstanceOf[LoggerContext]
+ .getConfiguration.isInstanceOf[DefaultConfiguration])
+ }
- private def initializeLogging(isInterpreter: Boolean): Unit = {
+ private def initializeLogging(
+ isInterpreter: Boolean,
+ loggerName: String,
+ logger: () => Logger): Unit = {
Review Comment:
thuck could be used here to simplify code
```suggestion
logger: => Logger): Unit = {
```
--
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: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] cxzl25 commented on pull request #3243: Moved trait Logging#initializeLogging to object Logging
Posted by GitBox <gi...@apache.org>.
cxzl25 commented on PR #3243:
URL: https://github.com/apache/incubator-kyuubi/pull/3243#issuecomment-1216403833
Related PR : https://github.com/apache/incubator-kyuubi/pull/3216#discussion_r944061488
--
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: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] codecov-commenter commented on pull request #3243: Moved trait Logging#initializeLogging to object Logging
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #3243:
URL: https://github.com/apache/incubator-kyuubi/pull/3243#issuecomment-1216549784
# [Codecov](https://codecov.io/gh/apache/incubator-kyuubi/pull/3243?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#3243](https://codecov.io/gh/apache/incubator-kyuubi/pull/3243?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (fbe84c8) into [master](https://codecov.io/gh/apache/incubator-kyuubi/commit/1466165a1e6b018953e93233f6e450fca963c450?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (1466165) will **decrease** coverage by `0.01%`.
> The diff coverage is `66.66%`.
```diff
@@ Coverage Diff @@
## master #3243 +/- ##
============================================
- Coverage 50.94% 50.93% -0.02%
Complexity 13 13
============================================
Files 469 469
Lines 26123 26123
Branches 3611 3612 +1
============================================
- Hits 13309 13305 -4
- Misses 11546 11547 +1
- Partials 1268 1271 +3
```
| [Impacted Files](https://codecov.io/gh/apache/incubator-kyuubi/pull/3243?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...mon/src/main/scala/org/apache/kyuubi/Logging.scala](https://codecov.io/gh/apache/incubator-kyuubi/pull/3243/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a3l1dWJpLWNvbW1vbi9zcmMvbWFpbi9zY2FsYS9vcmcvYXBhY2hlL2t5dXViaS9Mb2dnaW5nLnNjYWxh) | `43.42% <66.66%> (ø)` | |
| [...rg/apache/kyuubi/ctl/cmd/log/LogBatchCommand.scala](https://codecov.io/gh/apache/incubator-kyuubi/pull/3243/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a3l1dWJpLWN0bC9zcmMvbWFpbi9zY2FsYS9vcmcvYXBhY2hlL2t5dXViaS9jdGwvY21kL2xvZy9Mb2dCYXRjaENvbW1hbmQuc2NhbGE=) | `78.00% <0.00%> (-2.00%)` | :arrow_down: |
| [...ain/scala/org/apache/kyuubi/engine/EngineRef.scala](https://codecov.io/gh/apache/incubator-kyuubi/pull/3243/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a3l1dWJpLXNlcnZlci9zcmMvbWFpbi9zY2FsYS9vcmcvYXBhY2hlL2t5dXViaS9lbmdpbmUvRW5naW5lUmVmLnNjYWxh) | `74.07% <0.00%> (-0.93%)` | :arrow_down: |
| [...he/kyuubi/ha/client/etcd/EtcdDiscoveryClient.scala](https://codecov.io/gh/apache/incubator-kyuubi/pull/3243/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a3l1dWJpLWhhL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUva3l1dWJpL2hhL2NsaWVudC9ldGNkL0V0Y2REaXNjb3ZlcnlDbGllbnQuc2NhbGE=) | `67.50% <0.00%> (-0.63%)` | :arrow_down: |
| [...n/scala/org/apache/kyuubi/engine/ProcBuilder.scala](https://codecov.io/gh/apache/incubator-kyuubi/pull/3243/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a3l1dWJpLXNlcnZlci9zcmMvbWFpbi9zY2FsYS9vcmcvYXBhY2hlL2t5dXViaS9lbmdpbmUvUHJvY0J1aWxkZXIuc2NhbGE=) | `82.60% <0.00%> (-0.63%)` | :arrow_down: |
| [...a/org/apache/kyuubi/service/TFrontendService.scala](https://codecov.io/gh/apache/incubator-kyuubi/pull/3243/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a3l1dWJpLWNvbW1vbi9zcmMvbWFpbi9zY2FsYS9vcmcvYXBhY2hlL2t5dXViaS9zZXJ2aWNlL1RGcm9udGVuZFNlcnZpY2Uuc2NhbGE=) | `91.17% <0.00%> (-0.30%)` | :arrow_down: |
| [...org/apache/kyuubi/operation/ExecuteStatement.scala](https://codecov.io/gh/apache/incubator-kyuubi/pull/3243/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a3l1dWJpLXNlcnZlci9zcmMvbWFpbi9zY2FsYS9vcmcvYXBhY2hlL2t5dXViaS9vcGVyYXRpb24vRXhlY3V0ZVN0YXRlbWVudC5zY2FsYQ==) | `80.51% <0.00%> (ø)` | |
| [...che/kyuubi/server/KyuubiTHttpFrontendService.scala](https://codecov.io/gh/apache/incubator-kyuubi/pull/3243/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a3l1dWJpLXNlcnZlci9zcmMvbWFpbi9zY2FsYS9vcmcvYXBhY2hlL2t5dXViaS9zZXJ2ZXIvS3l1dWJpVEh0dHBGcm9udGVuZFNlcnZpY2Uuc2NhbGE=) | `64.96% <0.00%> (+0.72%)` | :arrow_up: |
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
--
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: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] pan3793 commented on a diff in pull request #3243: Moved trait Logging#initializeLogging to object Logging
Posted by GitBox <gi...@apache.org>.
pan3793 commented on code in PR #3243:
URL: https://github.com/apache/incubator-kyuubi/pull/3243#discussion_r946608841
##########
kyuubi-common/src/main/scala/org/apache/kyuubi/Logging.scala:
##########
@@ -88,13 +88,55 @@ trait Logging {
if (!Logging.initialized) {
Logging.initLock.synchronized {
if (!Logging.initialized) {
- initializeLogging(isInterpreter)
+ Logging.initializeLogging(isInterpreter, loggerName, () => logger)
}
}
}
}
+}
+
+object Logging {
+ @volatile private var useDefault = false
+ @volatile private var defaultRootLevel: String = _
+ @volatile private var initialized = false
+ val initLock = new Object()
+
+ private[kyuubi] def isLog4j12: Boolean = {
+ // This distinguishes the log4j 1.2 binding, currently
+ // org.slf4j.impl.Log4jLoggerFactory, from the log4j 2.0 binding, currently
+ // org.apache.logging.slf4j.Log4jLoggerFactory
+ val binderClass = StaticLoggerBinder.getSingleton.getLoggerFactoryClassStr
+ "org.slf4j.impl.Log4jLoggerFactory".equals(binderClass)
+ }
+
+ private[kyuubi] def isLog4j2: Boolean = {
+ // This distinguishes the log4j 1.2 binding, currently
+ // org.slf4j.impl.Log4jLoggerFactory, from the log4j 2.0 binding, currently
+ // org.apache.logging.slf4j.Log4jLoggerFactory
+ val binderClass = StaticLoggerBinder.getSingleton.getLoggerFactoryClassStr
+ "org.apache.logging.slf4j.Log4jLoggerFactory".equals(binderClass)
+ }
+
+ /**
+ * Return true if log4j2 is initialized by default configuration which has one
+ * appender with error level. See `org.apache.logging.log4j.core.config.DefaultConfiguration`.
+ */
+ private def isLog4j2DefaultConfigured(): Boolean = {
+ val rootLogger = LogManager.getRootLogger.asInstanceOf[Log4jLogger]
+ // If Log4j 2 is used but is initialized by default configuration,
+ // load a default properties file
+ // (see org.apache.logging.log4j.core.config.DefaultConfiguration)
+ rootLogger.getAppenders.isEmpty ||
+ (rootLogger.getAppenders.size() == 1 &&
+ rootLogger.getLevel == Level.ERROR &&
+ LogManager.getContext.asInstanceOf[LoggerContext]
+ .getConfiguration.isInstanceOf[DefaultConfiguration])
+ }
- private def initializeLogging(isInterpreter: Boolean): Unit = {
+ private def initializeLogging(
+ isInterpreter: Boolean,
+ loggerName: String,
+ logger: () => Logger): Unit = {
Review Comment:
thunk could be used here to simplify code
```suggestion
logger: => Logger): Unit = {
```
--
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: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org