-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
63 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<configuration> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- encoders are assigned the type | ||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<appender name="METRICS" class="micro.logback.MetricsLogbackAppender"/> | ||
|
||
<root level="info"> | ||
<appender-ref ref="STDOUT" /> | ||
</root> | ||
|
||
<logger level="info" name="micro" additivity="true"> | ||
<appender-ref ref="METRICS" /> | ||
</logger> | ||
|
||
<logger level="info" name="org.apache.spark.scheduler.DAGScheduler" additivity="true"> | ||
<appender-ref ref="METRICS" /> | ||
</logger> | ||
|
||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package micro.logback | ||
|
||
import java.util.concurrent.ConcurrentHashMap | ||
import java.util.concurrent.atomic.AtomicInteger | ||
import java.util.function.BiFunction | ||
|
||
import ch.qos.logback.classic.spi.ILoggingEvent | ||
import ch.qos.logback.core.UnsynchronizedAppenderBase | ||
|
||
class MetricsLogbackAppender extends UnsynchronizedAppenderBase[ILoggingEvent] { | ||
|
||
override def append(e: ILoggingEvent) = { | ||
//Send this message to elastic search or REST end point | ||
messageCount.compute(Thread.currentThread().getName, mergeValue) | ||
System.out.println(messageCount + " " + e) | ||
} | ||
|
||
val messageCount = new ConcurrentHashMap[String, AtomicInteger]() | ||
val mergeValue = new BiFunction[String, AtomicInteger, AtomicInteger] { | ||
def apply(key: String, currentValue: AtomicInteger) = { | ||
val nextValue = currentValue match { | ||
case null => new AtomicInteger(0) | ||
case _ => currentValue | ||
} | ||
nextValue.incrementAndGet() | ||
nextValue | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters