Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Faisal Alanzi
Nebulo
Commits
421b1fcc
Commit
421b1fcc
authored
Dec 29, 2020
by
Daniel Wolf
Browse files
Try writing to log file, do not depend on it
parent
b6699f04
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/com/frostnerd/smokescreen/Logger.kt
View file @
421b1fcc
...
...
@@ -118,7 +118,7 @@ fun Context.log(e: Throwable, extras: Map<String, String>? = null) {
"${Logger.logFileNameTimeStampFormatter.format(System.currentTimeMillis())}.err"
)
if
(
errorFile
.
c
reateNewFile
())
{
if
(
errorFile
.
tryC
reateNewFile
())
{
val
writer
=
BufferedWriter
(
FileWriter
(
errorFile
,
false
))
writer
.
write
(
"App version: ${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE}, Commit: ${BuildConfig.COMMIT_HASH})\n"
)
writer
.
write
(
"Android SDK version: ${Build.VERSION.SDK_INT} (${Build.VERSION.RELEASE} - ${Build.VERSION.CODENAME})\n"
)
...
...
@@ -178,7 +178,7 @@ class Logger private constructor(context: Context) {
"${id}_${logFileNameTimeStampFormatter.format(System.currentTimeMillis())}.log"
)
logDir
.
mkdirs
()
logFile
.
c
reateNewFile
()
logFile
.
tryC
reateNewFile
()
fileWriter
=
BufferedWriter
(
FileWriter
(
logFile
,
false
))
log
(
"App version: ${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})"
)
...
...
@@ -306,8 +306,12 @@ class Logger private constructor(context: Context) {
if
(
printToConsole
)
{
(
oldSystemOut
?:
System
.
out
).
println
(
textBuilder
)
}
fileWriter
.
write
(
textBuilder
.
toString
())
fileWriter
.
flush
()
try
{
fileWriter
.
write
(
textBuilder
.
toString
())
fileWriter
.
flush
()
}
catch
(
ex
:
Throwable
)
{
}
}
}
}
...
...
@@ -322,7 +326,7 @@ class Logger private constructor(context: Context) {
"${id}_${logFileNameTimeStampFormatter.format(System.currentTimeMillis())}.err"
)
if
(
errorFile
.
c
reateNewFile
())
{
if
(
errorFile
.
tryC
reateNewFile
())
{
val
writer
=
BufferedWriter
(
FileWriter
(
errorFile
,
false
))
writer
.
write
(
"App version: ${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})\n"
)
writer
.
write
(
"Android SDK version: ${Build.VERSION.SDK_INT} (${Build.VERSION.RELEASE} - ${Build.VERSION.CODENAME})\n"
)
...
...
@@ -340,6 +344,14 @@ class Logger private constructor(context: Context) {
}
}
fun
File
.
tryCreateNewFile
():
Boolean
{
return
try
{
createNewFile
()
}
catch
(
ex
:
Throwable
)
{
false
}
}
fun
Context
.
zipAllLogFiles
():
File
?
{
val
dir
=
Logger
.
getLogDir
(
this
)
if
(!
dir
.
canWrite
()
||
!
dir
.
canRead
())
return
null
...
...
Write
Preview
Supports
Markdown
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