android - 怎么adb logcat 输出到文件,并把文件命名为当前时间?
PHP中文网
PHP中文网 2017-04-17 17:52:42
0
3
919

adb logcat | grep -i "system.err" > test.log

这样可以输出log,可是执行两次这个命名,会把上次的覆盖掉,能不能动态的给“test.log”命名,比如命名为当前时间.log。 如2016-08-17-19-09-50.log

PHP中文网
PHP中文网

认证0级讲师

reply all(3)
Peter_Zhu

adb logcat > "%date:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%-%time:~3,2%- %time:~6,2%.txt"


The output is: 2016-11-09 15-40-16.txt

Note:
After executing the date command in the cmd command line window of Windows, the value of this environment variable is

Then the meaning of each of the following operations is as follows:
%date:~0,4% means that the pointer moves 0 bits to the right from left to right, and then extracts 4 characters starting from the position where the pointer is offset. The result is 2016 (year value)
%date:~5,2% means that the pointer is offset by 5 digits from left to right, and then extracts 2 characters starting from the offset. The result is 11 (the value of the month)
%date:~8,2 % means that the pointer is offset by 8 bits from left to right, and then extracts 2 characters starting from the offset. The result is 09 (the value of the day)

Another example:
%date:~5% means that the pointer is offset by 5 digits from left to right, and then extracts all values ​​
%date:~-5% means that the pointer is offset in the opposite direction, starting from the rightmost end, offset Shift 5 bits, then extract all values ​​to the left from the pointer.

Let’s look at the value of the time variable:

Then the meaning of each of the following operations is as follows:
%time:~0,2% means that the pointer shifts 0 bits to the right from left to right, and then extracts 2 characters starting from the offset position of the pointer, and the result is the hour field value
%time:~3,2% means that the pointer is offset by 3 digits from left to right, and then extracts 2 characters starting from the offset. The result is the minute field value
%time:~6,2% means that the pointer is offset from left to right Offset 6 bits to the right, and then extract 2 characters starting from the offset. The result is the second field value

阿神

> log_$(date "+%b_%d_%Y_%H.%M.%S").log
You can adjust the time format yourself.

洪涛

Just modify the command above

adb logcat > log_$(date +%Y-%m-%d).log
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template