Skip to content

Commit

Permalink
Viewer:
Browse files Browse the repository at this point in the history
* removed logs from viewer
* added clear button to filter view
* fixed padding of RecyclerView
* moved strings to strings.xml
* show name of currently displayed log file
* added menu to reload file
  • Loading branch information
MFlisar committed Jun 11, 2021
1 parent 9b60754 commit f615137
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class FileLoggingTree(
mBackgroundHandler?.post { doRealLog(priority, logMessage) } ?: doRealLog(priority, logMessage)
}

private val WTF_MARKER = MarkerFactory.getMarker("WTF ")
private val WTF_MARKER = MarkerFactory.getMarker("WTF-")

private fun doRealLog(priority: Int, logMessage: String) {
// slf4j: TRACE < DEBUG < INFO < WARN < ERROR < FATAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ object DefaultDataExtractor : IDataExtractor {
date = fullLogLine.substring(0, ind2).trim()
level = Level.values().find { it.getFileMarker() == levelString }
?: Level.UNKNOWN

log = fullLogLine.substring(ind3).trimStart()

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ internal class LumberjackViewerActivity : AppCompatActivity() {
}
true
}
R.id.menu_reload_file -> {
loadListData()
true
}
R.id.menu_clear_log_files -> {
fileLoggingSetup.clearLogFiles()
loadListData()
Expand Down Expand Up @@ -154,7 +158,8 @@ internal class LumberjackViewerActivity : AppCompatActivity() {
binding.pbLoading.visibility = View.VISIBLE
adapter?.clear()
lifecycleScope.launch(Dispatchers.IO) {
val lines = (selectedFile ?: fileLoggingSetup.getLatestLogFiles())?.readLines() ?: emptyList()
val file = selectedFile ?: fileLoggingSetup.getLatestLogFiles()
val lines = file?.readLines() ?: emptyList()

val allLogs = ArrayList<IDataExtractor.Data>()
var logEntry: String? = null
Expand All @@ -179,6 +184,7 @@ internal class LumberjackViewerActivity : AppCompatActivity() {
logs = allLogs
withContext(Dispatchers.Main) {
binding.pbLoading.visibility = View.GONE
binding.tvFile.text = file?.name
if (adapter == null) {
adapter = LogAdapter(this@LumberjackViewerActivity, logs, "")
binding.rvLogs.adapter = adapter
Expand All @@ -199,6 +205,10 @@ internal class LumberjackViewerActivity : AppCompatActivity() {
updateFilter(false)
}

binding.tilFilter.setEndIconOnClickListener {
binding.etFilter.setText("")
}

val items = mutableListOf("ALL")
items.addAll(Level.values().filter { it.level != -1 }.map { ">= ${it.name}" })
binding.spLevel.adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, items).apply {
Expand Down Expand Up @@ -227,7 +237,7 @@ internal class LumberjackViewerActivity : AppCompatActivity() {
?.let { Level.values()[it - 1] }
val filterIsActive = filter.isNotEmpty() || level != null

L.d { "updateFilter: $init | $filter | $level | $filterIsActive" }
//L.d { "updateFilter: $init | $filter | $level | $filterIsActive" }

if (loading || (init && !filterIsActive)) {
updateInfos()
Expand Down
10 changes: 10 additions & 0 deletions library-viewer/src/main/res/drawable/ic_baseline_refresh_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/>
</vector>
32 changes: 25 additions & 7 deletions library-viewer/src/main/res/layout/activity_lumberjack_viewer.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand Down Expand Up @@ -44,13 +43,14 @@
android:layout_gravity="center_vertical" />

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilFilter"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:hint="Filter"
tools:ignore="HardcodedText">
android:hint="@string/lumberjack_filter"
app:endIconMode="clear_text">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etFilter"
Expand All @@ -62,19 +62,37 @@

</LinearLayout>

<TextView
android:id="@+id/tvInfos"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:padding="5dp" />
android:orientation="horizontal"
android:paddingTop="4dp"
android:paddingBottom="4dp">

<TextView
android:id="@+id/tvFile"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="1"
android:paddingEnd="4dp"
android:paddingRight="4dp" />

<TextView
android:id="@+id/tvInfos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1" />

</LinearLayout>

</com.google.android.material.appbar.AppBarLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvLogs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="8dp"
android:paddingBottom="8dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
Expand Down
18 changes: 11 additions & 7 deletions library-viewer/src/main/res/menu/lumberjack_viewer_menu.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="HardcodedText">
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/menu_scroll_to_bottom"
android:icon="@drawable/ic_baseline_keyboard_arrow_down_24"
android:title="Scroll to bottom"
android:title="@string/lumberjack_menu_scroll_to_bottom"
app:showAsAction="ifRoom" />

<item
android:id="@+id/menu_scroll_to_top"
android:icon="@drawable/ic_baseline_keyboard_arrow_up_24"
android:title="Scroll to top"
android:title="@string/lumberjack_menu_scroll_to_top"
app:showAsAction="ifRoom" />

<item
android:id="@+id/menu_reload_file"
android:icon="@drawable/ic_baseline_refresh_24"
android:title="@string/lumberjack_reload_files"
app:showAsAction="ifRoom" />

<item
android:id="@+id/menu_clear_log_files"
android:title="Clear log file(s)"
android:title="@string/lumberjack_clear_log_files"
app:showAsAction="never" />

<item
android:id="@+id/menu_select_file"
android:title="Select log file"
android:title="@string/lumberjack_select_log_file"
app:showAsAction="never">

<menu></menu>
Expand Down
11 changes: 11 additions & 0 deletions library-viewer/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="lumberjack_filter">Filter</string>
<string name="lumberjack_menu_scroll_to_bottom">Scroll to bottom</string>
<string name="lumberjack_menu_scroll_to_top">Scroll to top</string>
<string name="lumberjack_reload_files">Reload file</string>
<string name="lumberjack_clear_log_files">Clear log file(s)</string>
<string name="lumberjack_select_log_file">Select log file</string>

</resources>
27 changes: 13 additions & 14 deletions library/src/main/java/com/michaelflisar/lumberjack/core/Level.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,29 @@ import android.graphics.Color

enum class Level(
val level: Int,
private val useDefaultTextColor: Boolean,
private val color: Int,
private val prefix: String = ""
) {
private val color: Int? = null,
private val marker: String? = null
) {

TRACE(0, true, -1),
DEBUG(1, true, -1),
INFO(2, true, Color.LTGRAY),
WARN(3, false, Color.parseColor("#FFA500") /* orange */),
ERROR(4, false, Color.RED),
WTF(5, false, Color.RED),
UNKNOWN(-1, false, android.R.color.transparent, "WTF-")
TRACE(0),
DEBUG(1),
INFO(2, Color.BLUE),
WARN(3, Color.parseColor("#FFA500") /* orange */),
ERROR(4, Color.RED),
WTF(5, Color.RED, "WTF-ERROR"),
UNKNOWN(-1, android.R.color.transparent)
;

fun getTitleColor(textColor: Int): Int {
return if (useDefaultTextColor) textColor else color
return color ?: textColor
}

fun getTextColor(textColor: Int): Int {
val c = getTitleColor(textColor)
return if (!useDefaultTextColor && c == android.R.color.transparent)
return if (c == android.R.color.transparent)
textColor
else c
}

fun getFileMarker() = name + prefix
fun getFileMarker() = marker ?: name
}

0 comments on commit f615137

Please sign in to comment.