android java log语法,Andoid java文件中的Log检查工具

Andoid java文件中的Log检查工具

AndroidLogChecker

由于发布软件版本的时候我们需要把Log注释掉,此工具可以检查java类中的Log所在行以及是否已经注释。

package com.leo.kang.tools;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import java.util.ArrayList;

import java.util.List;

public class AndroidLogChecker {

static List fileList;

public static void main(String[] args) {

fileList = new ArrayList();

// 递归显示D:test\\src下所有文件夹及其中文件

File root = new File("D:test\\src");

try {

getAllFiles(root);

for (File file : fileList) {

readFileByLine(file);

}

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

/**

* Get all files

*

* @author: yi.kang

* @date: 2014年7月31日 下午8:05:25

* @param dir

* @throws Exception

*/

final static void getAllFiles(File dir) throws Exception {

File[] fs = dir.listFiles();

if (fileList == null) {

fileList = new ArrayList();

}

String path = "";

for (int i = 0; i < fs.length; i++) {

path = fs[i].getAbsolutePath();

//

if (!fs[i].isDirectory() && path.contains(".java")

&& path.substring(path.lastIndexOf(".")).contains("java")) {

fileList.add(fs[i]);

}

if (fs[i].isDirectory()) {

try {

getAllFiles(fs[i]);

} catch (Exception e) {

e.printStackTrace();

}

}

}

}

/**

* Read file line by line

*

* @author: yi.kang

* @date: 2014年7月31日 下午8:06:20

* @param file

*/

public static void readFileByLine(File file) {

try {

// read file content from file

// StringBuffer sb = new StringBuffer("");

String fileName = file.getAbsolutePath();

FileReader reader = new FileReader(fileName);

BufferedReader br = new BufferedReader(reader);

String str = null;

int line = 0;

while ((str = br.readLine()) != null) {

line++;

if (str.contains("Log.i(") || str.contains("Log.d(")

|| str.contains("Log.w(") || str.contains("Log.v(")

|| str.contains("Log.e(")) {

// sb.append(fileName.substring(fileName.lastIndexOf("\\") +

// 1)

// + " line " + line + " " + str.trim() + "/n");

System.out.println(fileName.substring(fileName

.lastIndexOf("\\") + 1)

+ " line "

+ line

+ " "

+ str.trim().replaceAll("\\s", ""));

}

}

br.close();

reader.close();

// write string to file

// FileWriter writer = new FileWriter("c://test2.txt");

// BufferedWriter bw = new BufferedWriter(writer);

// bw.write(sb.toString());

// bw.close();

// writer.close();

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值