-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
17 changed files
with
536 additions
and
349 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
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 |
---|---|---|
@@ -1,74 +1,13 @@ | ||
package com.coditory.klog | ||
|
||
import com.coditory.klog.config.LogFilter | ||
|
||
interface LogListener { | ||
fun onLogStarted(event: LogEvent) {} | ||
|
||
fun onLogEnded(event: LogEvent) {} | ||
|
||
fun onStreamStarted( | ||
stream: LogStreamDescriptor, | ||
event: LogEvent, | ||
) { | ||
} | ||
|
||
fun onStreamEnded( | ||
stream: LogStreamDescriptor, | ||
event: LogEvent, | ||
) { | ||
} | ||
|
||
fun onPublishStarted( | ||
publisher: LogPublisherDescriptor, | ||
event: LogEvent, | ||
) { | ||
} | ||
|
||
fun onPublishStarted( | ||
publisher: LogPublisherDescriptor, | ||
events: List<LogEvent>, | ||
) { | ||
} | ||
|
||
fun onPublishDropped( | ||
publisher: LogPublisherDescriptor, | ||
event: LogEvent, | ||
e: Throwable? = null, | ||
) { | ||
} | ||
|
||
fun onPublishDropped( | ||
publisher: LogPublisherDescriptor, | ||
events: List<LogEvent>, | ||
e: Throwable? = null, | ||
) { | ||
} | ||
|
||
fun onPublishEnded( | ||
publisher: LogPublisherDescriptor, | ||
event: LogEvent, | ||
) { | ||
} | ||
fun onLogSkipped(event: LogEvent) {} | ||
|
||
fun onPublishEnded( | ||
publisher: LogPublisherDescriptor, | ||
events: List<LogEvent>, | ||
) { | ||
} | ||
fun onLogEnded(event: LogEvent) {} | ||
|
||
companion object { | ||
internal val NOOP = object : LogListener {} | ||
} | ||
} | ||
|
||
data class LogPublisherDescriptor( | ||
val stream: LogStreamDescriptor, | ||
val publisherIdx: Int, | ||
val publisherType: Class<out Any>, | ||
) | ||
|
||
data class LogStreamDescriptor( | ||
val idx: Int, | ||
val filter: LogFilter, | ||
) |
82 changes: 82 additions & 0 deletions
82
klog/src/main/kotlin/com/coditory/klog/LogPublisherListener.kt
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,82 @@ | ||
package com.coditory.klog | ||
|
||
interface LogPublisherListener { | ||
fun onPublishStarted(event: LogEvent) {} | ||
|
||
fun onPublishStarted(events: List<LogEvent>) {} | ||
|
||
fun onPublishDropped(event: LogEvent, e: Throwable? = null) {} | ||
|
||
fun onPublishDropped(events: List<LogEvent>, e: Throwable? = null) {} | ||
|
||
fun onPublishEnded(event: LogEvent) {} | ||
|
||
fun onPublishEnded(events: List<LogEvent>) {} | ||
|
||
companion object { | ||
internal val NOOP = object : LogPublisherListener {} | ||
} | ||
} | ||
|
||
internal class CompositeLogPublisherListener private constructor( | ||
private val first: LogPublisherListener, | ||
private val second: LogPublisherListener, | ||
) : LogPublisherListener { | ||
override fun onPublishStarted(event: LogEvent) { | ||
first.onPublishStarted(event) | ||
second.onPublishStarted(event) | ||
} | ||
|
||
override fun onPublishStarted(events: List<LogEvent>) { | ||
first.onPublishStarted(events) | ||
second.onPublishStarted(events) | ||
} | ||
|
||
override fun onPublishDropped(event: LogEvent, e: Throwable?) { | ||
first.onPublishDropped(event, e) | ||
second.onPublishDropped(event, e) | ||
} | ||
|
||
override fun onPublishDropped(events: List<LogEvent>, e: Throwable?) { | ||
first.onPublishDropped(events, e) | ||
second.onPublishDropped(events, e) | ||
} | ||
|
||
override fun onPublishEnded(event: LogEvent) { | ||
first.onPublishEnded(event) | ||
second.onPublishEnded(event) | ||
} | ||
|
||
override fun onPublishEnded(events: List<LogEvent>) { | ||
first.onPublishEnded(events) | ||
second.onPublishEnded(events) | ||
} | ||
|
||
companion object { | ||
fun create( | ||
first: LogPublisherListener, | ||
second: LogPublisherListener, | ||
): LogPublisherListener { | ||
if (first == LogPublisherListener.NOOP) return second | ||
if (second == LogPublisherListener.NOOP) return first | ||
return CompositeLogPublisherListener(first, second) | ||
} | ||
|
||
fun create( | ||
first: LogPublisherListener, | ||
second: LogStreamListener, | ||
third: LogListener, | ||
): LogPublisherListener { | ||
val combined = if (second is LogPublisherListener) { | ||
create(first, second as LogPublisherListener) | ||
} else { | ||
first | ||
} | ||
return if (third is LogPublisherListener) { | ||
create(combined, third as LogPublisherListener) | ||
} else { | ||
combined | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.