Skip to content

Commit

Permalink
fix(log-core):修复日志处理流程错误导致无法正常打印的问题 fix #174
Browse files Browse the repository at this point in the history
  • Loading branch information
SakurajimaMaii committed Dec 3, 2024
1 parent 68dc74f commit ddbe988
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,11 @@ class LogPrinter private constructor(private val mConfiguration: Configuration)
}

override fun install(plugin: LogPrinter, scope: LogCat) {
scope.logPipeline.intercept(LogPipeline.State) {
if (plugin.mLevelMap[subject.level] == false) {
finish()
}
}
scope.logPipeline.intercept(LogPipeline.Output) {
plugin.printLog(subject.build())
proceed()
if (plugin.mLevelMap[subject.level] == true) {
plugin.printLog(subject.build())
proceed()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,13 @@ class LogStorage private constructor(private val mConfiguration: Configuration)
}

override fun install(plugin: LogStorage, scope: LogCat) {
scope.logPipeline.intercept(LogPipeline.State) {
if (plugin.mLevelMap[subject.level] == false) {
finish()
}
}
val store = PipelinePhase("Store")
scope.logPipeline.insertPhaseAfter(LogPipeline.Output, store)
scope.logPipeline.intercept(store) {
plugin.storeLog(subject.build())
proceed()
if (plugin.mLevelMap[subject.level] == true) {
plugin.storeLog(subject.build())
proceed()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@

package com.log.vastgui.desktop

import com.log.vastgui.core.LogFactory
import com.log.vastgui.core.base.LogLevel
import com.log.vastgui.core.base.LogStore
import com.log.vastgui.core.base.Logger
import com.log.vastgui.core.getLogFactory
import com.log.vastgui.core.json.GsonConverter
import com.log.vastgui.core.plugin.LogJson
import com.log.vastgui.core.plugin.LogPrinter
import com.log.vastgui.core.plugin.LogStorage
import com.log.vastgui.core.plugin.LogSwitch
import com.log.vastgui.desktop.format.LineColorfulFormat
import org.junit.Test

// Author: Vast Gui
Expand All @@ -36,4 +47,37 @@ class DesktopKtTest {
logcat.a("This is a log.")
}

/**
* [Issue
* 174](https://github.com/SakurajimaMaii/Android-Vast-Extension/issues/174)
*/
@Test
fun issue174() {
val logFactory: LogFactory = getLogFactory {
install(LogSwitch) {
open = true
}
install(LogPrinter) {
logger = Logger.desktop(LineColorfulFormat)
levelSet = setOf(LogLevel.WARN, LogLevel.INFO)
}
install(LogStorage) {
logStore = LogStore.desktop("", 1024L * 1000)
levelSet = setOf(LogLevel.DEBUG, LogLevel.ASSERT)
}
install(LogJson) {
converter = GsonConverter.getInstance(true)
}
}

val log = logFactory("SimpleTest")
val map = mapOf("name" to "Xiao Ming", "age" to 19)
log.d(map)
val list = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9)
log.i(list)
log.w("This is a log.")
log.e("This is a log.")
log.a("This is a log.")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ val logFactory: LogFactory = getLogFactory {
logStore = LogStore.desktop("", 1024L * 1000)
}
install(LogJson) {
converter = GsonConverter.getInstance(false)
converter = GsonConverter.getInstance(true)
}
}

0 comments on commit ddbe988

Please sign in to comment.