人人网SDK Demo项目学习获取系统Log类
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类相关推荐
- WebRTC Native M96 SDK接口封装--enumerateVideoDevices获取系统中所有的视频设备列表
不管怎样,活着便是盛宴!!! 设备管理是重要的一环,在用户的实际使用过程中,会遇到各种各种的设备问题. 这里,讲一下如何枚举系统中的所有的视频设备列表. 接口定义(Agora) 接口名:enumera ...
- 项目中获取系统的用例的基本步骤
1.绘制关联图,用于定义系统与系统外部实体间的边界和接口的简单模型: 2.创建开发原型,当开发人员或用户不能明确某些需求时,开发一个系统原型,这样使得许多概念和可能发生的事更为直观明了: 3.分析可行 ...
- 网上图书商城项目学习笔记-035工具类之JdbcUtils及TxQueryRunner及C3P0配置
事务就是保证多个操作在同一个connection,TxQueryRunner通过JdbcUtils获取连接,而JdbcUtils通过ThreadLocal<Connection>确保了不同 ...
- Api demo源码学习(8)--App/Activity/QuickContactsDemo --获取系统联系人信息
本节通过Content Provider机制获取系统中的联系人信息,注意这个Anctivity直接继承的是ListActivity,所以不再需要setContentView函数来加载布局文件了(我自己 ...
- 博通Broadcom SDK源码学习与开发1——SDK源码探究与Cable Modem 系统编译
声明:原创作品,严禁用于商业目的. 本系列文章将全面剖析以Bcm33xxx芯片开发Cablemodem产品的SDK源码为例,从编译系统到各个功能模块进行分析与探讨. 文章目录 0.写在前篇 1. 博通 ...
- 博通Broadcom SDK源码学习与开发4——ECOS系统数据流
声明:原创作品,严禁用于商业目的. 本系列文章将全面剖析以Bcm33xxx芯片开发Cablemodem产品的SDK源码为例,从编译系统到各个功能模块进行分析与探讨. 文章目录 0.写在前篇 1. SD ...
- vue项目 乐橙云(imouplayer.js)--轻应用直播SDK demo案例(保姆级)
vue项目 乐橙云(imouplayer.js)--轻应用直播SDK demo测试案例(保姆级) 一.所用到的资源(参数) 1.appId (控制台-我的应用-应用信息中获取) 2.appSecret ...
- 学习Linux系统清理/var/log/journal/垃圾日志教程
学习Linux系统清理/var/log/journal/垃圾日志教程 journal介绍 常见的日志文件 查看垃圾文件的方法 清空 /var/log/journal 文件的方法 1.用 echo 命令 ...
- 海康sdk项目部署Linux系统时出现java.lang.UnstisfiedLinkError:jnidispatch(xxx)not found in resource path错误
海康sdk项目部署Linux系统时出现java.lang.UnstisfiedLinkError:jnidispatch(xxx)not found in resource path错误 问题描述 解 ...
最新文章
- 在网页中插入百度地图
- MySQL 5.7的新特性(新功能)
- identification for completing the census
- python与mysql数据库_python与MySQL数据库
- Mapreduce原理和YARN
- python计算两个时间间隔准确的天、月、年之差
- 无废话Git——本地服务器提交撤销
- append()方法_超详细教程 | pandas合并之append和concat
- 51单片机数控电源c语言设计,单片机数控电源设计,含源代码,原理图
- html怎么用excel打开乱码,excel打开是乱码,详细教您excel打开是乱码怎么解决
- 做独立淘客app有哪些运营方法
- 怎么把音频转换成mp3格式?
- android excel在线制作教程,Excel手机表格制作软件
- PHP中使用gRPC客户端
- vue 控制某个元素的显示与隐藏之v-if属性
- Android多点触控之——MotionEvent(触控事件)
- c# wifi串口通信_C#中的串口通信
- Gif动图如何在线编辑?教你三步在线编辑动图
- 【君思智慧园区】产业园区运营服务的创新模式
- 百战终破黄金甲,不破楼兰终不还!