renrenSDK中有个获取系统Log的方法 将来可能用的到吧

/*** $id$*/
package com.renren.api.connect.android.demo;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;/*** Read the logcat log* * @author Shaofeng Wang (shaofeng.wang@renren-inc.com)*/
public final class LogHelper {private static final String LOG_TAG_REQUEST = "Renren-SDK-Request";private static final String LOG_TAG_RESPONSE = "Renren-SDK-Response";/*** Get the log using the specified filter * * @param tag * @return*/public synchronized String getLog() { StringBuffer logger = new StringBuffer();try {Process process = Runtime.getRuntime().exec("logcat -v time + "+ LOG_TAG_REQUEST + ":I " + LOG_TAG_RESPONSE + ":I *:S");BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()), 1024);Thread thread = new Thread(new LogFinalizer(process));thread.start();String line = bufferedReader.readLine();while (line != null && line.length() != 0) {logger.append(parseLog(line));line = bufferedReader.readLine();}if(bufferedReader != null) {bufferedReader.close();}} catch (IOException e) {e.printStackTrace();}return logger.toString();}/*** clear the log*/public synchronized void clear() {try {Runtime.getRuntime().exec("logcat -c + "+ LOG_TAG_REQUEST + ":I " + LOG_TAG_RESPONSE + ":I *:S");} catch (IOException e) {}}/*** 解析log为显示格式* @param log* @return*/private static String parseLog(String logStr) {StringBuffer sb = new StringBuffer();String requestTag = "I/" + LOG_TAG_REQUEST;String responseTag = "I/" + LOG_TAG_RESPONSE;if(logStr.contains(requestTag)) { //请求log 格式形如:08-23 03:05:43.112 I/Renren-SDK-Request(  775): //method=users.getInfo&Bundle[{v=1.0, uids=3××××××, …… StringBuffer log = new StringBuffer(logStr);int tagIndex = log.indexOf(requestTag);//添加时间sb.append(log.substring(0, tagIndex)).append("\r\n");int methodIndex = log.indexOf("method");int methodEnd = log.indexOf("&");//添加method项sb.append(log.substring(methodIndex, methodEnd)).append("\r\n").append("request:\r\n");String bundleStr = "Bundle[{";int paramIndex = log.indexOf(bundleStr, 0) + bundleStr.length();//获取参数序列(不包括"[{"以及"}]")String paramStr = log.substring(paramIndex, log.length() - 2);//添加参数 key=value 对String[] params = paramStr.split(",");sb.append("{\r\n");if(params != null) {for(String str : params) {sb.append("\t").append(str.trim()).append(";\r\n");}}sb.append("}\r\n\r\n");} else if(logStr.contains(responseTag)){ //响应log 格式形如:03:05:51.452 I/Renren-SDK-Response(  775): // method=status.set&{"result":1}…… StringBuffer log = new StringBuffer(logStr);int tagIndex = log.indexOf(responseTag);//添加时间sb.append(log.substring(0, tagIndex)).append("\r\n");int methodIndex = log.indexOf("method");int methodEnd = log.indexOf("&");//添加method项sb.append(log.substring(methodIndex, methodEnd)).append("\r\n").append("response:\r\n");int paramIndex = methodEnd + 1;//获取参数序列String paramStr = log.substring(paramIndex, log.length());//添加参数 key=value 对paramStr.replace(",", ",\r\n");sb.append(paramStr).append("\r\n\r\n");} else {return logStr;}return sb.toString();}/*** Used to stop the log process after a specified time * * @author Shaofeng Wang (shaofeng.wang@renren-inc.com)*/private class LogFinalizer implements Runnable{private Process process;public LogFinalizer(Process process) {this.process = process;}@Overridepublic void run() {try {Thread.sleep(2000);} catch (InterruptedException e) {}process.destroy();}}
}

转载于:https://www.cnblogs.com/sfshine/archive/2012/10/13/2742847.html

人人网SDK Demo项目学习获取系统Log类相关推荐

  1. WebRTC Native M96 SDK接口封装--enumerateVideoDevices获取系统中所有的视频设备列表

    不管怎样,活着便是盛宴!!! 设备管理是重要的一环,在用户的实际使用过程中,会遇到各种各种的设备问题. 这里,讲一下如何枚举系统中的所有的视频设备列表. 接口定义(Agora) 接口名:enumera ...

  2. 项目中获取系统的用例的基本步骤

    1.绘制关联图,用于定义系统与系统外部实体间的边界和接口的简单模型: 2.创建开发原型,当开发人员或用户不能明确某些需求时,开发一个系统原型,这样使得许多概念和可能发生的事更为直观明了: 3.分析可行 ...

  3. 网上图书商城项目学习笔记-035工具类之JdbcUtils及TxQueryRunner及C3P0配置

    事务就是保证多个操作在同一个connection,TxQueryRunner通过JdbcUtils获取连接,而JdbcUtils通过ThreadLocal<Connection>确保了不同 ...

  4. Api demo源码学习(8)--App/Activity/QuickContactsDemo --获取系统联系人信息

    本节通过Content Provider机制获取系统中的联系人信息,注意这个Anctivity直接继承的是ListActivity,所以不再需要setContentView函数来加载布局文件了(我自己 ...

  5. 博通Broadcom SDK源码学习与开发1——SDK源码探究与Cable Modem 系统编译

    声明:原创作品,严禁用于商业目的. 本系列文章将全面剖析以Bcm33xxx芯片开发Cablemodem产品的SDK源码为例,从编译系统到各个功能模块进行分析与探讨. 文章目录 0.写在前篇 1. 博通 ...

  6. 博通Broadcom SDK源码学习与开发4——ECOS系统数据流

    声明:原创作品,严禁用于商业目的. 本系列文章将全面剖析以Bcm33xxx芯片开发Cablemodem产品的SDK源码为例,从编译系统到各个功能模块进行分析与探讨. 文章目录 0.写在前篇 1. SD ...

  7. vue项目 乐橙云(imouplayer.js)--轻应用直播SDK demo案例(保姆级)

    vue项目 乐橙云(imouplayer.js)--轻应用直播SDK demo测试案例(保姆级) 一.所用到的资源(参数) 1.appId (控制台-我的应用-应用信息中获取) 2.appSecret ...

  8. 学习Linux系统清理/var/log/journal/垃圾日志教程

    学习Linux系统清理/var/log/journal/垃圾日志教程 journal介绍 常见的日志文件 查看垃圾文件的方法 清空 /var/log/journal 文件的方法 1.用 echo 命令 ...

  9. 海康sdk项目部署Linux系统时出现java.lang.UnstisfiedLinkError:jnidispatch(xxx)not found in resource path错误

    海康sdk项目部署Linux系统时出现java.lang.UnstisfiedLinkError:jnidispatch(xxx)not found in resource path错误 问题描述 解 ...

最新文章

  1. 在网页中插入百度地图
  2. MySQL 5.7的新特性(新功能)
  3. identification for completing the census
  4. python与mysql数据库_python与MySQL数据库
  5. Mapreduce原理和YARN
  6. python计算两个时间间隔准确的天、月、年之差
  7. 无废话Git——本地服务器提交撤销
  8. append()方法_超详细教程 | pandas合并之append和concat
  9. 51单片机数控电源c语言设计,单片机数控电源设计,含源代码,原理图
  10. html怎么用excel打开乱码,excel打开是乱码,详细教您excel打开是乱码怎么解决
  11. 做独立淘客app有哪些运营方法
  12. 怎么把音频转换成mp3格式?
  13. android excel在线制作教程,Excel手机表格制作软件
  14. PHP中使用gRPC客户端
  15. vue 控制某个元素的显示与隐藏之v-if属性
  16. Android多点触控之——MotionEvent(触控事件)
  17. c# wifi串口通信_C#中的串口通信
  18. Gif动图如何在线编辑?教你三步在线编辑动图
  19. 【君思智慧园区】产业园区运营服务的创新模式
  20. 百战终破黄金甲,不破楼兰终不还!

热门文章

  1. 实验 6 数组1输出最大值和它所对应的下标
  2. XP共享访问无权限解决方法
  3. 40 | 案例篇:网络请求延迟变大了,我该怎么办?
  4. 【鬼网络】之NFS共享服务
  5. 钉钉宜搭邵磊:钉钉宜搭低代码加速业务互联 让改变发生
  6. 秒懂边缘云 | 边缘云技术进阶
  7. 走出舒适圈,从来都不简单
  8. 源码解析:Git的第一个提交是什么样的?
  9. 2050,一个属于年青人的大会
  10. 小游戏掉帧卡顿启动慢运行内存不足……这些问题有解吗?