简体   繁体   中英

How to display n records per line in Logcat in Android Studio?

The following code convert a list to a string and display to Logcat, but all records are displayed in one line. I hope to display top 10 records per line in Logcat in Android Studio 3.0, how can I do ?

Note: Log.e("My", logList.joinToString("<Br/>", limit =10, truncated = "...more...")) doesn't work

 val logList=LogHandler().getListAllLog()
 Log.e("My", logList.joinToString("|", limit =10, truncated = "...more..."))
val strings = ArrayList<String>()
    strings.add("This is line1")
    strings.add("This is line2")
    strings.add("This is line3")
    display(strings)

You should iterator list. Try this:

fun display(strings: List<String>) {
    for (str in strings) {
        Log.e("YourTag", str)
    }
}

you can chop up your List using chunked() method.
eg if you want to log 10 records per line, then just call chunked(10).

 //assuming logList is an array of String. 
 //you can use logList.chunked directly if it is a List.

 val batchSize = 10 //chop up to 10 per batch

 logList.asList().chunked(batchSize)
            .forEach{subList -> Log.d("My", subList.joinToString("|" )) }

You can simply use "\\n" for new line,in logs.

For example:

Log.e(TAG,"Hello \\n World");

which will give output as

Hello World

I hope this helps,thank you. if its not your answer,please ignore this answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM