Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev jingdan #50

Merged
merged 31 commits into from
Sep 8, 2017
Merged

Dev jingdan #50

merged 31 commits into from
Sep 8, 2017

Conversation

binghaiwang
Copy link
Contributor

No description provided.

@CLAassistant
Copy link

CLAassistant commented Aug 18, 2017

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


jingdan seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

@1019272778 1019272778 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 txt 改名 log
2 mainactivity OSSPlainTextAKSKCredentialProvider 去掉
3 testbucket 参数改为sample bucket
4 compile 'com.google.code.gson:gson:2.3.1' 去掉
5 testDeleteBucket oss-cn-beijing 最好是常量
6 OSSLogToFileUtils.java 中的 assertTrue 最好是在try catch block块中

@1019272778
Copy link
Contributor

  1. 新增一个规则。这个功能默认是关闭的。用户可以进行设置打开

@1019272778
Copy link
Contributor

添加测试覆盖率步骤

需要先在OSSTestConfig中修改配置变量
例如bucket名称,ak,sk
在assets中修改STS的相关信息。

执行生成测试case覆盖率 指令
./gradlew clean createDebugCoverageReport
验证覆盖率

README-CN.md Outdated
OSSCredentialProvider credentialProvider = new OSSStsTokenCredentialProvider("<StsToken.AccessKeyId>", "<StsToken.SecretKeyId>", "<StsToken.SecurityToken>");

OSS oss = new OSSClient(getApplicationContext(), endpoint, credentialProvider);
OSS oss = new OSSClient(getApplicationContext(), endpoint, credentialProvider,conf);
Copy link

@baiyubin baiyubin Sep 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • credentialProvider,conf ->credentialProvider, conf conf前添加一个空格。其它地方不再提醒。公司Java代码规范请参看集团开发规

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

public static void init(Context context, ClientConfiguration cfg) {
log(Log.INFO,"init ...");
if (null == sContext || null == instance || null == sLogFile || !sLogFile.exists()) {
if(cfg!=null) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

log(Log.INFO, "LogFilePath is: " + sLogFile.getPath());
// 获取当前日志文件大小
long logFileSize = getFileSize(sLogFile);
log(Log.DEBUG, "Log max size is: " + Formatter.formatFileSize(context, LOG_MAX_SIZE));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • LOG_MAX_SIZE是重要参数也应该使用Log.INFO输出。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

if (file!=null && file.exists()) {
try {
FileInputStream fis = new FileInputStream(file);
size = fis.available();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • FileInputStream.available返回的是文件估算长度,另外返回的是int大于2G的问题会出问题。请确认。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个只是内部使用读取日志文件大小, 日志文件大小基本不会超过5M

// 若目录不存在则创建目录
if(canStorage) {
if (!file.exists()) {
file.mkdir();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • mkdir最好使用mkdirs代替,可能需要创建多级目录。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

*
* @return 当前函数的信息
*/
private String getFunctionInfo(StackTraceElement[] sts) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StackTraceElement[] sts -> StackTraceElement[] ste

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

//写入普通log
pw.println(getInstance().getFunctionInfo(null) + " - " + mStr.toString());
}
pw.println("-----------------------------------------------------------------------");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pw.println("-----------------------------------------------------------------------"); 调试信息吗?如果是去除.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是日志文件 里边 不同日志 分割线

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

//输出流操作 输出日志信息至本地存储空间内
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(sLogFile,true)));
if(pw!=null) {
log(Log.DEBUG,"文件存在:"+sLogFile.exists());
Copy link

@baiyubin baiyubin Sep 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • log(Log.DEBUG,"文件存在:"+sLogFile.exists())日志里面打印 英文,不要有中文,放在乱码出现.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


public class OSSLogToFileUtils {

private static ExecutorService logService = Executors.newSingleThreadExecutor();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • newSingleThreadExecutor 默认应该不限任务队列长度的,会造成内存使用过大,请限制队列长度,合理处理入队失败的任务。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed 替换一个有限队列进行最大控制

private PrintWriter setBaseInfo(PrintWriter pw){
//导出手机信息和异常信息
pw.println("android版本号:" + Build.VERSION.RELEASE);
pw.println("手机型号:" + Build.MODEL);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • android版本号:, 手机型号:, 运营商: 请使用英文。非注释代码不要出现中文。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

}
}

private static void log(int level,String msg){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 为什么要自己实现log功能,不使用第三方库,比如log4j?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

android不适用~

}
catch(UnsupportedEncodingException ex){
throw new RuntimeException("Unsupported algorithm: " + DEFAULT_ENCODING);
//not enter
Copy link

@baiyubin baiyubin Sep 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 为什么不抛出异常?这样会改变行为。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个编码 是写死的utf-8 api默认支持这个格式 ,如果传入的格式参数是用户自己调用的 那么这个异常会发生, 否则 这个异常不会发生

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

}
catch(NoSuchAlgorithmException ex){
throw new RuntimeException("Unsupported algorithm: " + ALGORITHM);
//not enter
Copy link

@baiyubin baiyubin Sep 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 为什么不抛出异常?这样会改变行为。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("MD5 algorithm not found.");
//not enter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 为什么不抛出异常?这样会改变行为。

Copy link
Contributor Author

@binghaiwang binghaiwang Sep 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -70,9 +76,21 @@ public static void logW(String msg) {
* @param msg
*/
public static void logD(String msg) {
logD(msg,true);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • logD建议叫logDebug,logE叫logError,logI叫logInfo,这样比较易读,代码阅读者不需要思考猜测。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

jingdan added 5 commits September 5, 2017 16:44
@binghaiwang binghaiwang merged commit 9d9e848 into master Sep 8, 2017
@binghaiwang binghaiwang deleted the dev_jingdan branch October 12, 2017 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants