diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/LocalPreferences.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/LocalPreferences.kt index ae91ab5db..9165e674e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/LocalPreferences.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/LocalPreferences.kt @@ -254,7 +254,7 @@ object LocalPreferences { val prefsDir = File(prefsDirPath) prefsDir.list()?.forEach { if (it.contains(npub) && !File(prefsDir, it).delete()) { - Log.w("LocalPreferences", "Failed to delete preference file: $it") + Log.w("LocalPreferences") { "Failed to delete preference file: $it" } } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/AntiSpamFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/AntiSpamFilter.kt index 75c9e3aa7..d5033201b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/AntiSpamFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/AntiSpamFilter.kt @@ -87,7 +87,7 @@ class AntiSpamFilter { val link1 = njumpLink(NAddress.create(existingAddress.kind, existingAddress.pubKeyHex, existingAddress.dTag, relay)) val link2 = njumpLink(NAddress.create(event.kind, event.pubKey, event.dTag(), relay)) - Log.w("Duplicated/SPAM", "${relay?.url} $link1 $link2") + Log.w("Duplicated/SPAM") { "${relay?.url} $link1 $link2" } // Log down offenders val spammer = logOffender(hash, event) @@ -114,7 +114,7 @@ class AntiSpamFilter { val link1 = njumpLink(NEvent.create(existingEvent, null, null, relay)) val link2 = njumpLink(NEvent.create(event.id, null, null, relay)) - Log.w("Duplicated/SPAM", "${relay?.url} $link1 $link2") + Log.w("Duplicated/SPAM") { "${relay?.url} $link1 $link2" } // Log down offenders val spammer = logOffender(hash, event) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt index 49c78b9fb..75ea92e42 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt @@ -1931,7 +1931,7 @@ object LocalCache : ILocalCache, ICacheProvider { if (new) { val channel = checkGetOrCreatePublicChatChannel(channelId) if (channel == null) { - Log.w("LocalCache", "Unable to create public chat channel for event ${event.toJson()}") + Log.w("LocalCache") { "Unable to create public chat channel for event ${event.toJson()}" } return false } @@ -2019,7 +2019,7 @@ object LocalCache : ILocalCache, ICacheProvider { val zapRequest = event.zapRequest?.id?.let { getNoteIfExists(it) } if (zapRequest == null || zapRequest.event !is LnZapRequestEvent) { - Log.e("ZP", "Zap Request not found. Unable to process Zap {${event.toJson()}}") + Log.e("ZP") { "Zap Request not found. Unable to process Zap {${event.toJson()}}" } return false } @@ -2924,7 +2924,7 @@ object LocalCache : ILocalCache, ICacheProvider { event.checkSignature() } catch (e: Exception) { if (e is CancellationException) throw e - Log.w("Event Verification Failed", "Kind: ${event.kind} from ${dateFormatter(event.createdAt, "", "")} with message ${e.message}") + Log.w("Event Verification Failed") { "Kind: ${event.kind} from ${dateFormatter(event.createdAt, "", "")} with message ${e.message}" } } false } else { @@ -3247,7 +3247,7 @@ object LocalCache : ILocalCache, ICacheProvider { is WebBookmarkEvent -> consume(event, relay, wasVerified) is WikiNoteEvent -> consume(event, relay, wasVerified) is PaymentTargetsEvent -> consume(event, relay, wasVerified) - else -> Log.w("Event Not Supported", "From ${relay?.url}: ${event.toJson()}").let { false } + else -> Log.w("Event Not Supported") { "From ${relay?.url}: ${event.toJson()}" }.let { false } } } catch (e: Exception) { if (e is CancellationException) throw e diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip11RelayInfo/LoadRelayInfo.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip11RelayInfo/LoadRelayInfo.kt index 6ddb03366..308688d6c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip11RelayInfo/LoadRelayInfo.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip11RelayInfo/LoadRelayInfo.kt @@ -46,7 +46,7 @@ fun loadRelayInfo( value = it }, onError = { url, errorCode, exceptionMessage -> - Log.e("RelayInfo", "Error loading relay info for ${relay.url}: $errorCode - $exceptionMessage") + Log.e("RelayInfo") { "Error loading relay info for ${relay.url}: $errorCode - $exceptionMessage" } }, ) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/NamecoinSharedPreferences.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/NamecoinSharedPreferences.kt index b6bab2374..28b06b129 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/NamecoinSharedPreferences.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/NamecoinSharedPreferences.kt @@ -128,7 +128,7 @@ class NamecoinSharedPreferences( } } catch (e: Exception) { if (e is CancellationException) throw e - Log.e("NamecoinPrefs", "Error writing pinned certs: ${e.message}") + Log.e("NamecoinPrefs") { "Error writing pinned certs: ${e.message}" } } } @@ -159,7 +159,7 @@ class NamecoinSharedPreferences( } } catch (e: Exception) { if (e is CancellationException) throw e - Log.e("NamecoinPrefs", "Error writing DataStore: ${e.message}") + Log.e("NamecoinPrefs") { "Error writing DataStore: ${e.message}" } } } @@ -181,7 +181,7 @@ class NamecoinSharedPreferences( NamecoinSettings(enabled = enabled, customServers = servers) } catch (e: Exception) { if (e is CancellationException) throw e - Log.e("NamecoinPrefs", "Error reading DataStore: ${e.message}") + Log.e("NamecoinPrefs") { "Error reading DataStore: ${e.message}" } null } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/OtsSharedPreferences.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/OtsSharedPreferences.kt index 315278f50..9c769c796 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/OtsSharedPreferences.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/OtsSharedPreferences.kt @@ -86,7 +86,7 @@ class OtsSharedPreferences( } } catch (e: Exception) { if (e is CancellationException) throw e - Log.e("OtsPrefs", "Error writing DataStore: ${e.message}") + Log.e("OtsPrefs") { "Error writing DataStore: ${e.message}" } } } @@ -97,7 +97,7 @@ class OtsSharedPreferences( OtsSettings(customExplorerUrl = url) } catch (e: Exception) { if (e is CancellationException) throw e - Log.e("OtsPrefs", "Error reading DataStore: ${e.message}") + Log.e("OtsPrefs") { "Error reading DataStore: ${e.message}" } null } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/TorSharedPreferences.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/TorSharedPreferences.kt index 97422d41b..94d69ccca 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/TorSharedPreferences.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/TorSharedPreferences.kt @@ -106,7 +106,7 @@ class TorSharedPreferences( } catch (e: Exception) { if (e is CancellationException) throw e // Log any errors that occur while reading the DataStore. - Log.e("SharedPreferences", "Error reading DataStore preferences: ${e.message}") + Log.e("SharedPreferences") { "Error reading DataStore preferences: ${e.message}" } null } @@ -130,7 +130,7 @@ class TorSharedPreferences( } catch (e: Exception) { if (e is CancellationException) throw e // Log any errors that occur while reading the DataStore. - Log.e("SharedPreferences", "Error saving DataStore preferences: ${e.message}") + Log.e("SharedPreferences") { "Error saving DataStore preferences: ${e.message}" } } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/UISharedPreferences.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/UISharedPreferences.kt index bce3c62da..c3519c0e6 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/UISharedPreferences.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/preferences/UISharedPreferences.kt @@ -127,7 +127,7 @@ class UiSharedPreferences( } catch (e: Exception) { if (e is CancellationException) throw e // Log any errors that occur while reading the DataStore. - Log.e("SharedPreferences", "Error reading DataStore preferences: ${e.message}") + Log.e("SharedPreferences") { "Error reading DataStore preferences: ${e.message}" } try { val oldVersion = LocalPreferences.loadSharedSettings() @@ -159,7 +159,7 @@ class UiSharedPreferences( } catch (e: Exception) { if (e is CancellationException) throw e // Log any errors that occur while reading the DataStore. - Log.e("SharedPreferences", "Error saving DataStore preferences: ${e.message}") + Log.e("SharedPreferences") { "Error saving DataStore preferences: ${e.message}" } } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/location/ReverseGeolocation.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/location/ReverseGeolocation.kt index 6a57764e9..3caed0056 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/location/ReverseGeolocation.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/location/ReverseGeolocation.kt @@ -59,7 +59,7 @@ class ReverseGeolocation { override fun onError(errorMessage: String?) { super.onError(errorMessage) - Log.w("ReverseGeoLocation", "Failure $errorMessage") + Log.w("ReverseGeoLocation") { "Failure $errorMessage" } onReady(null) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/logging/ChoreographerHelper.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/logging/ChoreographerHelper.kt index c4d7569d0..591079375 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/logging/ChoreographerHelper.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/logging/ChoreographerHelper.kt @@ -41,7 +41,7 @@ object ChoreographerHelper { if (diff > 35) { // Follow the frame number val droppedCount = (diff / 16.6).toInt() - Log.w("block-canary", "Dropped $droppedCount frames. Skipped $diff ms") + Log.w("block-canary") { "Dropped $droppedCount frames. Skipped $diff ms" } } lastFrameTimeNanos = frameTimeNanos Choreographer.getInstance().postFrameCallback(this) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/NotificationReplyReceiver.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/NotificationReplyReceiver.kt index f5009118e..0289c3406 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/NotificationReplyReceiver.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/NotificationReplyReceiver.kt @@ -85,7 +85,7 @@ class NotificationReplyReceiver : BroadcastReceiver() { notificationManager.cancel(notificationId) } catch (e: Exception) { if (e is CancellationException) throw e - Log.e("NotificationReply", "Failed to send reply: ${e.message}") + Log.e("NotificationReply") { "Failed to send reply: ${e.message}" } } finally { pendingResult.finish() diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/service/PlaybackServiceClient.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/service/PlaybackServiceClient.kt index d3daa7ff6..534e2d025 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/service/PlaybackServiceClient.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/service/PlaybackServiceClient.kt @@ -96,7 +96,7 @@ object PlaybackServiceClient { try { MediaController.releaseFuture(controllerFuture) } catch (e: Exception) { - Log.e("Playback Client", "Failed to release Playback Client for $id $videoUri ${e.message}") + Log.e("Playback Client") { "Failed to release Playback Client for $id $videoUri ${e.message}" } } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/FileHeader.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/FileHeader.kt index 49abc9616..79427a04b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/FileHeader.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/FileHeader.kt @@ -58,7 +58,7 @@ class FileHeader( } } catch (e: Exception) { if (e is CancellationException) throw e - Log.e("ImageDownload", "Couldn't download image from server: ${e.message}") + Log.e("ImageDownload") { "Couldn't download image from server: ${e.message}" } Result.failure(e) } @@ -76,7 +76,7 @@ class FileHeader( Result.success(FileHeader(mimeType, hash, size, dim, blurHash)) } catch (e: Exception) { if (e is CancellationException) throw e - Log.e("ImageDownload", "Couldn't convert image in to File Header: ${e.message}") + Log.e("ImageDownload") { "Couldn't convert image in to File Header: ${e.message}" } Result.failure(e) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/MediaCompressor.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/MediaCompressor.kt index 5b25944a3..5cc488797 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/MediaCompressor.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/MediaCompressor.kt @@ -99,7 +99,7 @@ class MediaCompressor { default(width = 640, format = Bitmap.CompressFormat.JPEG, quality = imageQuality) } if (tempFile != compressedImageFile && !tempFile.delete()) { - Log.w("MediaCompressor", "Failed to delete temp file: ${tempFile.absolutePath}") + Log.w("MediaCompressor") { "Failed to delete temp file: ${tempFile.absolutePath}" } } Log.d("MediaCompressor") { "Image compression success. New size [${compressedImageFile.length()}]" } MediaCompressorResult(compressedImageFile.toUri(), MimeTypes.IMAGE_JPEG, compressedImageFile.length()) @@ -107,7 +107,7 @@ class MediaCompressor { if (e is CancellationException) throw e Log.d("MediaCompressor") { "Image compression failed: ${e.message}" } if (tempFile?.delete() == false) { - Log.w("MediaCompressor", "Failed to delete temp file: ${tempFile.absolutePath}") + Log.w("MediaCompressor") { "Failed to delete temp file: ${tempFile.absolutePath}" } } MediaCompressorResult(uri, contentType, null) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/MetadataStripper.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/MetadataStripper.kt index 0e1abd7d2..9a0363394 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/MetadataStripper.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/MetadataStripper.kt @@ -172,7 +172,7 @@ object MetadataStripper { muxer?.release() extractor.release() if (!succeeded && !outputFile.delete()) { - Log.w("MetadataStripper", "Failed to delete temp file: ${outputFile.absolutePath}") + Log.w("MetadataStripper") { "Failed to delete temp file: ${outputFile.absolutePath}" } } } return succeeded @@ -202,7 +202,7 @@ object MetadataStripper { context.contentResolver.openInputStream(uri) ?: run { if (!tempFile.delete()) { - Log.w("MetadataStripper", "Failed to delete temp file: ${tempFile.absolutePath}") + Log.w("MetadataStripper") { "Failed to delete temp file: ${tempFile.absolutePath}" } } return StrippingResult(uri, false) } @@ -223,7 +223,7 @@ object MetadataStripper { } catch (e: Exception) { if (e is CancellationException) throw e if (tempFile?.delete() == false) { - Log.w("MetadataStripper", "Failed to delete temp file: ${tempFile.absolutePath}") + Log.w("MetadataStripper") { "Failed to delete temp file: ${tempFile.absolutePath}" } } Log.d("MetadataStripper") { "Failed to strip image metadata: ${e.message}" } StrippingResult(uri, false) @@ -311,7 +311,7 @@ object MetadataStripper { } } ?: run { if (!tempInputFile.delete()) { - Log.w("MetadataStripper", "Failed to delete temp file: ${tempInputFile.absolutePath}") + Log.w("MetadataStripper") { "Failed to delete temp file: ${tempInputFile.absolutePath}" } } return StrippingResult(uri, false) } @@ -354,7 +354,7 @@ object MetadataStripper { if (startOffset == 0L && endOffset == fileSize) { if (!tempInputFile.delete()) { - Log.w("MetadataStripper", "Failed to delete temp file: ${tempInputFile.absolutePath}") + Log.w("MetadataStripper") { "Failed to delete temp file: ${tempInputFile.absolutePath}" } } tempInputFile = null return StrippingResult(uri, true) // no tags found, already clean @@ -376,7 +376,7 @@ object MetadataStripper { } } if (!tempInputFile.delete()) { - Log.w("MetadataStripper", "Failed to delete temp file: ${tempInputFile.absolutePath}") + Log.w("MetadataStripper") { "Failed to delete temp file: ${tempInputFile.absolutePath}" } } tempInputFile = null @@ -385,7 +385,7 @@ object MetadataStripper { } catch (e: Exception) { if (e is CancellationException) throw e if (tempInputFile?.delete() == false) { - Log.w("MetadataStripper", "Failed to delete temp file: ${tempInputFile.absolutePath}") + Log.w("MetadataStripper") { "Failed to delete temp file: ${tempInputFile.absolutePath}" } } Log.d("MetadataStripper") { "Failed to strip MP3 metadata: ${e.message}" } StrippingResult(uri, false) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/VideoCompressionHelper.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/VideoCompressionHelper.kt index c78f7dddc..945bf32b5 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/VideoCompressionHelper.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/VideoCompressionHelper.kt @@ -233,7 +233,7 @@ object VideoCompressionHelper { // Sanity check: compression not smaller than original if (originalSize in 1..size) { if (!File(path).delete()) { - Log.w("VideoCompressionHelper", "Failed to delete compressed file: $path") + Log.w("VideoCompressionHelper") { "Failed to delete compressed file: $path" } } applicationContext.notifyUser( "Compressed file larger than original. Using original.", diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt index 21268e128..357f85ec4 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableContentView.kt @@ -960,7 +960,7 @@ private suspend fun shareVideoFile( delay(SHARED_VIDEO_CLEANUP_DELAY_MS) sharedFile?.let { file -> if (!file.delete()) { - Log.w("ZoomableContentView", "Failed to delete shared file: ${file.path}") + Log.w("ZoomableContentView") { "Failed to delete shared file: ${file.path}" } } } } @@ -974,11 +974,11 @@ private suspend fun shareVideoFile( // Clean up temp file on error if (!tempFile.delete()) { - Log.w("ZoomableContentView", "Failed to delete temp file: ${tempFile.path}") + Log.w("ZoomableContentView") { "Failed to delete temp file: ${tempFile.path}" } } sharedFile?.let { file -> if (!file.delete()) { - Log.w("ZoomableContentView", "Failed to delete shared file: ${file.path}") + Log.w("ZoomableContentView") { "Failed to delete shared file: ${file.path}" } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Highlight.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Highlight.kt index 6cbb6251f..26a947d0c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Highlight.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/Highlight.kt @@ -361,7 +361,7 @@ fun DisplayEntryForAUrl( try { URL(url) } catch (_: Exception) { - Log.w("Note Compose", "Invalid URI: $url") + Log.w("Note Compose") { "Invalid URI: $url" } null } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/DecryptAndIndexProcessor.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/DecryptAndIndexProcessor.kt index 2b3eeeaf9..a569b5ac9 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/DecryptAndIndexProcessor.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/DecryptAndIndexProcessor.kt @@ -134,7 +134,7 @@ class EventProcessor( } if (deletedDrafts.isNotEmpty()) { - Log.w("EventProcessor", "Deleting ${deletedDrafts.size} draft notes") + Log.w("EventProcessor") { "Deleting ${deletedDrafts.size} draft notes" } account.delete(deletedDrafts) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/dal/HiddenAccountsFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/dal/HiddenAccountsFeedFilter.kt index 0ec1d5b64..119a427c2 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/dal/HiddenAccountsFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/dal/HiddenAccountsFeedFilter.kt @@ -40,7 +40,7 @@ class HiddenAccountsFeedFilter( LocalCache.getOrCreateUser(it) } catch (e: Exception) { if (e is CancellationException) throw e - Log.e("HiddenAccountsFeedFilter", "Failed to parse key $it") + Log.e("HiddenAccountsFeedFilter") { "Failed to parse key $it" } null } } diff --git a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/robohash/RobohashAssembler.kt b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/robohash/RobohashAssembler.kt index 6a493dd04..66edbae1e 100644 --- a/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/robohash/RobohashAssembler.kt +++ b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/robohash/RobohashAssembler.kt @@ -167,7 +167,7 @@ class RobohashAssembler { if (Hex.isHex(msg) && msg.length > 10) { Hex.decode(msg) } else { - Log.w("Robohash", "$msg is not a hex") + Log.w("Robohash") { "$msg is not a hex" } sha256(msg.toByteArray()) } diff --git a/quartz/src/appleMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.apple.kt b/quartz/src/appleMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.apple.kt index 882c298c6..1c53c5373 100644 --- a/quartz/src/appleMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.apple.kt +++ b/quartz/src/appleMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.apple.kt @@ -23,51 +23,40 @@ package com.vitorpamplona.quartz.utils import platform.Foundation.NSLog actual object PlatformLog { - actual fun w( + private fun log( + level: String, tag: String, message: String, throwable: Throwable?, ) { if (throwable != null) { - NSLog("WARN: [$tag] $message. Throwable: $throwable CAUSE ${throwable.cause}") + NSLog("$level: [$tag] $message. Throwable: $throwable CAUSE ${throwable.cause}") } else { - NSLog("WARN: [$tag] $message") + NSLog("$level: [$tag] $message") } } + actual fun w( + tag: String, + message: String, + throwable: Throwable?, + ) = log("WARN", tag, message, throwable) + actual fun e( tag: String, message: String, throwable: Throwable?, - ) { - if (throwable != null) { - NSLog("ERROR: [$tag] $message. Throwable: $throwable CAUSE ${throwable.cause}") - } else { - NSLog("ERROR: [$tag] $message") - } - } + ) = log("ERROR", tag, message, throwable) actual fun d( tag: String, message: String, throwable: Throwable?, - ) { - if (throwable != null) { - NSLog("DEBUG: [$tag] $message. Throwable: $throwable CAUSE ${throwable.cause}") - } else { - NSLog("DEBUG: [$tag] $message") - } - } + ) = log("DEBUG", tag, message, throwable) actual fun i( tag: String, message: String, throwable: Throwable?, - ) { - if (throwable != null) { - NSLog("INFO: [$tag] $message. Throwable: $throwable CAUSE ${throwable.cause}") - } else { - NSLog("INFO: [$tag] $message") - } - } + ) = log("INFO", tag, message, throwable) } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/core/AddressSerializer.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/core/AddressSerializer.kt index 1f9029cff..ec77fae66 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/core/AddressSerializer.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/core/AddressSerializer.kt @@ -46,7 +46,7 @@ class AddressSerializer { if (parts.size > 2 && parts[1].length == 64 && Hex.isHex(parts[1])) { if (parts[0].length > 5) { // invalid kind - Log.w("AddressableId", "Error parsing. invalid kind $addressId") + Log.w("AddressableId") { "Error parsing. invalid kind $addressId" } null } else { Address(parts[0].toInt(), parts[1], parts.getOrNull(2) ?: "") @@ -57,11 +57,11 @@ class AddressSerializer { if (addr is NAddress) { addr.address() } else { - Log.w("AddressableId", "Error parsing. naddr1 seems invalid: $addressId") + Log.w("AddressableId") { "Error parsing. naddr1 seems invalid: $addressId" } null } } else { - Log.w("AddressableId", "Error parsing. Not a valid address: $addressId") + Log.w("AddressableId") { "Error parsing. Not a valid address: $addressId" } null } } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/metadata/MetadataEvent.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/metadata/MetadataEvent.kt index eaae4027d..d7084aad9 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/metadata/MetadataEvent.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/metadata/MetadataEvent.kt @@ -71,7 +71,7 @@ class MetadataEvent( Json.parseToJsonElement(content) as JsonObject } catch (e: Exception) { if (e is CancellationException) throw e - Log.w("MetadataEvent", "Content Parse Error: ${toNostrUri()} ${e.message}") + Log.w("MetadataEvent") { "Content Parse Error: ${toNostrUri()} ${e.message}" } null } @@ -80,7 +80,7 @@ class MetadataEvent( JsonMapper.fromJson(content) } catch (e: Exception) { if (e is CancellationException) throw e - Log.w("MetadataEvent", "Content Parse Error: ${toNostrUri()} ${e.message}") + Log.w("MetadataEvent") { "Content Parse Error: ${toNostrUri()} ${e.message}" } null } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/pool/RelayBasedFilter.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/pool/RelayBasedFilter.kt index c117d6f95..102101ec9 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/pool/RelayBasedFilter.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/pool/RelayBasedFilter.kt @@ -36,7 +36,7 @@ fun List.groupByRelay(): Map> val result = mutableMapOf>() for (relayBasedFilter in this) { if (relayBasedFilter.filter.isEmpty()) { - Log.e("FilterError", "Ignoring empty filter for ${relayBasedFilter.relay}") + Log.e("FilterError") { "Ignoring empty filter for ${relayBasedFilter.relay}" } } else { result.getOrPut(relayBasedFilter.relay) { mutableListOf() }.add(relayBasedFilter.filter) } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/filters/Filter.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/filters/Filter.kt index 4fa6c6847..b21b7eec0 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/filters/Filter.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/filters/Filter.kt @@ -91,32 +91,32 @@ class Filter( init { ids?.forEach { - if (it.length != 64) Log.e("FilterError", "Invalid id length $it on ${toJson()}") + if (it.length != 64) Log.e("FilterError") { "Invalid id length $it on ${toJson()}" } } authors?.forEach { - if (it.length != 64) Log.e("FilterError", "Invalid author length $it on ${toJson()}") + if (it.length != 64) Log.e("FilterError") { "Invalid author length $it on ${toJson()}" } } // tests common tags. if (tags != null) { tags["p"]?.forEach { - if (it.length != 64) Log.e("FilterError", "Invalid p-tag length $it on ${toJson()}") + if (it.length != 64) Log.e("FilterError") { "Invalid p-tag length $it on ${toJson()}" } } tags["e"]?.forEach { - if (it.length != 64) Log.e("FilterError", "Invalid e-tag length $it on ${toJson()}") + if (it.length != 64) Log.e("FilterError") { "Invalid e-tag length $it on ${toJson()}" } } tags["a"]?.forEach { - if (Address.parse(it) == null) Log.e("FilterError", "Invalid a-tag $it on ${toJson()}") + if (Address.parse(it) == null) Log.e("FilterError") { "Invalid a-tag $it on ${toJson()}" } } } if (tagsAll != null) { tagsAll["p"]?.forEach { - if (it.length != 64) Log.e("FilterError", "Invalid p-tag length $it on ${toJson()}") + if (it.length != 64) Log.e("FilterError") { "Invalid p-tag length $it on ${toJson()}" } } tagsAll["e"]?.forEach { - if (it.length != 64) Log.e("FilterError", "Invalid e-tag length $it on ${toJson()}") + if (it.length != 64) Log.e("FilterError") { "Invalid e-tag length $it on ${toJson()}" } } tagsAll["a"]?.forEach { - if (Address.parse(it) == null) Log.e("FilterError", "Invalid a-tag $it on ${toJson()}") + if (Address.parse(it) == null) Log.e("FilterError") { "Invalid a-tag $it on ${toJson()}" } } } } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/normalizer/RelayUrlNormalizer.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/normalizer/RelayUrlNormalizer.kt index c89c5df52..ffd1da4d6 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/normalizer/RelayUrlNormalizer.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/normalizer/RelayUrlNormalizer.kt @@ -145,7 +145,7 @@ class RelayUrlNormalizer { if (trimmed.contains("://")) { // some other scheme we cannot connect to. - Log.w("RelayUrlNormalizer", "Rejected $url") + Log.w("RelayUrlNormalizer") { "Rejected $url" } return null } @@ -178,14 +178,14 @@ class RelayUrlNormalizer { normalizedUrls.put(url, NormalizationResult.Success(normalized)) normalized } else { - Log.w("NormalizedRelayUrl", "Rejected $url") + Log.w("NormalizedRelayUrl") { "Rejected $url" } normalizedUrls.put(url, NormalizationResult.Error) null } } catch (e: Exception) { if (e is CancellationException) throw e normalizedUrls.put(url, NormalizationResult.Error) - Log.w("NormalizedRelayUrl", "Rejected $url") + Log.w("NormalizedRelayUrl") { "Rejected $url" } null } } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/server/RelaySession.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/server/RelaySession.kt index 2a384d8a6..71a6fb944 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/server/RelaySession.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/server/RelaySession.kt @@ -73,7 +73,7 @@ class RelaySession( try { onSend(OptimizedJsonMapper.toJson(message)) } catch (e: Exception) { - Log.w("ClientSession", "Failed to send to ${e.message}") + Log.w("ClientSession") { "Failed to send to ${e.message}" } } } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip03Timestamp/ots/OpenTimestamps.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip03Timestamp/ots/OpenTimestamps.kt index 9392896b1..ce326cf83 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip03Timestamp/ots/OpenTimestamps.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip03Timestamp/ots/OpenTimestamps.kt @@ -156,7 +156,7 @@ class OpenTimestamps( ): Timestamp { val responses = mapNotNullAsync(calendarUrls) { calendarUrl -> - Log.i("OpenTimestamps", "Submitting to remote calendar $calendarUrl") + Log.i("OpenTimestamps") { "Submitting to remote calendar $calendarUrl" } calendar.submit(calendarUrl, timestamp.digest) } @@ -361,7 +361,7 @@ class OpenTimestamps( val attsFromRemote: MutableSet = upgradedStamp.getAttestations() if (attsFromRemote.isNotEmpty()) { - Log.i("OpenTimestamps", "Got 1 attestation(s) from $calendarUrl") + Log.i("OpenTimestamps") { "Got 1 attestation(s) from $calendarUrl" } } // Set difference from remote attestations & existing attestations diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip03Timestamp/ots/op/OpUnary.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip03Timestamp/ots/op/OpUnary.kt index 40d8004da..0c1c3cf73 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip03Timestamp/ots/op/OpUnary.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip03Timestamp/ots/op/OpUnary.kt @@ -56,7 +56,7 @@ abstract class OpUnary : Op() { } else -> { - Log.e("OpenTimestamp", "Unknown operation tag: $tag") + Log.e("OpenTimestamp") { "Unknown operation tag: $tag" } null // TODO: Is this OK? Won't it blow up later? Better to throw? } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip04Dm/crypto/EncryptedInfo.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip04Dm/crypto/EncryptedInfo.kt index a144170ae..a0dcaef32 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip04Dm/crypto/EncryptedInfo.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip04Dm/crypto/EncryptedInfo.kt @@ -62,7 +62,7 @@ class EncryptedInfo( nonce = Base64.decode(parts[1]), ) } catch (e: Exception) { - Log.w("NIP04", "Unable to Parse encrypted payload: $payload") + Log.w("NIP04") { "Unable to Parse encrypted payload: $payload" } null } } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip19Bech32/ATagExt.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip19Bech32/ATagExt.kt index eb643fa9f..77a0ef9f4 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip19Bech32/ATagExt.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip19Bech32/ATagExt.kt @@ -51,7 +51,7 @@ fun ATag.Companion.parseAtag( ATag(parts[0].toInt(), parts[1], parts[2], relayHint) } catch (t: Throwable) { - Log.w("ATag", "Error parsing A Tag: $atag: ${t.message}") + Log.w("ATag") { "Error parsing A Tag: $atag: ${t.message}" } null } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip19Bech32/Nip19Parser.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip19Bech32/Nip19Parser.kt index d9df56831..5fd03a905 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip19Bech32/Nip19Parser.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip19Bech32/Nip19Parser.kt @@ -78,7 +78,7 @@ object Nip19Parser { return type!! + key } catch (e: Throwable) { - Log.e("NIP19 Parser", "Issue trying to Decode NIP19 $uri: ${e.message}") + Log.e("NIP19 Parser") { "Issue trying to Decode NIP19 $uri: ${e.message}" } } return null @@ -98,7 +98,7 @@ object Nip19Parser { return parseComponents(type, key, additionalChars?.ifEmpty { null }) } catch (e: Throwable) { - Log.e("NIP19 Parser", "Issue trying to Decode NIP19 $uri: ${e.message}") + Log.e("NIP19 Parser") { "Issue trying to Decode NIP19 $uri: ${e.message}" } } return null @@ -127,7 +127,7 @@ object Nip19Parser { ParseReturn(it, nip19, additionalChars) } } catch (e: Throwable) { - Log.w("NIP19 Parser", "Issue trying to Decode NIP19 $key: ${e.message}") + Log.w("NIP19 Parser") { "Issue trying to Decode NIP19 $key: ${e.message}" } null } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip19Bech32/entities/NAddress.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip19Bech32/entities/NAddress.kt index 6cd3af2a2..155864843 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip19Bech32/entities/NAddress.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip19Bech32/entities/NAddress.kt @@ -55,7 +55,7 @@ data class NAddress( return parse(key.bechToBytes()) } } catch (e: Throwable) { - Log.w("NAddress", "Issue trying to Decode NIP19 $this: ${e.message}") + Log.w("NAddress") { "Issue trying to Decode NIP19 $this: ${e.message}" } } return null diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip28PublicChat/admin/ChannelCreateEvent.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip28PublicChat/admin/ChannelCreateEvent.kt index c52358a80..b4d0d59f9 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip28PublicChat/admin/ChannelCreateEvent.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip28PublicChat/admin/ChannelCreateEvent.kt @@ -68,7 +68,7 @@ class ChannelCreateEvent( } } catch (e: Exception) { if (e is CancellationException) throw e - Log.w("ChannelCreateEvent", "Failure to parse ${this.toJson()}") + Log.w("ChannelCreateEvent") { "Failure to parse ${this.toJson()}" } ChannelDataNorm() } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip28PublicChat/admin/ChannelMetadataEvent.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip28PublicChat/admin/ChannelMetadataEvent.kt index aa7c415da..f3208477b 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip28PublicChat/admin/ChannelMetadataEvent.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip28PublicChat/admin/ChannelMetadataEvent.kt @@ -74,7 +74,7 @@ class ChannelMetadataEvent( } } catch (e: Exception) { if (e is CancellationException) throw e - Log.w("ChannelCreateEvent", "Failure to parse ${this.toJson()}") + Log.w("ChannelCreateEvent") { "Failure to parse ${this.toJson()}" } ChannelDataNorm() } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip37Drafts/DraftWrapEvent.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip37Drafts/DraftWrapEvent.kt index f2930b640..31d818e45 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip37Drafts/DraftWrapEvent.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip37Drafts/DraftWrapEvent.kt @@ -60,7 +60,7 @@ class DraftWrapEvent( fromJson(json) } catch (e: Exception) { if (e is CancellationException) throw e - Log.w("DraftEvent", "Unable to parse inner event of a draft: $json") + Log.w("DraftEvent") { "Unable to parse inner event of a draft: $json" } throw e } } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip51Lists/encryption/PrivateTagsInContent.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip51Lists/encryption/PrivateTagsInContent.kt index 72bf2d090..a4e625cc3 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip51Lists/encryption/PrivateTagsInContent.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip51Lists/encryption/PrivateTagsInContent.kt @@ -43,7 +43,7 @@ class PrivateTagsInContent { decode(json) } catch (e: Exception) { if (e is CancellationException) throw e - Log.w("DraftEvent", "Unable to parse inner event of a draft: $json") + Log.w("DraftEvent") { "Unable to parse inner event of a draft: $json" } throw e } } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip56Reports/ReportType.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip56Reports/ReportType.kt index d2d00f93f..45ecf99e1 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip56Reports/ReportType.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip56Reports/ReportType.kt @@ -90,7 +90,7 @@ enum class ReportType( "スパム \uD83D\uDCE3" -> SPAM "Pourriel \uD83D\uDCE3" -> SPAM "violence" -> VIOLENCE - else -> Log.w("ReportedEventTag", "Report type not supported: `$code` ${tag.joinToString(", ")}").let { OTHER } + else -> Log.w("ReportedEventTag") { "Report type not supported: `$code` ${tag.joinToString(", ")}" }.let { OTHER } } } } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip90Dvms/NIP90ContentDiscoveryResponseEvent.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip90Dvms/NIP90ContentDiscoveryResponseEvent.kt index 65687157d..8d97e0f00 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip90Dvms/NIP90ContentDiscoveryResponseEvent.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip90Dvms/NIP90ContentDiscoveryResponseEvent.kt @@ -61,7 +61,7 @@ class NIP90ContentDiscoveryResponseEvent( } } } catch (e: Throwable) { - Log.w("NIP90ContentDiscoveryResponseEvent", "Error parsing the JSON ${e.message}") + Log.w("NIP90ContentDiscoveryResponseEvent") { "Error parsing the JSON ${e.message}" } } return events ?: listOf() diff --git a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip01Core/store/sqlite/LargeDBTests.kt b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip01Core/store/sqlite/LargeDBTests.kt index 82a982c1d..58ed4f0fd 100644 --- a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip01Core/store/sqlite/LargeDBTests.kt +++ b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip01Core/store/sqlite/LargeDBTests.kt @@ -62,7 +62,7 @@ class LargeDBTests { try { db.insert(event) } catch (e: SQLiteException) { - Log.w("LargeDBTests", "Error inserting event: ${e.message} for event: ${event.toJson()}") + Log.w("LargeDBTests") { "Error inserting event: ${e.message} for event: ${event.toJson()}" } } } } @@ -73,7 +73,7 @@ class LargeDBTests { try { db.insert(event) } catch (e: SQLiteException) { - Log.w("LargeDBTests", "Error inserting event: ${e.message} for event: ${event.toJson()}") + Log.w("LargeDBTests") { "Error inserting event: ${e.message} for event: ${event.toJson()}" } } } } diff --git a/quartz/src/jvmMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.jvm.kt b/quartz/src/jvmMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.jvm.kt index 33a737a66..c46efd525 100644 --- a/quartz/src/jvmMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.jvm.kt +++ b/quartz/src/jvmMain/kotlin/com/vitorpamplona/quartz/utils/PlatformLog.jvm.kt @@ -24,56 +24,44 @@ import java.time.LocalTime import java.time.format.DateTimeFormatter actual object PlatformLog { - // Define a formatter for the desired output format (e.g., HH:mm:ss) - val formatter: DateTimeFormatter? = DateTimeFormatter.ofPattern("HH:mm:ss.SSS") + private val formatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSS") - fun time() = LocalTime.now().format(formatter) + private fun time() = LocalTime.now().format(formatter) + + private fun log( + level: String, + tag: String, + message: String, + throwable: Throwable?, + ) { + if (throwable != null) { + println("${time()} $level: [$tag] $message. Throwable: ${throwable.message}") + } else { + println("${time()} $level: [$tag] $message") + } + } actual fun w( tag: String, message: String, throwable: Throwable?, - ) { - if (throwable != null) { - println("${time()} WARN : [$tag] $message. Throwable: ${throwable.message}") - } else { - println("${time()} WARN : [$tag] $message") - } - } + ) = log("WARN ", tag, message, throwable) actual fun e( tag: String, message: String, throwable: Throwable?, - ) { - if (throwable != null) { - println("${time()} ERROR: [$tag] $message. Throwable: ${throwable.message}") - } else { - println("${time()} ERROR: [$tag] $message") - } - } + ) = log("ERROR", tag, message, throwable) actual fun d( tag: String, message: String, throwable: Throwable?, - ) { - if (throwable != null) { - println("${time()} DEBUG: [$tag] $message. Throwable: ${throwable.message}") - } else { - println("${time()} DEBUG: [$tag] $message") - } - } + ) = log("DEBUG", tag, message, throwable) actual fun i( tag: String, message: String, throwable: Throwable?, - ) { - if (throwable != null) { - println("${time()} INFO : [$tag] $message. Throwable: ${throwable.message}") - } else { - println("${time()} INFO : [$tag] $message") - } - } + ) = log("INFO ", tag, message, throwable) }