Created
May 27, 2018 05:36
-
-
Save ashkrit/e3897b7a9630fd33b1db56c8a763f4f7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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