Skip to content

Commit ffdf610

Browse files
feat: silent user output (#167)
1 parent f1b6a84 commit ffdf610

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,15 @@ buildConfig {
4242
// Logging.
4343
buildConfigField 'String', 'ENV', project.hasProperty('env') ? env : 'production'
4444
buildConfigField 'String', 'LOG_LEVEL', project.hasProperty('log') ? log : 'info'
45+
buildConfigField 'boolean', 'SILENT_USER_OUTPUT', project.hasProperty('silent') ? silent : 'false'
46+
buildConfigField 'String', 'SENTRY_DSN', 'https://0263d6473bd24a9ba40e25aa5fb0a242:[email protected]/233260'
47+
buildConfigField 'boolean', 'PRINT_STACK_TRACE', 'false'
4548

4649
// Google Analytics.
4750
buildConfigField 'String', 'GA_BASE_PATH', 'http://www.google-analytics.com'
4851
buildConfigField 'String', 'GA_TRACKING_ID', 'UA-107129190-2'
4952
buildConfigField 'boolean', 'IS_GA_ENABLED', 'true'
5053

51-
// Logging.
52-
buildConfigField 'String', 'SENTRY_DSN', 'https://0263d6473bd24a9ba40e25aa5fb0a242:[email protected]/233260'
53-
buildConfigField 'boolean', 'PRINT_STACK_TRACE', 'false'
54-
5554
// Models storage path.
5655
buildConfigField 'String', 'LIBRARY_MODELS_URL', 'https://storage.googleapis.com/sourcerer-app/library-models/v1/'
5756

src/main/kotlin/app/Logger.kt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ object Logger {
6161
@kotlin.PublishedApi
6262
internal const val TRACE = 4
6363

64+
const val SILENT = BuildConfig.SILENT_USER_OUTPUT
65+
6466
/**
6567
* Print stack trace on error log.
6668
*/
@@ -112,24 +114,30 @@ object Logger {
112114
* CLI messages and pretty printing.
113115
*/
114116
fun print(message: Any, indentLine: Boolean = false) {
115-
print(message.toString(), indentLine)
117+
if (!SILENT) {
118+
print(message.toString(), indentLine)
119+
}
116120
}
117121

118122
fun print(message: String, indentLine: Boolean = false) {
119-
if (indentLine) {
120-
println()
123+
if (!SILENT) {
124+
if (indentLine) {
125+
println()
126+
}
127+
println(message)
121128
}
122-
println(message)
123129
}
124130

125131
fun printCommit(commitMessage: String, commitHash: String,
126132
percents: Double) {
127-
val percentsStr = percents.format(6, 2)
128-
val hash = commitHash.substring(0, 7)
129-
val messageTrim = if (commitMessage.length > 59) {
130-
commitMessage.substring(0, 56).plus("...")
131-
} else commitMessage
132-
println(" [$percentsStr%] * $hash $messageTrim")
133+
if (!SILENT) {
134+
val percentsStr = percents.format(6, 2)
135+
val hash = commitHash.substring(0, 7)
136+
val messageTrim = if (commitMessage.length > 59) {
137+
commitMessage.substring(0, 56).plus("...")
138+
} else commitMessage
139+
println(" [$percentsStr%] * $hash $messageTrim")
140+
}
133141
}
134142

135143
private val commitDetailIndent = generateIndent(10) + "|" +

0 commit comments

Comments
 (0)