Update XLog

This commit is contained in:
Jobobby04
2020-11-25 15:57:05 -05:00
parent fcc2b1773b
commit 643aa377bf
30 changed files with 79 additions and 89 deletions
+1 -1
View File
@@ -319,7 +319,7 @@ object EXHMigrations {
try {
dbLocation.copyTo(backupLocation, overwrite = true)
} catch (t: Throwable) {
XLog.w("Failed to backup database!")
logger.enableStackTrace(2).w("Failed to backup database!")
}
}
+8 -6
View File
@@ -22,6 +22,8 @@ class GalleryAdder {
private val sourceManager: SourceManager by injectLazy()
private val logger = XLog.tag("GalleryAdder").enableStackTrace(2).build()
fun pickSource(url: String): List<UrlImportableSource> {
val uri = url.toUri()
return sourceManager.getVisibleCatalogueSources()
@@ -43,7 +45,7 @@ class GalleryAdder {
forceSource: UrlImportableSource? = null,
throttleFunc: () -> Unit = {}
): GalleryAddEvent {
XLog.d(context.getString(R.string.gallery_adder_importing_manga, url, fav.toString(), forceSource))
logger.d(context.getString(R.string.gallery_adder_importing_manga, url, fav.toString(), forceSource))
try {
val uri = url.toUri()
@@ -53,7 +55,7 @@ class GalleryAdder {
if (forceSource.matchesUri(uri)) forceSource
else return GalleryAddEvent.Fail.UnknownType(url, context)
} catch (e: Exception) {
XLog.e(context.getString(R.string.gallery_adder_source_uri_must_match), e)
logger.e(context.getString(R.string.gallery_adder_source_uri_must_match), e)
return GalleryAddEvent.Fail.UnknownType(url, context)
}
} else {
@@ -73,7 +75,7 @@ class GalleryAdder {
val realUrl = try {
source.mapUrlToMangaUrl(uri)
} catch (e: Exception) {
XLog.e(context.getString(R.string.gallery_adder_uri_map_to_manga_error), e)
logger.e(context.getString(R.string.gallery_adder_uri_map_to_manga_error), e)
null
} ?: return GalleryAddEvent.Fail.UnknownType(url, context)
@@ -81,7 +83,7 @@ class GalleryAdder {
val cleanedUrl = try {
source.cleanMangaUrl(realUrl)
} catch (e: Exception) {
XLog.e(context.getString(R.string.gallery_adder_uri_clean_error), e)
logger.e(context.getString(R.string.gallery_adder_uri_clean_error), e)
null
} ?: return GalleryAddEvent.Fail.UnknownType(url, context)
@@ -125,13 +127,13 @@ class GalleryAdder {
} else emptyList<Chapter>() to emptyList()
}.awaitSingle()
} catch (e: Exception) {
XLog.w(context.getString(R.string.gallery_adder_chapter_fetch_error, manga.title), e)
logger.w(context.getString(R.string.gallery_adder_chapter_fetch_error, manga.title), e)
return GalleryAddEvent.Fail.Error(url, context.getString(R.string.gallery_adder_chapter_fetch_error, url))
}
return GalleryAddEvent.Success(url, manga, context)
} catch (e: Exception) {
XLog.w(context.getString(R.string.gallery_adder_could_not_add_manga, url), e)
logger.w(context.getString(R.string.gallery_adder_could_not_add_manga, url), e)
if (e is EHentai.GalleryNotFoundException) {
return GalleryAddEvent.Fail.NotFound(url, context)
@@ -30,6 +30,7 @@ import kotlinx.serialization.json.Json
import uy.kohesive.injekt.injectLazy
import java.lang.RuntimeException
@Suppress("unused")
object DebugFunctions {
val app: Application by injectLazy()
val db: DatabaseHelper by injectLazy()
@@ -239,7 +240,7 @@ object DebugFunctions {
Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
} catch (t: RuntimeException) {
// Load failed
XLog.e("Failed to load saved search!", t)
XLog.tag("DebugFunctions").e("Failed to load saved search!", t)
t.printStackTrace()
null
}
@@ -251,7 +252,7 @@ object DebugFunctions {
Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
} catch (t: RuntimeException) {
// Load failed
XLog.e("Failed to load saved search!", t)
XLog.tag("DebugFunctions").e("Failed to load saved search!", t)
t.printStackTrace()
null
}
@@ -278,7 +279,7 @@ object DebugFunctions {
Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
} catch (t: RuntimeException) {
// Load failed
XLog.e("Failed to load saved search!", t)
XLog.tag("DebugFunctions").e("Failed to load saved search!", t)
t.printStackTrace()
null
}
@@ -290,7 +291,7 @@ object DebugFunctions {
Json.decodeFromString<JsonSavedSearch>(it.substringAfter(':'))
} catch (t: RuntimeException) {
// Load failed
XLog.e("Failed to load saved search!", t)
XLog.tag("DebugFunctions").e("Failed to load saved search!", t)
t.printStackTrace()
null
}
@@ -93,7 +93,7 @@ class MemAutoFlushingLookupTable<T>(
}
}
} catch (e: FileNotFoundException) {
XLog.d("Lookup table not found!", e)
XLog.tag("MemAutoFlushingLookupTable").enableStackTrace(2).d("Lookup table not found!", e)
// Ignored
}
@@ -11,9 +11,9 @@ fun OkHttpClient.Builder.maybeInjectEHLogger(): OkHttpClient.Builder {
val logger: HttpLoggingInterceptor.Logger = HttpLoggingInterceptor.Logger { message ->
try {
Json.decodeFromString<Any>(message)
XLog.tag("||EH-NETWORK-JSON").nst().json(message)
XLog.tag("||EH-NETWORK-JSON").json(message)
} catch (ex: Exception) {
XLog.tag("||EH-NETWORK").nb().nst().d(message)
XLog.tag("||EH-NETWORK").disableBorder().d(message)
}
}
return addInterceptor(HttpLoggingInterceptor(logger).apply { level = HttpLoggingInterceptor.Level.BODY })
@@ -1,6 +1,5 @@
package exh.log
import com.elvishew.xlog.flattener.Flattener2
import com.elvishew.xlog.internal.DefaultsFactory
import com.elvishew.xlog.printer.Printer
import com.elvishew.xlog.printer.file.backup.BackupStrategy
@@ -12,6 +11,7 @@ import java.io.FileWriter
import java.io.IOException
import java.util.concurrent.BlockingQueue
import java.util.concurrent.LinkedBlockingQueue
import com.elvishew.xlog.flattener.Flattener2 as Flattener
/**
* Log [Printer] using file system. When print a log, it will print it to the specified file.
@@ -31,7 +31,7 @@ class EnhancedFilePrinter internal constructor(
private val fileNameGenerator: FileNameGenerator,
private val backupStrategy: BackupStrategy,
private val cleanStrategy: CleanStrategy,
private val flattener: Flattener2
private val flattener: Flattener
) : Printer {
/**
* Log writer.
@@ -134,7 +134,7 @@ class EnhancedFilePrinter internal constructor(
/**
* The flattener when print a log.
*/
private var flattener: Flattener2? = null
private var flattener: Flattener? = null
/**
* Set the file name generator for log file.
@@ -174,9 +174,8 @@ class EnhancedFilePrinter internal constructor(
*
* @param flattener the flattener when print a log
* @return the builder
* @since 1.6.0
*/
fun flattener(flattener: Flattener2): Builder {
fun flattener(flattener: Flattener): Builder {
this.flattener = flattener
return this
}
@@ -187,11 +186,13 @@ class EnhancedFilePrinter internal constructor(
* @return the built configured [EnhancedFilePrinter] object
*/
fun build(): EnhancedFilePrinter {
val fileNameGenerator = fileNameGenerator ?: DefaultsFactory.createFileNameGenerator()
val backupStrategy = backupStrategy ?: DefaultsFactory.createBackupStrategy()
val cleanStrategy = cleanStrategy ?: DefaultsFactory.createCleanStrategy()
val flattener = flattener ?: DefaultsFactory.createFlattener2()
return EnhancedFilePrinter(folderPath, fileNameGenerator, backupStrategy, cleanStrategy, flattener)
return EnhancedFilePrinter(
folderPath,
fileNameGenerator ?: DefaultsFactory.createFileNameGenerator(),
backupStrategy ?: DefaultsFactory.createBackupStrategy(),
cleanStrategy ?: DefaultsFactory.createCleanStrategy(),
flattener ?: DefaultsFactory.createFlattener2()
)
}
}
@@ -244,8 +245,8 @@ class EnhancedFilePrinter internal constructor(
}
override fun run() {
var log: LogItem
try {
var log: LogItem
while (logs.take().also { log = it } != null) {
doPrintln(log.timeMillis, log.level, log.tag, log.msg)
}
@@ -341,7 +342,7 @@ class EnhancedFilePrinter internal constructor(
*/
fun appendLog(flattenedLog: String) {
val bufferedWriter = bufferedWriter
require(bufferedWriter != null)
requireNotNull(bufferedWriter)
try {
bufferedWriter.write(flattenedLog)
bufferedWriter.newLine()
@@ -129,7 +129,7 @@ class ApiMangaParser(private val langs: List<String>) {
if (tags.isNotEmpty()) tags.clear()
tags += genres.map { RaisedTag(null, it, MangaDexSearchMetadata.TAG_TYPE_DEFAULT) }
} catch (e: Exception) {
XLog.e(e)
XLog.tag("ApiMangaParser").enableStackTrace(2).e(e)
throw e
}
}
@@ -239,7 +239,7 @@ class ApiMangaParser(private val langs: List<String>) {
val jsonObject = Json.decodeFromString<JsonObject>(body)
return jsonObject["manga_id"]?.jsonPrimitive?.intOrNull ?: throw Exception("No manga associated with chapter")
} catch (e: Exception) {
XLog.e(e)
XLog.tag("ApiMangaParser").enableStackTrace(2).e(e)
throw e
}
}
@@ -51,7 +51,7 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
response.body?.string().orEmpty()
)
} catch (e: Exception) {
XLog.e("error parsing follows", e)
XLog.tag("FollowsHandler").enableStackTrace(2).e("error parsing follows", e)
FollowsPageResult()
}
@@ -81,7 +81,7 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
response.body?.string().orEmpty()
)
} catch (e: Exception) {
XLog.e("error parsing follows", e)
XLog.tag("FollowsHandler").enableStackTrace(2).e("error parsing follows", e)
FollowsPageResult()
}
val track = Track.create(TrackManager.MDLIST)
@@ -158,7 +158,7 @@ class FollowsHandler(val client: OkHttpClient, val headers: Headers, val prefere
val mangaID = MdUtil.getMangaId(track.tracking_url)
val formBody = FormBody.Builder()
.add("chapter", track.last_chapter_read.toString())
XLog.d("chapter to update %s", track.last_chapter_read.toString())
XLog.tag("FollowsHandler").d("chapter to update %s", track.last_chapter_read.toString())
val response = client.newCall(
POST(
"${MdUtil.baseUrl}/ajax/actions.ajax.php?function=edit_progress&id=$mangaID",
@@ -27,7 +27,7 @@ class MangaHandler(val client: OkHttpClient, val headers: Headers, val langs: Li
val jsonData = withContext(Dispatchers.IO) { response.body!!.string() }
if (response.code != 200) {
XLog.e("error from MangaDex with response code ${response.code} \n body: \n$jsonData")
XLog.tag("MangaHandler").enableStackTrace(2).e("error from MangaDex with response code ${response.code} \n body: \n$jsonData")
throw Exception("Error from MangaDex Response code ${response.code} ")
}
@@ -118,7 +118,7 @@ class SimilarUpdateService(
// Unsubscribe from any previous subscription if needed.
job?.cancel()
val handler = CoroutineExceptionHandler { _, exception ->
XLog.e(exception)
XLog.tag("SimilarUpdateService").enableStackTrace(2).e(exception)
stopSelf(startId)
showResultNotification(true)
cancelProgressNotification()
@@ -37,7 +37,7 @@ class ConfiguringDialogController : DialogController() {
.show()
}
}
XLog.e("Configuration error!", e)
XLog.tag("ConfiguringDialogController").enableStackTrace(2).e("Configuration error!", e)
}
launchUI {
finish()
@@ -81,7 +81,7 @@ class EHConfigurator(val context: Context) {
}
}
XLog.nst().d("Hath perks: $hathPerks")
XLog.tag("EHConfigurator").d("Hath perks: $hathPerks")
configure(ehSource, hathPerks)
configure(exhSource, hathPerks)
@@ -59,7 +59,7 @@ class BatchAddPresenter : BasePresenter<BatchAddController>() {
currentlyAddingRelay.call(STATE_INPUT_TO_PROGRESS)
val handler = CoroutineExceptionHandler { _, throwable ->
XLog.e(throwable)
XLog.tag("BatchAddPresenter").enableStackTrace(2).e(throwable)
}
scope.launch(Dispatchers.IO + handler) {
@@ -187,7 +187,7 @@ class BrowserActionActivity : AppCompatActivity() {
suspend fun captchaSolveFail() {
currentLoopId = null
validateCurrentLoopId = null
XLog.e(IllegalStateException("Captcha solve failure!"))
XLog.tag("BrowserActionActivity").enableStackTrace(2).e(IllegalStateException("Captcha solve failure!"))
withContext(Dispatchers.Main) {
binding.webview.evaluateJavascript(SOLVE_UI_SCRIPT_HIDE, null)
MaterialDialog(this@BrowserActionActivity)
@@ -231,7 +231,7 @@ class BrowserActionActivity : AppCompatActivity() {
val ih = splitResult[3]
val x = binding.webview.x + origX / iw * binding.webview.width
val y = binding.webview.y + origY / ih * binding.webview.height
XLog.nst().d("Found audio button coords: %f %f", x, y)
XLog.tag("BrowserActionActivity").d("Found audio button coords: %f %f", x, y)
simulateClick(x + 50, y + 50)
binding.webview.post {
doStageDownloadAudio(loopId)
@@ -247,12 +247,12 @@ class BrowserActionActivity : AppCompatActivity() {
}
STAGE_DOWNLOAD_AUDIO -> {
if (result != null) {
XLog.nst().d("Got audio URL: $result")
XLog.tag("BrowserActionActivity").d("Got audio URL: $result")
performRecognize(result)
.observeOn(Schedulers.io())
.subscribe(
{
XLog.nst().d("Got audio transcript: $it")
XLog.tag("BrowserActionActivity").d("Got audio transcript: $it")
binding.webview.post {
typeResult(
loopId,
@@ -465,7 +465,7 @@ class BrowserActionActivity : AppCompatActivity() {
if (loopId != validateCurrentLoopId) return
if (result) {
XLog.nst().d("Captcha solved!")
XLog.tag("BrowserActionActivity").d("Captcha solved!")
binding.webview.post {
binding.webview.evaluateJavascript(SOLVE_UI_SCRIPT_HIDE, null)
}
@@ -91,7 +91,7 @@ class LoginController : NucleusController<EhActivityLoginBinding, LoginPresenter
binding.webview.webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView, url: String) {
super.onPageFinished(view, url)
XLog.nst().d(url)
XLog.tag("LoginController").d(url)
val parsedUrl = Uri.parse(url)
if (parsedUrl.host.equals("forums.e-hentai.org", ignoreCase = true)) {
// Hide distracting content
@@ -27,7 +27,7 @@ class MetadataViewPresenter(
override fun onCreate(savedState: Bundle?) {
super.onCreate(savedState)
getMangaMetaObservable().subscribeLatestCache({ view, flatMetadata -> if (flatMetadata != null) view.onNextMetaInfo(flatMetadata) else XLog.nst().d("Invalid metadata") })
getMangaMetaObservable().subscribeLatestCache({ view, flatMetadata -> if (flatMetadata != null) view.onNextMetaInfo(flatMetadata) else XLog.tag("MetadataViewPresenter").disableStackTrace().d("Invalid metadata") })
getMangaObservable()
.observeOn(AndroidSchedulers.mainThread())
+1 -1
View File
@@ -21,7 +21,7 @@ fun Response.interceptAsHtml(block: (Document) -> Unit): Response {
block(parsed)
} catch (t: Throwable) {
// Ignore all errors
XLog.w("Interception error!", t)
XLog.tag("Response.interceptAsHtml").enableStackTrace(2).w("Interception error!", t)
} finally {
close()
}