Skip to content

Instantly share code, notes, and snippets.

@ashkrit
Created May 27, 2018 05:36
Show Gist options
  • Select an option

  • Save ashkrit/e3897b7a9630fd33b1db56c8a763f4f7 to your computer and use it in GitHub Desktop.

Select an option

Save ashkrit/e3897b7a9630fd33b1db56c8a763f4f7 to your computer and use it in GitHub Desktop.
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
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment