Time displayed in Logcat
Asked Answered
R

6

46

I need to get the Android device timestamp in the format hh:mm:ss:SS. I am able to view the time displayed in the Logcat of Eclipse. Is it the computer's time or is it the Android device's time?

Revoice answered 27/2, 2013 at 14:7 Comment(1)
It's been the Android device's date and time in all the logcat logs I've taken.Icsh
A
9

If you are running your app on Android device then it will print device's time, if on emulator then it will show computer's time.

To be ensure just match the Log's time with device's time and with computer's time you will find your answer..

Alsatian answered 27/2, 2013 at 14:15 Comment(1)
This is no longer the case at least since Android 5.x.Pegpega
A
92

From the docs of logcat you can see that there is an option to specify how the output is formatted (-v).

To get a timestamp, you can use the command

logcat -v time

This will prefix each message with a timestamp.

Allodial answered 27/2, 2013 at 14:16 Comment(1)
it's not a timestampCorselet
C
21

use adb logcat -v threadtime in terminal to take the logs from device, it will include date and time.

if you want to redirect these logs into a text file then use command in terminal.

 adb logcat -v threadtime > folder_path_in_the_computer/filename.txt
Ctn answered 3/2, 2015 at 16:50 Comment(1)
Interesting is this gone now. in 2019 I get: adb logcat -v threadtime adb: usage: unknown command threadtimeCrawfish
A
9

If you are running your app on Android device then it will print device's time, if on emulator then it will show computer's time.

To be ensure just match the Log's time with device's time and with computer's time you will find your answer..

Alsatian answered 27/2, 2013 at 14:15 Comment(1)
This is no longer the case at least since Android 5.x.Pegpega
R
9

Use long, threadtime or time formats with logcat -v <format>

logcat has a number of format options, which can be passed to the -v flag in the command line. You can view all of the formats in the documentation here.

Here are samples of what each option looks like so you can decide which one suits your needs:


brief

Display priority, tag, and PID of the process issuing the message.

D/StatusBar.NetworkController( 1222): refreshNwBoosterIndicator - setNWBoosterIndicators(false)
D/StatusBar.NetworkController( 1222): refreshNwBoosterIndicator - setNWBoosterIndicators(false)

long

Display all metadata fields and separate messages with blank lines.

(I like this the best, but I'm a sucker for whitespace.)

[ 01-27 13:17:07.703  1222: 1222 D/StatusBar.NetworkController ]
refreshNwBoosterIndicator - setNWBoosterIndicators(false)

[ 01-27 13:17:07.703  1222: 1222 D/StatusBar.NetworkController ]
refreshNwBoosterIndicator - setNWBoosterIndicators(false)

process

Display PID only.

D( 1222) refreshNwBoosterIndicator - setNWBoosterIndicators(false)  (StatusBar.NetworkController)
D( 1222) refreshNwBoosterIndicator - setNWBoosterIndicators(false)  (StatusBar.NetworkController)

raw

Display the raw log message with no other metadata fields.

refreshNwBoosterIndicator - setNWBoosterIndicators(false)
refreshNwBoosterIndicator - setNWBoosterIndicators(false)

tag

Display the priority and tag only.

D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)

thread

A legacy format that shows priority, PID, and TID of the thread issuing the message.

D( 1222: 1222) refreshNwBoosterIndicator - setNWBoosterIndicators(false)
D( 1222: 1222) refreshNwBoosterIndicator - setNWBoosterIndicators(false)

threadtime

Display the date, invocation time, priority, tag, PID, and TID of the thread issuing the message.

(The docs say this is the default but not true in my case.)

01-27 13:17:07.703  1222  1222 D StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
01-27 13:17:07.703  1222  1222 D StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)

time

Display the date, invocation time, priority, tag, and PID of the process issuing the message.

01-27 13:17:07.703 D/StatusBar.NetworkController( 1222): refreshNwBoosterIndicator - setNWBoosterIndicators(false)
01-27 13:17:07.703 D/StatusBar.NetworkController( 1222): refreshNwBoosterIndicator - setNWBoosterIndicators(false)

NOTE: If you're using this in your app to programmatically collect your User's device logs to send to your support team or whatever, you need to omit the space between -v and the format, like so:

commandLine.add( "-vlong" )

Not sure why it's like that but hopefully that saves somebody time trying to figure that out.

Roryros answered 27/1, 2018 at 19:16 Comment(1)
Any way of getting the year along with date in "-v time" format? Please help.Abstracted
C
1

Taken from Reading and Writing Logs on the Developer Site:

"time — Display the date, invocation time, priority/tag, and PID of the process issuing the message."

On the emulator it will be your computers time, on a device it will be time of your device...

Cleanser answered 27/2, 2013 at 14:18 Comment(0)
P
0

If you need the device date programmatically:

 SimpleDateFormat s = new SimpleDateFormat("hh:mm:ss");
    String format = s.format(new Date());
Padus answered 27/2, 2013 at 14:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.