首页 > 其他分享 >android-code-saveLog

android-code-saveLog

时间:2022-11-08 10:32:20浏览次数:82  
标签:code logcat String saveLog br close new android input


一个工具类。第一个用来将logcat保存到文件,第二个用来获得logcat字符串。


public class Logcat {
public final static String TAG = "VLC/Util/Logcat";

/**
* Writes the current app logcat to a file.
*
* @param filename The filename to save it as
* @throws IOException
*/
public static void writeLogcat(String filename) throws IOException {
String[] args = { "logcat", "-v", "time", "-d" };

Process process = Runtime.getRuntime().exec(args);

InputStreamReader input = new InputStreamReader(process.getInputStream());

FileOutputStream fileStream;
try {
fileStream = new FileOutputStream(filename);
} catch( FileNotFoundException e) {
return;
}

OutputStreamWriter output = new OutputStreamWriter(fileStream);
BufferedReader br = new BufferedReader(input);
BufferedWriter bw = new BufferedWriter(output);

try {
String line;
while ((line = br.readLine()) != null) {
bw.write(line);
bw.newLine();
}
}catch(Exception e) {}
finally {
bw.close();
output.close();
br.close();
input.close();
}
}

/**
* Get the last 500 lines of the application logcat.
*
* @return the log string.
* @throws IOException
*/
public static String getLogcat() throws IOException {
String[] args = { "logcat", "-v", "time", "-d", "-t", "500" };

Process process = Runtime.getRuntime().exec(args);
InputStreamReader input = new InputStreamReader(
process.getInputStream());
BufferedReader br = new BufferedReader(input);
StringBuilder log = new StringBuilder();
String line;

while ((line = br.readLine()) != null)
log.append(line + "\n");

br.close();
input.close();

return log.toString();
}

}



标签:code,logcat,String,saveLog,br,close,new,android,input
From: https://blog.51cto.com/u_13316945/5832019

相关文章

  • android-code-调整音量
    这是不弹出界面的方式:/***@paramvalue*0-15*/publicvoiddealCMDSound(intvalue){AudioManagermAudioManager=(AudioManager)getSy......
  • vscode常用配置的json文件
    {"editor.parameterHints":true,"editor.quickSuggestions":{"other":true,"comments":true,"strings":true},"wind......
  • 小程序开发vscode常用插件
    wechat-snippet微信小程序代码辅助,代码片段自动完成minapp微信小程序标签、属性的智能补全(同时支持原生小程序、mpvue和wepy框架,并提供snippets)wxapp-helper微信......
  • vscode常用配置
    {"editor.quickSuggestions":{"other":true,"comments":true,"strings":true},"editor.fontSize":16,"editor.wordWrap":"off",//永不......
  • leetcode 35. 搜索插入位置 js 实现
    给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。请必须使用时间复杂度为 O(logn) 的算法。......
  • [LeetCode] 1323. Maximum 69 Number
    Youaregivenapositiveinteger num consistingonlyofdigits 6 and 9.Return themaximumnumberyoucangetbychanging atmost onedigit(6 becomes......
  • leetcode 300. 最长递增子序列 js 动态规划实现
    给你一个整数数组nums,找到其中最长严格递增子序列的长度。子序列是由数组派生而来的序列,删除(或不删除)数组中的元素而不改变其余元素的顺序。例如,[3,6,2,7]是数组[0......
  • LeetCode刷题记录.Day8
    两个数组的交集链接349.两个数组的交集-力扣(LeetCode)classSolution{public:vector<int>intersection(vector<int>&nums1,vector<int>&nums2){......
  • 【Leetcode】 剑指offer:栈与队列 --Day01
    写在前面2023届秋招形势严峻,作为2024届本科生倍感压力。时间紧迫,需要加快脚步。计划之一是在未来的36天时间里通关Leetcode的剑指offer系列算法题。这一系列的学习周期为......
  • AtCoder Beginner Contest 276
    A-Rightmost#include<bits/stdc++.h>usingnamespacestd;int32_tmain(){strings;cin>>s;for(inti=s.size();i>=1;i--)i......