Commit 608f075b by Kim Jinsung

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

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