Commit 608f075b by Kim Jinsung

ログ出力を内部ストレージに変更

ログファイルの削除しないように変更
parent 7a2ea6e5
......@@ -3,6 +3,9 @@ package jp.odakyu.toiletsignage.application;
import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
import android.os.Environment;
import java.io.File;
import java.util.List;
import java.util.Timer;
......@@ -25,7 +28,8 @@ public class ToiletApplication extends Application {
public void onCreate() {
super.onCreate();
Logger logger = new Logger();
String logPath = getApplicationContext().getCacheDir().getPath() + "/" + APP_LOG_PATH;
File downloadFilePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
String logPath = downloadFilePath.getPath() + "/" + APP_LOG_PATH;
logger.setLogPathFormat(logPath);
FileUtil.createParentDirectory(logPath);
......
......@@ -9,6 +9,7 @@ import java.util.Date;
import jp.odakyu.toiletsignage.util.DateTimeFormat;
import jp.odakyu.toiletsignage.util.DateTimeUtil;
import jp.odakyu.toiletsignage.util.FileUtil;
import android.util.Log;
public class Logger extends AbstractLogger {
private static AbstractLogger logger = new Logger();
......@@ -170,6 +171,7 @@ public class Logger extends AbstractLogger {
* #26344 端末ログファイル削除方式改善のため
*/
private boolean isDeletable(File file) {
long toTime = retentionPeriod * 24 * 60 * 60 * 1000; // [retentionPeriod] 日
long fromTime = (retentionPeriod + 7) * 24 * 60 * 60 * 1000; // [retentionPeriod + 7] 日
// fromTime < file.lastModified() < toTime
......@@ -189,18 +191,18 @@ public class Logger extends AbstractLogger {
if (logPathFormat != null) {
if (currentDay == null || !currentDay.equals(day)) {
File dir = new File(FileUtil.getParentPath(logPathFormat));
if (dir.exists()) {
File[] files = dir.listFiles();
if (files != null) {
for (File file : files) { // 同一ディレクトリの旧ファイル(retentionPeriod日前)をすべて削除する
// if (file.lastModified() < System.currentTimeMillis() - retentionPeriod * 24 * 60 * 60 * 1000) {
if (isDeletable(file)) {
file.delete();
}
}
}
}
//ログ削除処理しない
// if (dir.exists()) {
// File[] files = dir.listFiles();
// if (files != null) {
// for (File file : files) { // 同一ディレクトリの旧ファイル(retentionPeriod日前)をすべて削除する
//// if (file.lastModified() < System.currentTimeMillis() - retentionPeriod * 24 * 60 * 60 * 1000) {
// if (isDeletable(file)) {
// file.delete();
// }
// }
// }
// }
currentDay = day;
try {
ps = new PrintStream(new FileOutputStream(String.format(logPathFormat, day), true));
......@@ -211,7 +213,7 @@ public class Logger extends AbstractLogger {
}
String time = DateTimeUtil.toString(date, DateTimeFormat.MMddHHmmssSSS_hyphen);
System.out.println(time + ": [" + level + "] " + tag + "(" + Thread.currentThread().getId() + "): " + log);
ps.println(time + ": [" + level + "] " + tag + "(" + Thread.currentThread().getId() + "): " + log);
}
private void log(String level, String defaultLogName, String log, Throwable e) {
......@@ -222,51 +224,61 @@ public class Logger extends AbstractLogger {
@Override
protected void verbose(String tag, String log) {
log("VERBOSE", tag, log);
Log.w(tag,log);
}
@Override
protected void verbose(String tag, String log, Throwable t) {
log("VERBOSE", tag, log, t);
Log.w(tag,log,t);
}
@Override
protected void debug(String tag, String log) {
log("DEBUG", tag, log);
Log.d(tag,log);
}
@Override
protected void debug(String tag, String log, Throwable t) {
log("DEBUG", tag, log, t);
Log.d(tag,log,t);
}
@Override
protected void info(String tag, String log) {
log("INFO", tag, log);
Log.i(tag, log);
}
@Override
protected void info(String tag, String log, Throwable t) {
log("INFO", tag, log, t);
Log.i(tag, log, t);
}
@Override
protected void warn(String tag, String log) {
log("WARN", tag, log);
Log.w(tag, log);
}
@Override
protected void warn(String tag, String log, Throwable t) {
log("WARN", tag, log, t);
Log.w(tag,log, t);
}
@Override
protected void error(String tag, String log) {
log("ERROR", tag, log);
Log.e(tag,log);
}
@Override
protected void error(String tag, String log, Throwable t) {
log("ERROR", tag, log, t);
Log.e(tag,log,t);
}
private static boolean isLoggable(int level) {
......
......@@ -16,7 +16,6 @@ import jp.odakyu.toiletsignage.info.ToiletInfo;
import jp.odakyu.toiletsignage.json.ResultToiletJson;
import jp.odakyu.toiletsignage.json.USBToiletDefaultJson;
import jp.odakyu.toiletsignage.log.Logger;
/**
* Created by agentec on 2017/12/11.
*/
......@@ -51,11 +50,12 @@ public class UpdateToiletInfoTask extends TimerTask {
isError = true;
break;
}
Logger.d(TAG,"jsonString = " + jsonString);
JSONObject jsonObject = new JSONObject(jsonString);
ArrayList<ResultToiletJson> resultToiletJsonArray = new ArrayList<>();
JSONArray jsonArray = jsonObject.getJSONArray(ResultToiletJson.KEY_RESULT);
Logger.d(TAG,"jsonArray.length = " + jsonArray.length());
for (int i = 0; i < jsonArray.length(); i++){
ResultToiletJson resultToiletJson = new ResultToiletJson((JSONObject) jsonArray.get(i));
resultToiletJsonArray.add(resultToiletJson);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment