logcatの出力を微妙に改善
This commit is contained in:
parent
e29422928e
commit
fe4ac33809
|
@ -41,7 +41,7 @@ class ActAbout : AppCompatActivity() {
|
|||
val tv = findViewById<TextView>(R.id.tvVersion)
|
||||
tv.text = getString(R.string.version_is, pInfo.versionName)
|
||||
} catch(ex : PackageManager.NameNotFoundException) {
|
||||
log.trace(ex)
|
||||
log.trace(ex,"getPackageInfo failed.")
|
||||
}
|
||||
|
||||
var b : Button
|
||||
|
@ -102,7 +102,7 @@ class ActAbout : AppCompatActivity() {
|
|||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
startActivity(intent)
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
log.trace(ex,"open_browser failed.")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -549,7 +549,7 @@ class ActAccountSetting
|
|||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
startActivity(intent)
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
log.trace(ex,"open_browser failed.")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -654,7 +654,7 @@ class ActAccountSetting
|
|||
log.e("performAccountRemove: %s", response)
|
||||
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
log.trace(ex,"performAccountRemove failed.")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1201,7 +1201,7 @@ class ActAccountSetting
|
|||
intent.putExtra(Intent.EXTRA_MIME_TYPES, arrayOf("image/*", "video/*"))
|
||||
startActivityForResult(intent, request_code)
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
log.trace(ex,"ACTION_OPEN_DOCUMENT failed.")
|
||||
showToast(this, ex, "ACTION_OPEN_DOCUMENT failed.")
|
||||
}
|
||||
|
||||
|
@ -1223,7 +1223,7 @@ class ActAccountSetting
|
|||
|
||||
startActivityForResult(intent, request_code)
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
log.trace(ex,"opening camera app failed.")
|
||||
showToast(this, ex, "opening camera app failed.")
|
||||
}
|
||||
|
||||
|
@ -1296,7 +1296,7 @@ class ActAccountSetting
|
|||
}
|
||||
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
log.trace(ex,"Resizing image failed.")
|
||||
showToast(this, ex, "Resizing image failed.")
|
||||
}
|
||||
|
||||
|
|
|
@ -171,7 +171,7 @@ class ActAppSetting : AppCompatActivity()
|
|||
try {
|
||||
PollingWorker.scheduleJob(this, PollingWorker.JOB_POLLING)
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
log.trace(ex,"PollingWorker.scheduleJob failed.")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -137,8 +137,7 @@ class PollingWorker private constructor(c : Context) {
|
|||
log.e("getDeviceId: missing device token.")
|
||||
return null
|
||||
} catch(ex : Throwable) {
|
||||
log.e("getDeviceId: could not get device token.")
|
||||
log.trace(ex)
|
||||
log.trace(ex,"getDeviceId: could not get device token.")
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
@ -168,8 +167,7 @@ class PollingWorker private constructor(c : Context) {
|
|||
prefDevice.edit().putString(PrefDevice.KEY_DEVICE_TOKEN, device_token).apply()
|
||||
}
|
||||
} catch(ex : Throwable) {
|
||||
log.e("getInstallId: could not get device token.")
|
||||
log.trace(ex)
|
||||
log.trace(ex,"getInstallId: could not get device token.")
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +200,7 @@ class PollingWorker private constructor(c : Context) {
|
|||
return sv
|
||||
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
log.trace(ex,"prepareInstallId")
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
@ -513,7 +511,7 @@ class PollingWorker private constructor(c : Context) {
|
|||
}
|
||||
|
||||
override fun run() {
|
||||
log.e("worker thread start.")
|
||||
log.d("worker thread start.")
|
||||
job_status.set("worker thread start.")
|
||||
while(! bThreadCancelled.get()) {
|
||||
try {
|
||||
|
@ -550,7 +548,7 @@ class PollingWorker private constructor(c : Context) {
|
|||
|
||||
}
|
||||
job_status.set("worker thread end.")
|
||||
log.e("worker thread end.")
|
||||
log.d("worker thread end.")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -786,8 +784,7 @@ class PollingWorker private constructor(c : Context) {
|
|||
jobService.jobFinished(jobParams, willReschedule)
|
||||
}
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
log.e(ex, "jobFinished failed(1).")
|
||||
log.trace(ex,"jobFinished failed(1).")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -826,7 +823,7 @@ class PollingWorker private constructor(c : Context) {
|
|||
|
||||
fun runTask(job : JobItem, taskId : Int, taskData : JSONObject) {
|
||||
try {
|
||||
log.e("(runTask: taskId=${taskId}")
|
||||
log.d("(runTask: taskId=${taskId}")
|
||||
job_status.set("start task $taskId")
|
||||
|
||||
this.job = job
|
||||
|
@ -977,10 +974,9 @@ class PollingWorker private constructor(c : Context) {
|
|||
if(! job.isJobCancelled) job.bPollingComplete = true
|
||||
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
log.e(ex, "task execution failed.")
|
||||
log.trace(ex,"task execution failed.")
|
||||
} finally {
|
||||
log.e(")runTask: taskId=$taskId")
|
||||
log.d(")runTask: taskId=$taskId")
|
||||
job_status.set("end task $taskId")
|
||||
}
|
||||
}
|
||||
|
@ -1187,7 +1183,7 @@ class PollingWorker private constructor(c : Context) {
|
|||
|
||||
val response = call.execute()
|
||||
|
||||
log.e("unregisterDeviceToken: %s", response)
|
||||
log.d("unregisterDeviceToken: %s", response)
|
||||
|
||||
if(response.isSuccessful) {
|
||||
account.register_key = SavedAccount.REGISTER_KEY_UNREGISTERED
|
||||
|
@ -1293,7 +1289,7 @@ class PollingWorker private constructor(c : Context) {
|
|||
} catch(ignored : Throwable) {
|
||||
}
|
||||
|
||||
log.e("registerDeviceToken: %s (%s)", response, body ?: "")
|
||||
log.d("registerDeviceToken: %s (%s)", response, body ?: "")
|
||||
|
||||
val code = response.code()
|
||||
|
||||
|
|
|
@ -1,219 +1,97 @@
|
|||
package jp.juggler.subwaytooter.util
|
||||
|
||||
import android.content.ContentValues
|
||||
import android.content.res.Resources
|
||||
import android.util.Log
|
||||
|
||||
import java.util.Collections
|
||||
import java.util.IdentityHashMap
|
||||
|
||||
import jp.juggler.subwaytooter.table.LogData
|
||||
|
||||
class LogCategory(private val category : String) {
|
||||
class LogCategory(category : String) {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "SubwayTooter"
|
||||
|
||||
/**
|
||||
* Caption for labeling causative exception stack traces
|
||||
*/
|
||||
private const val CAUSE_CAPTION = "Caused by: "
|
||||
private fun format(fmt : String, args : Array<out Any?>) =
|
||||
if(args.isEmpty()) fmt else String.format(fmt, *args)
|
||||
|
||||
/**
|
||||
* Caption for labeling suppressed exception stack traces
|
||||
*/
|
||||
private const val SUPPRESSED_CAPTION = "Suppressed: "
|
||||
private fun format(res : Resources, string_id : Int, args : Array<out Any?>) =
|
||||
res.getString(string_id, *args)
|
||||
|
||||
private fun Throwable.withCaption(caption : String) =
|
||||
"${caption} :${javaClass.simpleName} ${message}"
|
||||
}
|
||||
|
||||
private val cv = ContentValues()
|
||||
|
||||
// fun addLog(level : Int, message : String) {
|
||||
// synchronized(cv) {
|
||||
// LogData.insert(cv, System.currentTimeMillis(), level, category, message)
|
||||
// }
|
||||
// }
|
||||
private val tag = "$TAG:$category"
|
||||
|
||||
fun e(fmt : String, vararg args : Any?) {
|
||||
val message = if( args.isEmpty() ) fmt else String.format(fmt, *args)
|
||||
synchronized(cv) {
|
||||
LogData.insert(cv, System.currentTimeMillis(), LogData.LEVEL_ERROR, category, message)
|
||||
}
|
||||
Log.e(tag, format(fmt, args))
|
||||
}
|
||||
|
||||
fun w(fmt : String, vararg args : Any?) {
|
||||
val message = if( args.isEmpty() ) fmt else String.format(fmt, *args)
|
||||
synchronized(cv) {
|
||||
LogData.insert(cv, System.currentTimeMillis(), LogData.LEVEL_WARNING, category, message)
|
||||
}
|
||||
Log.w(tag, format(fmt, args))
|
||||
}
|
||||
|
||||
fun i(fmt : String, vararg args : Any?) {
|
||||
val message = if( args.isEmpty() ) fmt else String.format(fmt, *args)
|
||||
synchronized(cv) {
|
||||
LogData.insert(cv, System.currentTimeMillis(), LogData.LEVEL_INFO, category, message)
|
||||
}
|
||||
}
|
||||
|
||||
fun v(fmt : String, vararg args : Any?) {
|
||||
val message = if( args.isEmpty() ) fmt else String.format(fmt, *args)
|
||||
synchronized(cv) {
|
||||
LogData.insert(cv, System.currentTimeMillis(), LogData.LEVEL_VERBOSE, category, message)
|
||||
}
|
||||
Log.i(tag, format(fmt, args))
|
||||
}
|
||||
|
||||
fun d(fmt : String, vararg args : Any?) {
|
||||
val message = if( args.isEmpty() ) fmt else String.format(fmt, *args)
|
||||
synchronized(cv) {
|
||||
LogData.insert(cv, System.currentTimeMillis(), LogData.LEVEL_DEBUG, category, message)
|
||||
}
|
||||
Log.d(tag, format(fmt, args))
|
||||
}
|
||||
|
||||
fun h(fmt : String, vararg args : Any?) {
|
||||
val message = if( args.isEmpty() ) fmt else String.format(fmt, *args)
|
||||
synchronized(cv) {
|
||||
LogData.insert(cv, System.currentTimeMillis(), LogData.LEVEL_HEARTBEAT, category, message)
|
||||
}
|
||||
fun v(fmt : String, vararg args : Any?) {
|
||||
Log.v(tag, format(fmt, args))
|
||||
}
|
||||
|
||||
fun f(fmt : String, vararg args : Any?) {
|
||||
val message = if( args.isEmpty() ) fmt else String.format(fmt, *args)
|
||||
synchronized(cv) {
|
||||
LogData.insert(cv, System.currentTimeMillis(), LogData.LEVEL_FLOOD, category, message)
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
// getString()
|
||||
|
||||
fun e(res : Resources, string_id : Int, vararg args : Any?) {
|
||||
val fmt = res.getString(string_id, *args)
|
||||
synchronized(cv) {
|
||||
LogData.insert(cv, System.currentTimeMillis(), LogData.LEVEL_ERROR, category, fmt)
|
||||
}
|
||||
Log.e(tag, format(res, string_id, args))
|
||||
}
|
||||
|
||||
fun w(res : Resources, string_id : Int, vararg args : Any?) {
|
||||
val fmt = res.getString(string_id, *args)
|
||||
synchronized(cv) {
|
||||
LogData.insert(cv, System.currentTimeMillis(), LogData.LEVEL_WARNING, category, fmt)
|
||||
}
|
||||
Log.w(tag, format(res, string_id, args))
|
||||
}
|
||||
|
||||
fun i(res : Resources, string_id : Int, vararg args : Any?) {
|
||||
val fmt = res.getString(string_id, *args)
|
||||
synchronized(cv) {
|
||||
LogData.insert(cv, System.currentTimeMillis(), LogData.LEVEL_INFO, category, fmt)
|
||||
}
|
||||
}
|
||||
|
||||
fun v(res : Resources, string_id : Int, vararg args : Any?) {
|
||||
val fmt = res.getString(string_id, *args)
|
||||
synchronized(cv) {
|
||||
LogData.insert(cv, System.currentTimeMillis(), LogData.LEVEL_VERBOSE, category, fmt)
|
||||
}
|
||||
Log.i(tag, format(res, string_id, args))
|
||||
}
|
||||
|
||||
fun d(res : Resources, string_id : Int, vararg args : Any?) {
|
||||
val fmt = res.getString(string_id, *args)
|
||||
synchronized(cv) {
|
||||
LogData.insert(cv, System.currentTimeMillis(), LogData.LEVEL_DEBUG, category, fmt)
|
||||
}
|
||||
Log.d(tag, format(res, string_id, args))
|
||||
}
|
||||
|
||||
fun h(res : Resources, string_id : Int, vararg args : Any?) {
|
||||
val fmt = res.getString(string_id, *args)
|
||||
synchronized(cv) {
|
||||
LogData.insert(cv, System.currentTimeMillis(), LogData.LEVEL_HEARTBEAT, category, fmt)
|
||||
}
|
||||
fun v(res : Resources, string_id : Int, vararg args : Any?) {
|
||||
Log.v(tag, format(res, string_id, args))
|
||||
}
|
||||
|
||||
fun f(res : Resources, string_id : Int, vararg args : Any?) {
|
||||
val fmt = res.getString(string_id, *args)
|
||||
synchronized(cv) {
|
||||
LogData.insert(cv, System.currentTimeMillis(), LogData.LEVEL_FLOOD, category, fmt)
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
// exception
|
||||
|
||||
|
||||
fun e(ex : Throwable, fmt : String, vararg args : Any?) {
|
||||
val message = if( args.isEmpty() ) fmt else String.format(fmt, *args)
|
||||
synchronized(cv) {
|
||||
LogData.insert(cv, System.currentTimeMillis(), LogData.LEVEL_ERROR, category, message + String.format(":%s %s", ex.javaClass.simpleName, ex.message))
|
||||
}
|
||||
Log.e(tag, ex.withCaption(format(fmt, args)))
|
||||
}
|
||||
|
||||
fun e(ex : Throwable, res : Resources, string_id : Int, vararg args : Any?) {
|
||||
val message = res.getString(string_id, *args)
|
||||
synchronized(cv) {
|
||||
LogData.insert(cv, System.currentTimeMillis(), LogData.LEVEL_ERROR, category, message + String.format(":%s %s", ex.javaClass.simpleName, ex.message))
|
||||
}
|
||||
fun w(ex : Throwable, fmt : String, vararg args : Any?) {
|
||||
Log.w(tag, ex.withCaption(format(fmt, args)))
|
||||
}
|
||||
|
||||
fun i(ex : Throwable, fmt : String, vararg args : Any?) {
|
||||
Log.i(tag, ex.withCaption(format(fmt, args)))
|
||||
}
|
||||
|
||||
fun d(ex : Throwable, fmt : String, vararg args : Any?) {
|
||||
Log.d(tag, ex.withCaption(format(fmt, args)))
|
||||
}
|
||||
|
||||
fun v(ex : Throwable, fmt : String, vararg args : Any?) {
|
||||
Log.v(tag, ex.withCaption(format(fmt, args)))
|
||||
}
|
||||
////////////////////////
|
||||
// stack trace
|
||||
|
||||
fun trace(ex : Throwable, fmt : String, vararg args : Any?) {
|
||||
Log.e(tag, format(fmt, args), ex)
|
||||
}
|
||||
|
||||
fun trace(ex : Throwable) {
|
||||
//// ex.printStackTrace();
|
||||
|
||||
// Guard against malicious overrides of Throwable.equals by
|
||||
// using a Set with identity equality semantics.
|
||||
val dejaVu = Collections.newSetFromMap(IdentityHashMap<Throwable, Boolean>())
|
||||
dejaVu.add(ex)
|
||||
|
||||
// Print our stack trace
|
||||
e(ex.toString())
|
||||
|
||||
val trace = ex.stackTrace
|
||||
for(traceElement in trace) {
|
||||
e("\tat " + traceElement)
|
||||
}
|
||||
|
||||
// Print suppressed exceptions, if any
|
||||
for(se in ex.suppressed)
|
||||
printEnclosedStackTrace(se, trace, SUPPRESSED_CAPTION, "\t", dejaVu)
|
||||
|
||||
// Print cause, if any
|
||||
val ourCause = ex.cause
|
||||
if(ourCause != null)
|
||||
printEnclosedStackTrace(ourCause, trace, CAUSE_CAPTION, "", dejaVu)
|
||||
Log.e(tag, "exception.", ex)
|
||||
}
|
||||
|
||||
/**
|
||||
* Print our stack trace as an enclosed exception for the specified
|
||||
* stack trace.
|
||||
*/
|
||||
private fun printEnclosedStackTrace(
|
||||
ex : Throwable, enclosingTrace : Array<StackTraceElement>, caption : String, prefix : String, dejaVu : MutableSet<Throwable>
|
||||
) {
|
||||
if(dejaVu.contains(ex)) {
|
||||
e("\t[CIRCULAR REFERENCE:$ex]")
|
||||
} else {
|
||||
dejaVu.add(ex)
|
||||
// Compute number of frames in common between this and enclosing trace
|
||||
val trace = ex.stackTrace
|
||||
var m = trace.size - 1
|
||||
var n = enclosingTrace.size - 1
|
||||
while(m >= 0 && n >= 0 && trace[m] == enclosingTrace[n]) {
|
||||
m --
|
||||
n --
|
||||
}
|
||||
val framesInCommon = trace.size - 1 - m
|
||||
|
||||
// Print our stack trace
|
||||
e(prefix + caption + ex)
|
||||
for(i in 0 .. m)
|
||||
e(prefix + "\tat " + trace[i])
|
||||
if(framesInCommon != 0)
|
||||
e("$prefix\t... $framesInCommon more")
|
||||
|
||||
// Print suppressed exceptions, if any
|
||||
for(ex2 in ex.suppressed)
|
||||
printEnclosedStackTrace(ex2, trace, SUPPRESSED_CAPTION, prefix + "\t", dejaVu)
|
||||
|
||||
// Print cause, if any
|
||||
val ourCause = ex.cause
|
||||
if(ourCause != null)
|
||||
printEnclosedStackTrace(ourCause, trace, CAUSE_CAPTION, prefix, dejaVu)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@ import org.json.JSONArray
|
|||
import org.json.JSONObject
|
||||
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.FileNotFoundException
|
||||
import java.util.LinkedList
|
||||
|
||||
class TaskList {
|
||||
|
@ -38,9 +39,10 @@ class TaskList {
|
|||
}
|
||||
|
||||
}
|
||||
} catch(ex : FileNotFoundException) {
|
||||
log.e(ex, "prepareList: file not found.")
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
log.e(ex, "TaskList: prepareArray failed.")
|
||||
log.trace(ex,"TaskList: prepareArray failed.")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue