Skip to content

Commit a71345e

Browse files
committed
Better error logging.
1 parent 774e77f commit a71345e

4 files changed

Lines changed: 22 additions & 15 deletions

File tree

dfc/src/main/java/com/lazygeniouz/dfc/extension/Extension.kt

Lines changed: 0 additions & 9 deletions
This file was deleted.

dfc/src/main/java/com/lazygeniouz/dfc/file/internals/RawDocumentFileCompat.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package com.lazygeniouz.dfc.file.internals
33
import android.content.Context
44
import android.net.Uri
55
import android.webkit.MimeTypeMap
6-
import com.lazygeniouz.dfc.extension.logError
76
import com.lazygeniouz.dfc.file.DocumentFileCompat
7+
import com.lazygeniouz.dfc.logger.ErrorLogger.logError
88
import java.io.File
99

1010
/**
@@ -95,7 +95,7 @@ internal class RawDocumentFileCompat constructor(context: Context, var file: Fil
9595
if (target.createNewFile()) fromFile(context, target)
9696
else null
9797
} catch (exception: Exception) {
98-
logError("Exception while creating a document: ${exception.message}")
98+
logError("Exception while creating a document", exception)
9999
null
100100
}
101101
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.lazygeniouz.dfc.logger
2+
3+
import android.util.Log
4+
5+
/**
6+
* A logging utility class.
7+
*/
8+
object ErrorLogger {
9+
10+
/**
11+
* Log error to the logcat to let the developer know if something went wrong.
12+
*/
13+
internal fun logError(message: String, throwable: Throwable?) {
14+
Log.e("DocumentFileCompat", "$message: ${throwable?.message}")
15+
}
16+
}

dfc/src/main/java/com/lazygeniouz/dfc/resolver/ResolverCompat.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import android.content.Context
55
import android.database.Cursor
66
import android.net.Uri
77
import android.provider.DocumentsContract
8-
import com.lazygeniouz.dfc.extension.logError
98
import com.lazygeniouz.dfc.file.DocumentFileCompat
109
import com.lazygeniouz.dfc.file.internals.SingleDocumentFileCompat
1110
import com.lazygeniouz.dfc.file.internals.TreeDocumentFileCompat
11+
import com.lazygeniouz.dfc.logger.ErrorLogger.logError
1212

1313
/**
1414
* This class calls relevant queries on the [ContentResolver]
@@ -44,7 +44,7 @@ internal class ResolverCompat(
4444
return try {
4545
DocumentsContract.deleteDocument(contentResolver, uri)
4646
} catch (exception: Exception) {
47-
logError("Exception while deleting document: ${exception.message}")
47+
logError("Exception while deleting document", exception)
4848
false
4949
}
5050
}
@@ -58,7 +58,7 @@ internal class ResolverCompat(
5858
return try {
5959
(DocumentsContract.renameDocument(contentResolver, uri, name) != null)
6060
} catch (exception: Exception) {
61-
logError("Exception while renaming document: ${exception.message}")
61+
logError("Exception while renaming document", exception)
6262
false
6363
}
6464
}
@@ -75,7 +75,7 @@ internal class ResolverCompat(
7575
return try {
7676
DocumentsContract.createDocument(contentResolver, uri, mimeType, name)
7777
} catch (exception: Exception) {
78-
logError("Exception while creating a document: ${exception.message}")
78+
logError("Exception while creating a document", exception)
7979
null
8080
}
8181
}

0 commit comments

Comments
 (0)