Skip to content

Commit

Permalink
feat: add ripper for log &
Browse files Browse the repository at this point in the history
Fix log wrapper not applied
  • Loading branch information
xchacha20-poly1305 committed Sep 18, 2024
1 parent 5e6b9e2 commit f56012b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 46 deletions.
1 change: 0 additions & 1 deletion app/src/main/java/io/nekohasekai/sagernet/ktx/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ fun <T : Any> T.asMap(): MutableMap<String, Any> {

// Get SerializedName annotation or fallback to field name
val serializedName = field.getAnnotation(SerializedName::class.java)?.value ?: field.name
if (serializedName == "type") Logs.d("find type: ${field.get(this)}")

val mappedValue = when (val value = field.get(this)) {
// Listable
Expand Down
29 changes: 15 additions & 14 deletions app/src/main/res/layout/layout_logcat.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ui.ToolsFragment">
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ui.ToolsFragment">

<include
layout="@layout/layout_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
layout="@layout/layout_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/log_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:padding="16dp" />
android:id="@+id/log_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:padding="16dp"
android:paddingTop="8dp" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
29 changes: 15 additions & 14 deletions app/src/main/res/layout/view_log_item.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
style="?attr/materialCardViewElevatedStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:checkable="true"
android:clickable="true"
android:focusable="true">
style="?attr/materialCardViewElevatedStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:checkable="true"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground">

<TextView
android:id="@+id/text"
android:textIsSelectable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingHorizontal="12dp"
android:paddingVertical="14dp" />
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingHorizontal="12dp"
android:paddingVertical="14dp"
android:textIsSelectable="true" />

</com.google.android.material.card.MaterialCardView>
7 changes: 4 additions & 3 deletions libcore/libcore.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package libcore

import (
"log"
"os"
"path/filepath"
"strings"
_ "unsafe"

"github.com/sagernet/sing-box/log"
)

const ProtectPath = "protect_path"
Expand All @@ -18,7 +19,7 @@ func InitCore(process, cachePath, internalAssets, externalAssets string,
maxLogSizeKb int32, logEnable bool,
useOfficialAssets bool,
) {
defer catchPanic("InitCore", func(panicErr error) { log.Println(panicErr) })
defer catchPanic("InitCore", func(panicErr error) { log.Error(panicErr) })
isBgProcess := strings.HasSuffix(process, ":bg")

workDir := filepath.Join(cachePath, "../no_backup")
Expand All @@ -33,7 +34,7 @@ func InitCore(process, cachePath, internalAssets, externalAssets string,

// Set up some component
go func() {
defer catchPanic("InitCore-go", func(panicErr error) { log.Println(panicErr) })
defer catchPanic("InitCore-go", func(panicErr error) { log.Error(panicErr) })
GoDebug(process)

externalAssetsPath = externalAssets
Expand Down
18 changes: 4 additions & 14 deletions libcore/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ func setupLog(maxSize int64, path string, enableLog, notTruncateOnStart bool) (e
DisableTimestamp: true,
DisableLineBreak: true,
},
file,
path,
nil,
io.Discard,
"",
platformLogWrapper,
false,
).Logger())
// setup std log
Expand All @@ -108,17 +108,7 @@ func (w *logWriter) DisableColors() bool {
const LogSplitFlag = "\n\n"

func (w *logWriter) WriteMessage(_ log.Level, message string) {
// Prevent add extra LogSplitFlag
// We are sure that message must longer than 2 bytes.
if message[0] == '\n' {
if message[1] != '\n' {
message = "\n" + message
}
} else {
message = LogSplitFlag + message
}

_, _ = io.WriteString(w.writer, message)
_, _ = io.WriteString(w.writer, LogSplitFlag+message)
}

var _ io.Writer = (*logWriter)(nil)
Expand Down

0 comments on commit f56012b

Please sign in to comment.