diff --git a/settings.gradle.kts b/settings.gradle.kts
index 3b63c01e1a..54d5f1a9b2 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -124,6 +124,7 @@ include(":subprojects:logger:gradle-logger")
include(":subprojects:logger:logger")
include(":subprojects:logger:sentry-logger")
include(":subprojects:logger:elastic-logger")
+include(":subprojects:logger:android-logger")
include(":subprojects:delivery:artifactory-app-backup")
include(":subprojects:delivery:cd")
diff --git a/subprojects/assemble/build-metrics/src/gradleTest/kotlin/com/avito/android/plugin/build_metrics/BuildMetricsPluginTest.kt b/subprojects/assemble/build-metrics/src/gradleTest/kotlin/com/avito/android/plugin/build_metrics/BuildMetricsPluginTest.kt
index d1e7d88c9b..fe800c4559 100644
--- a/subprojects/assemble/build-metrics/src/gradleTest/kotlin/com/avito/android/plugin/build_metrics/BuildMetricsPluginTest.kt
+++ b/subprojects/assemble/build-metrics/src/gradleTest/kotlin/com/avito/android/plugin/build_metrics/BuildMetricsPluginTest.kt
@@ -32,7 +32,6 @@ internal class BuildMetricsPluginTest {
),
buildGradleExtra = """
|gradleLogger {
- | appendMetadata.set(true)
| printlnHandler(false, com.avito.logger.LogLevel.DEBUG)
|}
""".trimMargin()
diff --git a/subprojects/assemble/build-metrics/src/gradleTest/kotlin/com/avito/android/plugin/build_metrics/cache/BuildCacheMetricsTest.kt b/subprojects/assemble/build-metrics/src/gradleTest/kotlin/com/avito/android/plugin/build_metrics/cache/BuildCacheMetricsTest.kt
index d692f7ceb9..b0bf5b2a0d 100644
--- a/subprojects/assemble/build-metrics/src/gradleTest/kotlin/com/avito/android/plugin/build_metrics/cache/BuildCacheMetricsTest.kt
+++ b/subprojects/assemble/build-metrics/src/gradleTest/kotlin/com/avito/android/plugin/build_metrics/cache/BuildCacheMetricsTest.kt
@@ -19,7 +19,6 @@ internal class BuildCacheMetricsTest : BuildCacheTestFixture() {
}
gradleLogger {
- appendMetadata.set(true)
printlnHandler(false, com.avito.logger.LogLevel.DEBUG)
}
diff --git a/subprojects/assemble/build-metrics/src/gradleTest/kotlin/com/avito/android/plugin/build_metrics/cache/HttpBuildCacheMetricsTest.kt b/subprojects/assemble/build-metrics/src/gradleTest/kotlin/com/avito/android/plugin/build_metrics/cache/HttpBuildCacheMetricsTest.kt
index a91d5a1fed..20cb138af5 100644
--- a/subprojects/assemble/build-metrics/src/gradleTest/kotlin/com/avito/android/plugin/build_metrics/cache/HttpBuildCacheMetricsTest.kt
+++ b/subprojects/assemble/build-metrics/src/gradleTest/kotlin/com/avito/android/plugin/build_metrics/cache/HttpBuildCacheMetricsTest.kt
@@ -64,7 +64,6 @@ internal class HttpBuildCacheMetricsTest : HttpBuildCacheTestFixture() {
id("com.avito.android.build-metrics")
}
gradleLogger {
- appendMetadata.set(true)
printlnHandler(false, com.avito.logger.LogLevel.DEBUG)
}
diff --git a/subprojects/assemble/build-metrics/src/gradleTest/kotlin/com/avito/android/plugin/build_metrics/tasks/TasksMetricsTest.kt b/subprojects/assemble/build-metrics/src/gradleTest/kotlin/com/avito/android/plugin/build_metrics/tasks/TasksMetricsTest.kt
index f41b4837b5..776536d720 100644
--- a/subprojects/assemble/build-metrics/src/gradleTest/kotlin/com/avito/android/plugin/build_metrics/tasks/TasksMetricsTest.kt
+++ b/subprojects/assemble/build-metrics/src/gradleTest/kotlin/com/avito/android/plugin/build_metrics/tasks/TasksMetricsTest.kt
@@ -25,7 +25,6 @@ internal class TasksMetricsTest {
},
buildGradleExtra = """
|gradleLogger {
- | appendMetadata.set(true)
| printlnHandler(false, com.avito.logger.LogLevel.DEBUG)
|}
""".trimMargin(),
diff --git a/subprojects/logger/android-logger/build.gradle.kts b/subprojects/logger/android-logger/build.gradle.kts
new file mode 100644
index 0000000000..cdd7c9971c
--- /dev/null
+++ b/subprojects/logger/android-logger/build.gradle.kts
@@ -0,0 +1,8 @@
+plugins {
+ id("convention.kotlin-android-library")
+ id("convention.publish-android-library")
+}
+
+dependencies {
+ api(projects.subprojects.logger.logger)
+}
diff --git a/subprojects/logger/android-logger/src/main/AndroidManifest.xml b/subprojects/logger/android-logger/src/main/AndroidManifest.xml
new file mode 100644
index 0000000000..70bb7918b3
--- /dev/null
+++ b/subprojects/logger/android-logger/src/main/AndroidManifest.xml
@@ -0,0 +1 @@
+
diff --git a/subprojects/logger/android-logger/src/main/kotlin/com/avito/logger/handler/AndroidLogcatLoggingHandler.kt b/subprojects/logger/android-logger/src/main/kotlin/com/avito/logger/handler/AndroidLogcatLoggingHandler.kt
new file mode 100644
index 0000000000..f2d05c1238
--- /dev/null
+++ b/subprojects/logger/android-logger/src/main/kotlin/com/avito/logger/handler/AndroidLogcatLoggingHandler.kt
@@ -0,0 +1,19 @@
+package com.avito.logger.handler
+
+import android.util.Log
+import com.avito.logger.LogLevel
+
+internal class AndroidLogcatLoggingHandler(
+ private val tag: String,
+ acceptedLogLevel: LogLevel
+) : LogLevelLoggingHandler(acceptedLogLevel) {
+
+ override fun handleIfAcceptLogLevel(level: LogLevel, message: String, error: Throwable?) {
+ when (level) {
+ LogLevel.DEBUG -> Log.d(tag, message, error)
+ LogLevel.INFO -> Log.i(tag, message, error)
+ LogLevel.WARNING -> Log.w(tag, message, error)
+ LogLevel.CRITICAL -> Log.e(tag, message, error)
+ }
+ }
+}
diff --git a/subprojects/logger/android-logger/src/main/kotlin/com/avito/logger/handler/AndroidLogcatLoggingHandlerProvider.kt b/subprojects/logger/android-logger/src/main/kotlin/com/avito/logger/handler/AndroidLogcatLoggingHandlerProvider.kt
new file mode 100644
index 0000000000..73290ad754
--- /dev/null
+++ b/subprojects/logger/android-logger/src/main/kotlin/com/avito/logger/handler/AndroidLogcatLoggingHandlerProvider.kt
@@ -0,0 +1,14 @@
+package com.avito.logger.handler
+
+import com.avito.logger.LogLevel
+import com.avito.logger.metadata.LoggerMetadata
+
+public class AndroidLogcatLoggingHandlerProvider(private val acceptedLogLevel: LogLevel) : LoggingHandlerProvider {
+
+ override fun provide(metadata: LoggerMetadata): LoggingHandler {
+ return AndroidLogcatLoggingHandler(
+ tag = metadata.asMessagePrefix,
+ acceptedLogLevel = acceptedLogLevel
+ )
+ }
+}
diff --git a/subprojects/logger/elastic-logger/src/main/kotlin/com/avito/logger/destination/ElasticLoggingHandlerProvider.kt b/subprojects/logger/elastic-logger/src/main/kotlin/com/avito/logger/destination/ElasticLoggingHandlerProvider.kt
index a8c55d26a3..79c310dcea 100644
--- a/subprojects/logger/elastic-logger/src/main/kotlin/com/avito/logger/destination/ElasticLoggingHandlerProvider.kt
+++ b/subprojects/logger/elastic-logger/src/main/kotlin/com/avito/logger/destination/ElasticLoggingHandlerProvider.kt
@@ -2,9 +2,9 @@ package com.avito.logger.destination
import com.avito.android.elastic.ElasticClient
import com.avito.logger.LogLevel
-import com.avito.logger.LoggerMetadata
import com.avito.logger.handler.LoggingHandler
import com.avito.logger.handler.LoggingHandlerProvider
+import com.avito.logger.metadata.LoggerMetadata
public class ElasticLoggingHandlerProvider(
private val acceptedLogLevel: LogLevel,
diff --git a/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/FileHandledLoggerMetadata.kt b/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/FileHandledLoggerMetadata.kt
index b34c95e91b..f18ccc3919 100644
--- a/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/FileHandledLoggerMetadata.kt
+++ b/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/FileHandledLoggerMetadata.kt
@@ -1,5 +1,6 @@
package com.avito.logger
+import com.avito.logger.metadata.LoggerMetadata
import java.nio.file.Path
/**
diff --git a/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/GradleLoggerExtension.kt b/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/GradleLoggerExtension.kt
index 05722bceda..b2f1ac31ab 100644
--- a/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/GradleLoggerExtension.kt
+++ b/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/GradleLoggerExtension.kt
@@ -23,7 +23,6 @@ public abstract class GradleLoggerExtension {
val config: ElasticConfig
) : Serializable
- public abstract val appendMetadata: Property
public abstract val fileHandler: Property
public abstract val fileHandlerRootDir: DirectoryProperty
internal abstract val printlnHandler: Property
@@ -44,7 +43,6 @@ public abstract class GradleLoggerExtension {
}
internal fun finalizeValues() {
- appendMetadata.finalizeValue()
fileHandler.finalizeValue()
fileHandlerRootDir.finalizeValue()
printlnHandler.finalizeValue()
diff --git a/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/GradleLoggerMetadata.kt b/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/GradleLoggerMetadata.kt
index bb2e13746e..6c0449a060 100644
--- a/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/GradleLoggerMetadata.kt
+++ b/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/GradleLoggerMetadata.kt
@@ -2,12 +2,12 @@ package com.avito.logger
import java.nio.file.Path
-public data class GradleLoggerMetadata(
- public override val tag: String,
- public val coordinates: GradleLoggerCoordinates
+internal class GradleLoggerMetadata(
+ private val tag: String,
+ private val coordinates: GradleLoggerCoordinates
) : FileHandledLoggerMetadata {
- private val asString by lazy {
+ override val asMessagePrefix: String by lazy {
buildString {
append('[')
append(tag)
@@ -37,8 +37,6 @@ public data class GradleLoggerMetadata(
}
}
- override fun asString(): String = asString
-
override fun asMap(): Map {
val result = mutableMapOf(
"tag" to tag,
diff --git a/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/GradleLoggerPlugin.kt b/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/GradleLoggerPlugin.kt
index 1a84d96999..3b0ac3b8d9 100644
--- a/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/GradleLoggerPlugin.kt
+++ b/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/GradleLoggerPlugin.kt
@@ -17,7 +17,6 @@ public class GradleLoggerPlugin : Plugin {
checkProjectIsRoot(target)
val extension = target.extensions.create("gradleLogger", GradleLoggerExtension::class.java)
extension.fileHandlerRootDir.set(target.layout.buildDirectory.dir("logs"))
- extension.appendMetadata.set(true)
target.afterEvaluate {
/**
* The problem is some plugins could start use LoggerService before build script evaluated
@@ -102,7 +101,6 @@ public class GradleLoggerPlugin : Plugin {
.withZone(ZoneId.from(ZoneOffset.UTC))
val instant = Instant.now()
it.parameters {
- it.appendMetadata.set(extension.appendMetadata)
it.printlnHandler.set(extension.printlnHandler)
it.fileHandler.set(extension.fileHandler)
it.fileHandlerRootDir.set(extension.fileHandlerRootDir.map { it.dir(formatter.format(instant)) })
diff --git a/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/GradleMetadataProvider.kt b/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/GradleMetadataProvider.kt
index 4f5219bce6..4424285ba6 100644
--- a/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/GradleMetadataProvider.kt
+++ b/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/GradleMetadataProvider.kt
@@ -1,5 +1,8 @@
package com.avito.logger
+import com.avito.logger.metadata.LoggerMetadata
+import com.avito.logger.metadata.LoggerMetadataProvider
+
internal class GradleMetadataProvider(
private val coordinates: GradleLoggerCoordinates
) : LoggerMetadataProvider {
diff --git a/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/LegacyGradleLoggerConfigurator.kt b/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/LegacyGradleLoggerConfigurator.kt
index 7c70600ec1..17d5c3297c 100644
--- a/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/LegacyGradleLoggerConfigurator.kt
+++ b/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/LegacyGradleLoggerConfigurator.kt
@@ -15,7 +15,6 @@ internal class LegacyGradleLoggerConfigurator(
fun configure(parameters: LoggerService.Params) {
with(parameters) {
- appendMetadata.set(true)
val verbosity = getVerbosity() ?: LogLevel.INFO
printlnHandler.set(GradleLoggerExtension.PrintlnMode(verbosity, doPrintStackTrace()))
fileHandler.set(LogLevel.INFO)
diff --git a/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/LoggerService.kt b/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/LoggerService.kt
index 9d173b3c32..67e444cfc2 100644
--- a/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/LoggerService.kt
+++ b/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/LoggerService.kt
@@ -6,7 +6,7 @@ import com.avito.android.elastic.ElasticClientFactory
import com.avito.android.sentry.sentryClient
import com.avito.logger.destination.ElasticLoggingHandlerProvider
import com.avito.logger.destination.SentryLoggingHandlerProvider
-import com.avito.logger.formatter.AppendMetadataFormatter
+import com.avito.logger.handler.FileLoggingHandlerProvider
import com.avito.logger.handler.LoggingHandlerProvider
import com.avito.logger.handler.PrintlnLoggingHandlerProvider
import org.gradle.api.file.DirectoryProperty
@@ -17,7 +17,6 @@ import org.gradle.api.services.BuildServiceParameters
public abstract class LoggerService : BuildService {
public interface Params : BuildServiceParameters {
- public val appendMetadata: Property
public val fileHandler: Property
public val fileHandlerRootDir: DirectoryProperty
public val printlnHandler: Property
@@ -32,8 +31,6 @@ public abstract class LoggerService : BuildService {
}
}
- private val appendMetadata: Boolean = parameters.appendMetadata.getOrElse(false)
-
private val handlerProviders: List by lazy {
val providers = mutableListOf()
with(parameters) {
@@ -66,9 +63,6 @@ public abstract class LoggerService : BuildService {
public fun createLoggerFactory(coordinates: GradleLoggerCoordinates): LoggerFactory {
val builder = LoggerFactoryBuilder()
with(builder) {
- if (appendMetadata) {
- formatter(AppendMetadataFormatter)
- }
metadataProvider(GradleMetadataProvider(coordinates))
handlerProviders.forEach { addLoggingHandlerProvider(it) }
}
diff --git a/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/FileLoggingHandler.kt b/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/handler/FileLoggingHandler.kt
similarity index 85%
rename from subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/FileLoggingHandler.kt
rename to subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/handler/FileLoggingHandler.kt
index c7f44a1835..7fb2367a64 100644
--- a/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/FileLoggingHandler.kt
+++ b/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/handler/FileLoggingHandler.kt
@@ -1,11 +1,12 @@
-package com.avito.logger
+package com.avito.logger.handler
-import com.avito.logger.handler.LogLevelLoggingHandler
+import com.avito.logger.LogLevel
import java.io.PrintWriter
import java.nio.file.Files
import java.nio.file.Path
internal class FileLoggingHandler(
+ private val messagePrefix: String,
acceptedLogLevel: LogLevel,
logFile: Path
) : LogLevelLoggingHandler(acceptedLogLevel) {
@@ -17,7 +18,7 @@ internal class FileLoggingHandler(
private val stackTraceWriter by lazy { PrintWriter(fileWriter) }
override fun handleIfAcceptLogLevel(level: LogLevel, message: String, error: Throwable?) {
- fileWriter.write("[$level] $message")
+ fileWriter.write("$messagePrefix [$level] $message")
fileWriter.newLine()
if (error != null) {
val errorMessage = error.message
diff --git a/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/FileLoggingHandlerProvider.kt b/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/handler/FileLoggingHandlerProvider.kt
similarity index 82%
rename from subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/FileLoggingHandlerProvider.kt
rename to subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/handler/FileLoggingHandlerProvider.kt
index 12d34f8472..e1565589a4 100644
--- a/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/FileLoggingHandlerProvider.kt
+++ b/subprojects/logger/gradle-logger/src/main/kotlin/com/avito/logger/handler/FileLoggingHandlerProvider.kt
@@ -1,7 +1,8 @@
-package com.avito.logger
+package com.avito.logger.handler
-import com.avito.logger.handler.LoggingHandler
-import com.avito.logger.handler.LoggingHandlerProvider
+import com.avito.logger.FileHandledLoggerMetadata
+import com.avito.logger.LogLevel
+import com.avito.logger.metadata.LoggerMetadata
import java.io.File
import kotlin.io.path.createDirectories
import kotlin.io.path.exists
@@ -32,6 +33,6 @@ internal class FileLoggingHandlerProvider(
require(absoluteLogDirPath.isDirectory()) {
"Must be dir but was $absoluteLogDirPath"
}
- return FileLoggingHandler(acceptedLogLevel, absoluteLogFilePath)
+ return FileLoggingHandler(metadata.asMessagePrefix, acceptedLogLevel, absoluteLogFilePath)
}
}
diff --git a/subprojects/logger/logger/src/main/kotlin/com/avito/logger/DefaultLoggerFactory.kt b/subprojects/logger/logger/src/main/kotlin/com/avito/logger/DefaultLoggerFactory.kt
index 6fe001cdb2..5b1a0f0504 100644
--- a/subprojects/logger/logger/src/main/kotlin/com/avito/logger/DefaultLoggerFactory.kt
+++ b/subprojects/logger/logger/src/main/kotlin/com/avito/logger/DefaultLoggerFactory.kt
@@ -2,9 +2,10 @@ package com.avito.logger
import com.avito.logger.handler.CompositeLoggingHandler
import com.avito.logger.handler.LoggingHandlerProvider
+import com.avito.logger.metadata.LoggerMetadataProvider
+import com.avito.logger.metadata.TagLoggerMetadataProvider
internal class DefaultLoggerFactory(
- private val formatter: LoggingFormatter?,
private val metadataProvider: LoggerMetadataProvider,
private val handlerProviders: List
) : LoggerFactory {
@@ -19,27 +20,15 @@ internal class DefaultLoggerFactory(
val metadata = metadataProvider.provide(tag)
val handlers = handlerProviders.map { it.provide(metadata) }
val handler = CompositeLoggingHandler(handlers)
- return LoggerImpl(
- handler = if (formatter != null) {
- FormatterLoggingHandler(formatter, handler, metadata)
- } else {
- handler
- },
- )
+ return LoggerImpl(handler)
}
}
public class LoggerFactoryBuilder {
- private var formatter: LoggingFormatter = LoggingFormatter.NoOpFormatter
private var metadataProvider: LoggerMetadataProvider = TagLoggerMetadataProvider
private val handlerProviders = mutableListOf()
- public fun formatter(formatter: LoggingFormatter): LoggerFactoryBuilder {
- this.formatter = formatter
- return this
- }
-
public fun metadataProvider(provider: LoggerMetadataProvider): LoggerFactoryBuilder {
this.metadataProvider = provider
return this
@@ -54,7 +43,6 @@ public class LoggerFactoryBuilder {
public fun newBuilder(): LoggerFactoryBuilder {
return LoggerFactoryBuilder().also { newBuilder ->
- newBuilder.formatter = formatter
newBuilder.metadataProvider = metadataProvider
newBuilder.handlerProviders.addAll(handlerProviders)
}
@@ -62,7 +50,6 @@ public class LoggerFactoryBuilder {
public fun build(): LoggerFactory {
return DefaultLoggerFactory(
- formatter = formatter,
metadataProvider = metadataProvider,
handlerProviders = handlerProviders.toList()
)
diff --git a/subprojects/logger/logger/src/main/kotlin/com/avito/logger/LoggerMetadataProvider.kt b/subprojects/logger/logger/src/main/kotlin/com/avito/logger/LoggerMetadataProvider.kt
deleted file mode 100644
index a5e149945d..0000000000
--- a/subprojects/logger/logger/src/main/kotlin/com/avito/logger/LoggerMetadataProvider.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.avito.logger
-
-public interface LoggerMetadata {
- public val tag: String
- public fun asString(): String
-
- public fun asMap(): Map
-}
-
-internal class TagLoggerMetadata(override val tag: String) : LoggerMetadata {
- private val asString by lazy { "[$tag]" }
- override fun asString() = asString
- override fun asMap(): Map {
- return mapOf("tag" to tag)
- }
-}
-
-internal object TagLoggerMetadataProvider : LoggerMetadataProvider {
-
- override fun provide(tag: String) = TagLoggerMetadata(tag)
-}
-
-public interface LoggerMetadataProvider {
- public fun provide(tag: String): LoggerMetadata
-}
diff --git a/subprojects/logger/logger/src/main/kotlin/com/avito/logger/LoggingFormatter.kt b/subprojects/logger/logger/src/main/kotlin/com/avito/logger/LoggingFormatter.kt
deleted file mode 100644
index 5b08cc65ef..0000000000
--- a/subprojects/logger/logger/src/main/kotlin/com/avito/logger/LoggingFormatter.kt
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.avito.logger
-
-import com.avito.logger.handler.LoggingHandler
-
-public interface LoggingFormatter {
-
- public fun format(metadata: LoggerMetadata, message: String): String
-
- public object NoOpFormatter : LoggingFormatter {
- override fun format(metadata: LoggerMetadata, message: String): String {
- // do nothing
- return message
- }
- }
-}
-
-internal class FormatterLoggingHandler(
- private val formatter: LoggingFormatter,
- private val delegate: LoggingHandler,
- private val metadata: LoggerMetadata
-) : LoggingHandler {
-
- override fun write(level: LogLevel, message: String, error: Throwable?) {
- delegate.write(
- level,
- formatter.format(metadata, message),
- error
- )
- }
-}
diff --git a/subprojects/logger/logger/src/main/kotlin/com/avito/logger/formatter/AppendMetadataFormatter.kt b/subprojects/logger/logger/src/main/kotlin/com/avito/logger/formatter/AppendMetadataFormatter.kt
deleted file mode 100644
index d2b97e1111..0000000000
--- a/subprojects/logger/logger/src/main/kotlin/com/avito/logger/formatter/AppendMetadataFormatter.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.avito.logger.formatter
-
-import com.avito.logger.LoggerMetadata
-import com.avito.logger.LoggingFormatter
-
-public object AppendMetadataFormatter : LoggingFormatter {
-
- override fun format(metadata: LoggerMetadata, message: String): String = buildString {
- append(metadata.asString())
- append(' ')
- append(message)
- }
-}
diff --git a/subprojects/logger/logger/src/main/kotlin/com/avito/logger/handler/LoggingHandlerProvider.kt b/subprojects/logger/logger/src/main/kotlin/com/avito/logger/handler/LoggingHandlerProvider.kt
index 050556f3df..f8929a026b 100644
--- a/subprojects/logger/logger/src/main/kotlin/com/avito/logger/handler/LoggingHandlerProvider.kt
+++ b/subprojects/logger/logger/src/main/kotlin/com/avito/logger/handler/LoggingHandlerProvider.kt
@@ -1,6 +1,6 @@
package com.avito.logger.handler
-import com.avito.logger.LoggerMetadata
+import com.avito.logger.metadata.LoggerMetadata
public interface LoggingHandlerProvider {
public fun provide(metadata: LoggerMetadata): LoggingHandler
diff --git a/subprojects/logger/logger/src/main/kotlin/com/avito/logger/handler/PrintlnLoggingHandler.kt b/subprojects/logger/logger/src/main/kotlin/com/avito/logger/handler/PrintlnLoggingHandler.kt
index 604bab78eb..165750c056 100644
--- a/subprojects/logger/logger/src/main/kotlin/com/avito/logger/handler/PrintlnLoggingHandler.kt
+++ b/subprojects/logger/logger/src/main/kotlin/com/avito/logger/handler/PrintlnLoggingHandler.kt
@@ -1,7 +1,7 @@
package com.avito.logger.handler
import com.avito.logger.LogLevel
-import com.avito.logger.LoggerMetadata
+import com.avito.logger.metadata.LoggerMetadata
public class PrintlnLoggingHandlerProvider(
private val acceptedLogLevel: LogLevel,
@@ -9,17 +9,18 @@ public class PrintlnLoggingHandlerProvider(
) : LoggingHandlerProvider {
override fun provide(metadata: LoggerMetadata): LoggingHandler {
- return PrintlnLoggingHandler(acceptedLogLevel, printStackTrace)
+ return PrintlnLoggingHandler(acceptedLogLevel, printStackTrace, metadata.asMessagePrefix)
}
}
internal class PrintlnLoggingHandler(
acceptedLogLevel: LogLevel,
- private val printStackTrace: Boolean
+ private val printStackTrace: Boolean,
+ private val messagePrefix: String
) : LogLevelLoggingHandler(acceptedLogLevel) {
override fun handleIfAcceptLogLevel(level: LogLevel, message: String, error: Throwable?) {
- println(message)
+ println("$messagePrefix $message")
if (printStackTrace && error != null) {
error.printStackTrace()
}
diff --git a/subprojects/logger/logger/src/main/kotlin/com/avito/logger/metadata/LoggerMetadata.kt b/subprojects/logger/logger/src/main/kotlin/com/avito/logger/metadata/LoggerMetadata.kt
new file mode 100644
index 0000000000..0b93731425
--- /dev/null
+++ b/subprojects/logger/logger/src/main/kotlin/com/avito/logger/metadata/LoggerMetadata.kt
@@ -0,0 +1,6 @@
+package com.avito.logger.metadata
+
+public interface LoggerMetadata {
+ public val asMessagePrefix: String
+ public fun asMap(): Map
+}
diff --git a/subprojects/logger/logger/src/main/kotlin/com/avito/logger/metadata/LoggerMetadataProvider.kt b/subprojects/logger/logger/src/main/kotlin/com/avito/logger/metadata/LoggerMetadataProvider.kt
new file mode 100644
index 0000000000..6d37e21a46
--- /dev/null
+++ b/subprojects/logger/logger/src/main/kotlin/com/avito/logger/metadata/LoggerMetadataProvider.kt
@@ -0,0 +1,5 @@
+package com.avito.logger.metadata
+
+public interface LoggerMetadataProvider {
+ public fun provide(tag: String): LoggerMetadata
+}
diff --git a/subprojects/logger/logger/src/main/kotlin/com/avito/logger/metadata/TagLoggerMetadata.kt b/subprojects/logger/logger/src/main/kotlin/com/avito/logger/metadata/TagLoggerMetadata.kt
new file mode 100644
index 0000000000..f5aacf2a8a
--- /dev/null
+++ b/subprojects/logger/logger/src/main/kotlin/com/avito/logger/metadata/TagLoggerMetadata.kt
@@ -0,0 +1,10 @@
+package com.avito.logger.metadata
+
+internal class TagLoggerMetadata(private val tag: String) : LoggerMetadata {
+
+ override val asMessagePrefix: String = "[$tag]"
+
+ override fun asMap(): Map {
+ return mapOf("tag" to tag)
+ }
+}
diff --git a/subprojects/logger/logger/src/main/kotlin/com/avito/logger/metadata/TagLoggerMetadataProvider.kt b/subprojects/logger/logger/src/main/kotlin/com/avito/logger/metadata/TagLoggerMetadataProvider.kt
new file mode 100644
index 0000000000..56b740cf1b
--- /dev/null
+++ b/subprojects/logger/logger/src/main/kotlin/com/avito/logger/metadata/TagLoggerMetadataProvider.kt
@@ -0,0 +1,6 @@
+package com.avito.logger.metadata
+
+internal object TagLoggerMetadataProvider : LoggerMetadataProvider {
+
+ override fun provide(tag: String) = TagLoggerMetadata(tag)
+}
diff --git a/subprojects/logger/sentry-logger/src/main/kotlin/com/avito/logger/destination/SentryLoggingHandlerProvider.kt b/subprojects/logger/sentry-logger/src/main/kotlin/com/avito/logger/destination/SentryLoggingHandlerProvider.kt
index 38ebd3cc54..b3a3c3e9a2 100644
--- a/subprojects/logger/sentry-logger/src/main/kotlin/com/avito/logger/destination/SentryLoggingHandlerProvider.kt
+++ b/subprojects/logger/sentry-logger/src/main/kotlin/com/avito/logger/destination/SentryLoggingHandlerProvider.kt
@@ -1,9 +1,9 @@
package com.avito.logger.destination
import com.avito.logger.LogLevel
-import com.avito.logger.LoggerMetadata
import com.avito.logger.handler.LoggingHandler
import com.avito.logger.handler.LoggingHandlerProvider
+import com.avito.logger.metadata.LoggerMetadata
import io.sentry.SentryClient
public class SentryLoggingHandlerProvider(
diff --git a/subprojects/test-runner/test-inhouse-runner/src/main/kotlin/com/avito/android/log/AndroidTestLoggerMetadataProvider.kt b/subprojects/test-runner/test-inhouse-runner/src/main/kotlin/com/avito/android/log/AndroidTestLoggerMetadataProvider.kt
index 7b263280bf..239a4ffc01 100644
--- a/subprojects/test-runner/test-inhouse-runner/src/main/kotlin/com/avito/android/log/AndroidTestLoggerMetadataProvider.kt
+++ b/subprojects/test-runner/test-inhouse-runner/src/main/kotlin/com/avito/android/log/AndroidTestLoggerMetadataProvider.kt
@@ -1,7 +1,7 @@
package com.avito.android.log
-import com.avito.logger.LoggerMetadata
-import com.avito.logger.LoggerMetadataProvider
+import com.avito.logger.metadata.LoggerMetadata
+import com.avito.logger.metadata.LoggerMetadataProvider
class AndroidTestLoggerMetadataProvider(
private val testName: String
diff --git a/subprojects/test-runner/test-inhouse-runner/src/main/kotlin/com/avito/android/log/AndroidTestMetadata.kt b/subprojects/test-runner/test-inhouse-runner/src/main/kotlin/com/avito/android/log/AndroidTestMetadata.kt
index 9a46eb02ca..19d19497ed 100644
--- a/subprojects/test-runner/test-inhouse-runner/src/main/kotlin/com/avito/android/log/AndroidTestMetadata.kt
+++ b/subprojects/test-runner/test-inhouse-runner/src/main/kotlin/com/avito/android/log/AndroidTestMetadata.kt
@@ -1,13 +1,14 @@
package com.avito.android.log
-import com.avito.logger.LoggerMetadata
+import com.avito.logger.metadata.LoggerMetadata
-internal data class AndroidTestMetadata(
- override val tag: String,
- val testName: String
+internal class AndroidTestMetadata(
+ private val tag: String,
+ private val testName: String
) : LoggerMetadata {
- override fun asString(): String = tag
+ override val asMessagePrefix: String = "[$tag]"
+
override fun asMap(): Map {
return mapOf(
"tag" to tag,