diff --git a/tool-timber/src/main/kotlin/com/infinum/sentinel/SentinelFileTree.kt b/tool-timber/src/main/kotlin/com/infinum/sentinel/SentinelFileTree.kt index b09cb455..f507eb3f 100644 --- a/tool-timber/src/main/kotlin/com/infinum/sentinel/SentinelFileTree.kt +++ b/tool-timber/src/main/kotlin/com/infinum/sentinel/SentinelFileTree.kt @@ -6,7 +6,8 @@ import com.infinum.sentinel.ui.logger.models.FlowBuffer import com.infinum.sentinel.ui.logger.models.Level import com.infinum.sentinel.ui.shared.LogFileResolver import java.io.File -import java.util.Calendar +import java.text.SimpleDateFormat +import java.util.Locale import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.MainScope import kotlinx.coroutines.launch @@ -21,6 +22,8 @@ internal class SentinelFileTree( private val logFileResolver = LogFileResolver(context) override fun log(priority: Int, tag: String?, message: String, t: Throwable?) { + val dateTimeFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss. SSSZ", Locale.getDefault()) + MainScope().launch { withContext(Dispatchers.IO) { val entry = Entry( @@ -34,7 +37,7 @@ internal class SentinelFileTree( buffer.enqueue(entry) val file: File = logFileResolver.createOrOpenFile() - val line = entry.asLineString() + val line = entry.asLineString(dateTimeFormat) file.appendText(line) } diff --git a/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logger/LoggerAdapter.kt b/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logger/LoggerAdapter.kt index 46d750f1..2ca2cd72 100644 --- a/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logger/LoggerAdapter.kt +++ b/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logger/LoggerAdapter.kt @@ -5,12 +5,16 @@ import android.view.ViewGroup import androidx.recyclerview.widget.ListAdapter import com.infinum.sentinel.SentinelFileTree import com.infinum.sentinel.databinding.SentinelItemLogBinding +import java.text.SimpleDateFormat +import java.util.Locale internal class LoggerAdapter( private val onListChanged: (Boolean) -> Unit, private val onClick: (SentinelFileTree.Entry) -> Unit ) : ListAdapter(LoggerDiffUtil()) { + private val dateTimeFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss. SSSZ", Locale.getDefault()) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LoggerViewHolder = LoggerViewHolder( SentinelItemLogBinding.inflate( @@ -21,7 +25,11 @@ internal class LoggerAdapter( ) override fun onBindViewHolder(holder: LoggerViewHolder, position: Int) { - holder.bind(getItem(position), onClick) + holder.bind( + item = getItem(position), + dateTimeFormat = dateTimeFormat, + onClick = onClick + ) } override fun onViewRecycled(holder: LoggerViewHolder) { diff --git a/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logger/LoggerViewHolder.kt b/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logger/LoggerViewHolder.kt index 5be29921..ce2361e7 100644 --- a/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logger/LoggerViewHolder.kt +++ b/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logger/LoggerViewHolder.kt @@ -14,7 +14,11 @@ internal class LoggerViewHolder( private val binding: SentinelItemLogBinding ) : RecyclerView.ViewHolder(binding.root) { - fun bind(item: SentinelFileTree.Entry?, onClick: (SentinelFileTree.Entry) -> Unit) { + fun bind( + item: SentinelFileTree.Entry?, + dateTimeFormat: SimpleDateFormat, + onClick: (SentinelFileTree.Entry) -> Unit + ) { item?.let { entry -> with(binding) { levelView.setBackgroundColor( @@ -31,7 +35,7 @@ internal class LoggerViewHolder( } ) ) - timestampView.text = SimpleDateFormat.getDateTimeInstance().format(Date(entry.timestamp)) + timestampView.text = dateTimeFormat.format(Date(entry.timestamp)) tagView.text = entry.tag entry.stackTrace?.let { stackTraceView.text = it diff --git a/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logger/models/BaseEntry.kt b/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logger/models/BaseEntry.kt index 7ec2e2bc..9feadbf5 100644 --- a/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logger/models/BaseEntry.kt +++ b/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logger/models/BaseEntry.kt @@ -1,6 +1,7 @@ package com.infinum.sentinel.ui.logger.models -import java.io.File +import java.text.SimpleDateFormat +import java.util.Date import org.json.JSONObject internal open class BaseEntry( @@ -10,7 +11,6 @@ internal open class BaseEntry( open val message: String? = null, open val stackTrace: String? = null ) { - fun asJSONString(): String = JSONObject() .put("level", level) @@ -20,9 +20,9 @@ internal open class BaseEntry( .put("stackTrace", stackTrace) .toString() - fun asLineString(): String = + fun asLineString(dateTimeFormat: SimpleDateFormat): String = buildString { - append(timestamp) + append(dateTimeFormat.format(Date(timestamp))) append(" LEVEL: ") append(level) append(" TAG: ") diff --git a/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logs/LogsAdapter.kt b/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logs/LogsAdapter.kt index 8913309e..d2c03244 100644 --- a/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logs/LogsAdapter.kt +++ b/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logs/LogsAdapter.kt @@ -3,10 +3,10 @@ package com.infinum.sentinel.ui.logs import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.ListAdapter -import com.infinum.sentinel.SentinelFileTree -import com.infinum.sentinel.databinding.SentinelItemLogBinding import com.infinum.sentinel.databinding.SentinelItemLogFileBinding import java.io.File +import java.text.SimpleDateFormat +import java.util.Locale internal class LogsAdapter( private val onListChanged: (Boolean) -> Unit, @@ -14,6 +14,8 @@ internal class LogsAdapter( private val onShare: (File) -> Unit ) : ListAdapter(LogsDiffUtil()) { + private val dateTimeFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss. SSSZ", Locale.getDefault()) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LogsViewHolder = LogsViewHolder( SentinelItemLogFileBinding.inflate( @@ -24,7 +26,12 @@ internal class LogsAdapter( ) override fun onBindViewHolder(holder: LogsViewHolder, position: Int) { - holder.bind(getItem(position), onDelete, onShare) + holder.bind( + item = getItem(position), + dateTimeFormat = dateTimeFormat, + onDelete = onDelete, + onShare = onShare + ) } override fun onViewRecycled(holder: LogsViewHolder) { diff --git a/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logs/LogsViewHolder.kt b/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logs/LogsViewHolder.kt index 61c2d608..da7df108 100644 --- a/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logs/LogsViewHolder.kt +++ b/tool-timber/src/main/kotlin/com/infinum/sentinel/ui/logs/LogsViewHolder.kt @@ -1,12 +1,7 @@ package com.infinum.sentinel.ui.logs -import androidx.core.content.ContextCompat -import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView -import com.infinum.sentinel.R -import com.infinum.sentinel.SentinelFileTree import com.infinum.sentinel.databinding.SentinelItemLogFileBinding -import com.infinum.sentinel.ui.logger.models.Level import java.io.File import java.text.SimpleDateFormat import java.util.Date @@ -15,11 +10,11 @@ internal class LogsViewHolder( private val binding: SentinelItemLogFileBinding ) : RecyclerView.ViewHolder(binding.root) { - fun bind(item: File?, onDelete: (File) -> Unit, onShare: (File) -> Unit) { + fun bind(item: File?, dateTimeFormat: SimpleDateFormat, onDelete: (File) -> Unit, onShare: (File) -> Unit) { item?.let { entry -> with(binding) { messageView.text = entry.name - timestampView.text = SimpleDateFormat.getDateTimeInstance().format(Date(entry.lastModified())) + timestampView.text = dateTimeFormat.format(Date(entry.lastModified())) deleteButton.setOnClickListener { onDelete(entry) } shareButton.setOnClickListener { onShare(entry) } }