-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avito.logging.verbose property (#923)
* new avito.logging.verbose property to override local console output log levels for out plugins * use println (quiet level in gradle) * add stacktrace print control, extract VerboseDestination
- Loading branch information
Showing
4 changed files
with
143 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...ts/common/slf4j-logger/src/main/kotlin/com/avito/logger/destination/VerboseDestination.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.avito.logger.destination | ||
|
||
import com.avito.logger.LogLevel | ||
import com.avito.logger.LoggingDestination | ||
|
||
data class VerboseMode( | ||
val verbosity: LogLevel, | ||
val printStackTrace: Boolean | ||
) | ||
|
||
/** | ||
* See Logging.md#Verbose-mode | ||
*/ | ||
class VerboseDestination(private val verboseMode: VerboseMode) : LoggingDestination { | ||
|
||
private val verbosity = verboseMode.verbosity | ||
|
||
override fun write(level: LogLevel, message: String, throwable: Throwable?) { | ||
when (level) { | ||
LogLevel.DEBUG -> if (verbosity == LogLevel.DEBUG) { | ||
print(message, throwable) | ||
} | ||
LogLevel.INFO -> if (verbosity == LogLevel.DEBUG || verbosity == LogLevel.INFO) { | ||
print(message, throwable) | ||
} | ||
LogLevel.WARNING -> if (verbosity == LogLevel.DEBUG | ||
|| verbosity == LogLevel.INFO | ||
|| verbosity == LogLevel.WARNING | ||
) { | ||
print(message, throwable) | ||
} | ||
LogLevel.CRITICAL -> print(message, throwable) | ||
} | ||
} | ||
|
||
private fun print(message: String, throwable: Throwable?) { | ||
println(message) | ||
if (verboseMode.printStackTrace) { | ||
throwable?.printStackTrace() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters