-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Logger and refine existing logs
- Introduces a new Logger class with configurable log levels to provide enhanced logging control. - Refine existing logs within TestDataUploader for improved clarity. - Add more meaningful logs around upload error.
- Loading branch information
1 parent
1b67873
commit 3a27e55
Showing
2 changed files
with
73 additions
and
19 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
48 changes: 48 additions & 0 deletions
48
...or/test-data-uploader/src/main/kotlin/com/buildkite/test/collector/android/util/Logger.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,48 @@ | ||
package com.buildkite.test.collector.android.util | ||
|
||
/** | ||
* Provides logging functionality with configurable log level sensitivity. | ||
* | ||
* @property minLevel The minimum log level that will be logged. | ||
*/ | ||
class Logger( | ||
private val minLevel: LogLevel = LogLevel.INFO | ||
) { | ||
/** | ||
* Logs a message at [LogLevel.DEBUG]. | ||
* - Messages are logged only if [LogLevel.DEBUG] is greater than or equal to [minLevel]. | ||
*/ | ||
fun debug(message: () -> String) = log(LogLevel.DEBUG, message) | ||
|
||
/** | ||
* Logs a message at [LogLevel.INFO]. | ||
* - Messages are logged only if [LogLevel.INFO] is greater than or equal to [minLevel]. | ||
*/ | ||
fun info(message: () -> String) = log(LogLevel.INFO, message) | ||
|
||
/** | ||
* Logs a message at [LogLevel.ERROR]. | ||
* - Messages are logged only if [LogLevel.ERROR] is greater than or equal to [minLevel]. | ||
*/ | ||
fun error(message: () -> String) = log(LogLevel.ERROR, message) | ||
|
||
/** | ||
* Conditionally logs messages based on the [minLevel] set. | ||
* - Logs to standard output for [LogLevel.DEBUG] and [LogLevel.INFO], and to standard error for [LogLevel.ERROR]. | ||
*/ | ||
private fun log(level: LogLevel, message: () -> String) { | ||
if (level >= minLevel) { | ||
val output = if (level == LogLevel.ERROR) System.err else System.out | ||
output.println("\nBuildkiteTestCollector-${level.name}: ${message()}") | ||
} | ||
} | ||
|
||
/** | ||
* Defines the log levels, ordered from least to most severe. | ||
*/ | ||
enum class LogLevel { | ||
DEBUG, | ||
INFO, | ||
ERROR | ||
} | ||
} |