-
Notifications
You must be signed in to change notification settings - Fork 306
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
Dev jingdan #50
Conversation
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. |
There was a problem hiding this 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块中
|
添加测试覆盖率步骤 需要先在OSSTestConfig中修改配置变量 执行生成测试case覆盖率 指令 |
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); |
There was a problem hiding this comment.
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代码规范请参看集团开发规。
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- cfg!=null -> cfg != null,请正确使用空格,空行,具体要求请参看https://www.atatech.org/articles/50331,其它地方不在提示。
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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输出。
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- FileInputStream.available返回的是文件估算长度,另外返回的是int大于2G的问题会出问题。请确认。
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- mkdir最好使用mkdirs代替,可能需要创建多级目录。
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StackTraceElement[] sts -> StackTraceElement[] ste
There was a problem hiding this comment.
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("-----------------------------------------------------------------------"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pw.println("-----------------------------------------------------------------------"); 调试信息吗?如果是去除.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是日志文件 里边 不同日志 分割线
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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())
日志里面打印 英文,不要有中文,放在乱码出现.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newSingleThreadExecutor
默认应该不限任务队列长度的,会造成内存使用过大,请限制队列长度,合理处理入队失败的任务。
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
android版本号:
,手机型号:
,运营商:
请使用英文。非注释代码不要出现中文。
There was a problem hiding this comment.
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){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 为什么要自己实现log功能,不使用第三方库,比如log4j?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 为什么不抛出异常?这样会改变行为。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个编码 是写死的utf-8 api默认支持这个格式 ,如果传入的格式参数是用户自己调用的 那么这个异常会发生, 否则 这个异常不会发生
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 为什么不抛出异常?这样会改变行为。
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 为什么不抛出异常?这样会改变行为。
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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,这样比较易读,代码阅读者不需要思考猜测。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
…-sdk into dev_jingdan Conflicts: oss-android-sdk/src/main/java/com/alibaba/sdk/android/common/utils/HttpUtil.java
No description provided.