Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
odakyuToiletSignage
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kddi
odakyuToiletSignage
Commits
608f075b
Commit
608f075b
authored
Dec 27, 2017
by
Kim Jinsung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ログ出力を内部ストレージに変更
ログファイルの削除しないように変更
parent
7a2ea6e5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
16 deletions
+32
-16
app/src/main/java/jp/odakyu/toiletsignage/application/ToiletApplication.java
+5
-1
app/src/main/java/jp/odakyu/toiletsignage/log/Logger.java
+25
-13
app/src/main/java/jp/odakyu/toiletsignage/task/UpdateToiletInfoTask.java
+2
-2
No files found.
app/src/main/java/jp/odakyu/toiletsignage/application/ToiletApplication.java
View file @
608f075b
...
...
@@ -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
);
...
...
app/src/main/java/jp/odakyu/toiletsignage/log/Logger.java
View file @
608f075b
...
...
@@ -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
)
{
...
...
app/src/main/java/jp/odakyu/toiletsignage/task/UpdateToiletInfoTask.java
View file @
608f075b
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment