Skip to content

Commit

Permalink
Plugin support
Browse files Browse the repository at this point in the history
  • Loading branch information
amankgo committed Feb 1, 2022
1 parent df7dfa3 commit 68fc0a0
Show file tree
Hide file tree
Showing 158 changed files with 1,475 additions and 774 deletions.
23 changes: 0 additions & 23 deletions .idea/runConfigurations/logvue__run_.xml

This file was deleted.

30 changes: 30 additions & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
val pf4jVersion: String by project


plugins {
kotlin("jvm")
}

dependencies {
implementation(kotlin("stdlib"))
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl
implementation("org.apache.logging.log4j:log4j-slf4j-impl:2.17.0")
implementation("org.apache.logging.log4j:log4j-api:2.17.0")
implementation("org.apache.logging.log4j:log4j-core:2.17.0")

compileOnly("org.pf4j:pf4j:${pf4jVersion}")
// types parser for object to map conversion
implementation("com.github.drapostolos:type-parser:0.7.0")
implementation("com.google.code.gson:gson:2.8.9")
// https://mvnrepository.com/artifact/com.google.guava/guava
api("com.google.guava:guava:31.0.1-jre")
testImplementation(platform("org.junit:junit-bom:5.8.2"))
testImplementation("org.junit.jupiter:junit-jupiter")
}

tasks.test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}
29 changes: 29 additions & 0 deletions api/src/main/kotlin/com/voxfinite/logvue/api/LogEventParser.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.voxfinite.logvue.api

import com.voxfinite.logvue.api.models.LogCatMessage2
import com.voxfinite.logvue.api.models.LogItem
import org.pf4j.ExtensionPoint

/**
* Plugin extension point
* All plugins must extend with interface and annotate with @Extension
*/
interface LogEventParser : ExtensionPoint {

/**
* Filters for tags
*/
fun filters() : List<String>

/**
* Validate and return whether to process this message
*/
fun validate(logCatMessage2: LogCatMessage2) : Boolean

/**
* Parse item which is validated before to [LogItem]
*
*/
fun parse(logCatMessage2: LogCatMessage2) : LogItem

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models
package com.voxfinite.logvue.api.models

sealed interface InternalContent

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package models
package com.voxfinite.logvue.api.models

import java.io.Serializable

sealed class ItemSource(val type: String, val icon: String) : Serializable {
abstract class ItemSource(val type: String, val icon: String) : Serializable {
companion object {
private const val serialVersionUID = 1L
}
}

object SourceFA : ItemSource("Firebase", "icons/firebaseLogo.webp")
object SourceFA : ItemSource("Firebase", "icons/firebaseLogo.webp") // TODO: Move to url
object SourceInternalContent : ItemSource("Content", "")
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package models
package com.voxfinite.logvue.api.models

import com.android.ddmlib.Log.LogLevel
import com.android.ddmlib.logcat.LogCatHeader
import java.time.Instant
import java.time.format.DateTimeFormatter
import java.time.format.DateTimeFormatterBuilder
Expand All @@ -14,15 +12,13 @@ private val EPOCH_TIME_FORMATTER: DateTimeFormatter = DateTimeFormatterBuilder()
.toFormatter(Locale.ROOT)

data class LogCatHeader2(
val logLevel: LogLevel,
val logLevel: LogLevel2,
val pid: Int,
val tid: Int,
val appName: String,
val tag: String,
val timestamp: Instant,
) {
constructor(header: LogCatHeader) : this(
header.logLevel, header.pid, header.tid, header.appName, header.tag, header.timestamp)

override fun toString(): String {
val epoch = EPOCH_TIME_FORMATTER.format(timestamp)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package models
package com.voxfinite.logvue.api.models

import com.android.ddmlib.logcat.LogCatMessage
import java.io.Serializable

data class LogCatMessage2(val header: LogCatHeader2, val message: String) : Serializable {

constructor(log: LogCatMessage) : this(LogCatHeader2(log.header), log.message)

companion object {
private const val serialVersionUID = 1L
}
Expand Down
36 changes: 36 additions & 0 deletions api/src/main/kotlin/com/voxfinite/logvue/api/models/LogItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.voxfinite.logvue.api.models

import com.voxfinite.logvue.api.utils.HashMapEntity
import com.voxfinite.logvue.api.utils.hashMapEntityOf
import java.io.Serializable
import java.util.*

/**
* Base class for holding analytics data
* Every plugin can extend [ItemSource] and add here along with event name and other details.
* Do not add anything to [internalContent]
*/
data class LogItem @JvmOverloads constructor(
val source: ItemSource,
val eventName: String,
val properties: HashMapEntity<String, Any> = hashMapEntityOf(hashMapOf()),
val localTime: Long = System.currentTimeMillis(),
val internalContent: InternalContent? = null,
) : Serializable {
companion object {
private const val serialVersionUID = 1L
}

private val id: String = buildKey()

@Transient
var isSelected: Boolean = false

private fun buildKey() = "${iKey()}_$localTime"
fun key() = id

private fun iKey(): String {
val k = "${source.type}_${eventName}_${properties.hashCode()}"
return k + UUID.randomUUID().toString()
}
}
69 changes: 69 additions & 0 deletions api/src/main/kotlin/com/voxfinite/logvue/api/models/LogLevel2.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.voxfinite.logvue.api.models

/**
* Log Level enum.
*/
enum class LogLevel2(
/**
* Returns the numerical value of the priority.
*/
//$NON-NLS-1$
val priority: Int,
/**
* Returns a non translated string representing the LogLevel.
*/
val stringValue: String,
/**
* Returns the letter identifying the priority of the [LogLevel2].
*/
val priorityLetter: Char
) {
VERBOSE(2, "verbose", 'V'), //$NON-NLS-1$
DEBUG(3, "debug", 'D'), //$NON-NLS-1$
INFO(4, "info", 'I'), //$NON-NLS-1$
WARN(5, "warn", 'W'), //$NON-NLS-1$
ERROR(6, "error", 'E'), //$NON-NLS-1$
ASSERT(7, "assert", 'A');

companion object {
fun getByString(value: String): LogLevel2? {
for (mode in values()) {
if (mode.stringValue == value) {
return mode
}
}
return null
}

/**
* Returns the [LogLevel2] enum matching the specified letter.
*
* @param letter the letter matching a `LogLevel` enum
* @return a `LogLevel` object or `null` if no match were found.
*/
fun getByLetter(letter: Char): LogLevel2? {
for (mode in values()) {
if (mode.priorityLetter == letter) {
return mode
}
}
return null
}

/**
* Returns the [LogLevel2] enum matching the specified letter.
*
*
* The letter is passed as a [String] argument, but only the first character
* is used.
*
* @param letter the letter matching a `LogLevel` enum
* @return a `LogLevel` object or `null` if no match were found.
*/
fun getByLetterString(letter: String): LogLevel2? {
return if (letter.isNotEmpty()) {
getByLetter(letter[0])
} else null
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package com.voxfinite.logvue.api.utils

import java.io.Serializable

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.voxfinite.logvue.api.utils

fun <K, V> hashMapEntityOf(mapToWrap: MutableMap<K, V>): HashMapEntity<K, V> = HashMapEntity(mapToWrap)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.voxfinite.logvue.api.utils.deserializers

import com.voxfinite.logvue.api.utils.deserializers.`object`.ObjectDeserializer
import com.voxfinite.logvue.api.utils.deserializers.json.JsonDeserializer

object EventDeserializers {

fun fromObject(message: String?) = ObjectDeserializer.map(message)
fun fromJson(message: String?) = JsonDeserializer.map(message)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.voxfinite.logvue.api.utils.deserializers.json

import com.google.gson.GsonBuilder
import com.google.gson.JsonParseException
import com.google.gson.JsonSyntaxException
import com.google.gson.ToNumberPolicy
import com.google.gson.reflect.TypeToken
import com.voxfinite.logvue.api.utils.HashMapEntity
import com.voxfinite.logvue.api.utils.hashMapEntityOf

object JsonDeserializer {

private val gson by lazy {
val gsonBuilder = GsonBuilder().setObjectToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE)
gsonBuilder.setPrettyPrinting()
gsonBuilder.create()
}

fun createJsonString(src: Any): String {
return gson.toJson(src)
}

fun map(message: String?): HashMapEntity<String, Any> {
val type = object : TypeToken<HashMap<String, Any>>() {}.type
val map = try {
gson.fromJson<HashMap<String, Any>>(message, type)
} catch (e: JsonParseException) {
hashMapOf()
} catch (e: JsonSyntaxException) {
hashMapOf()
}
return hashMapEntityOf(map)
}

}
Loading

0 comments on commit 68fc0a0

Please sign in to comment.