Skip to content

Commit

Permalink
[KYUUBI #4653] [KYUUBI 4650][Improvement] LogDivertAppender supports …
Browse files Browse the repository at this point in the history
…reading RollingFileAppender pattern

### _Why are the changes needed?_

close #4650

### _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.readthedocs.io/en/master/develop_tools/testing.html#running-tests) locally before make a pull request

Closes #4653 from lsm1/features/kyuubi_4650.

Closes #4653

79962aa [senmiaoliu] reformat
e4bb732 [senmiaoliu] respect user log pattern

Authored-by: senmiaoliu <senmiaoliu@trip.com>
Signed-off-by: Cheng Pan <chengpan@apache.org>
  • Loading branch information
lsm1 authored and pan3793 committed Apr 4, 2023
1 parent 061545b commit 473907c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Log4j12DivertAppender extends WriterAppender {

final private val lo = Logger.getRootLogger
.getAllAppenders.asScala
.find(_.isInstanceOf[ConsoleAppender])
.find(ap => ap.isInstanceOf[ConsoleAppender] || ap.isInstanceOf[RollingFileAppender])
.map(_.asInstanceOf[Appender].getLayout)
.getOrElse(new PatternLayout("%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import scala.collection.JavaConverters._

import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.core.{Filter, LogEvent, StringLayout}
import org.apache.logging.log4j.core.appender.{AbstractWriterAppender, ConsoleAppender, WriterManager}
import org.apache.logging.log4j.core.appender.{AbstractWriterAppender, ConsoleAppender, RollingFileAppender, WriterManager}
import org.apache.logging.log4j.core.filter.AbstractFilter
import org.apache.logging.log4j.core.layout.PatternLayout

Expand Down Expand Up @@ -91,7 +91,9 @@ object Log4j2DivertAppender {
def initLayout(): StringLayout = {
LogManager.getRootLogger.asInstanceOf[org.apache.logging.log4j.core.Logger]
.getAppenders.values().asScala
.find(ap => ap.isInstanceOf[ConsoleAppender] && ap.getLayout.isInstanceOf[StringLayout])
.find(ap =>
(ap.isInstanceOf[ConsoleAppender] || ap.isInstanceOf[RollingFileAppender]) &&
ap.getLayout.isInstanceOf[StringLayout])
.map(_.getLayout.asInstanceOf[StringLayout])
.getOrElse(PatternLayout.newBuilder().withPattern(
"%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n").build())
Expand Down

0 comments on commit 473907c

Please sign in to comment.