Skip to content

Commit ca9304b

Browse files
author
ihsanbal
committed
log printer line fixes
1 parent b91193c commit ca9304b

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ allprojects {
3737
}
3838
3939
dependencies {
40-
implementation('com.github.ihsanbal:LoggingInterceptor:3.1.0-rc4') {
40+
implementation('com.github.ihsanbal:LoggingInterceptor:3.1.0-rc5') {
4141
exclude group: 'org.json', module: 'json'
4242
}
4343
}
@@ -53,7 +53,7 @@ Maven:
5353
<dependency>
5454
<groupId>com.github.ihsanbal</groupId>
5555
<artifactId>LoggingInterceptor</artifactId>
56-
<version>3.1.0-rc4</version>
56+
<version>3.1.0-rc5</version>
5757
</dependency>
5858
```
5959

lib/src/main/java/com/ihsanbal/logging/Printer.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import java.nio.charset.StandardCharsets
1717
/**
1818
* @author ihsan on 09/02/2017.
1919
*/
20-
open class Printer protected constructor() {
20+
class Printer private constructor() {
2121
companion object {
2222
private const val JSON_INDENT = 3
2323
private val LINE_SEPARATOR = System.getProperty("line.separator")
@@ -40,7 +40,9 @@ open class Printer protected constructor() {
4040
}
4141

4242
fun printJsonRequest(builder: LoggingInterceptor.Builder, body: RequestBody?, url: String, header: Headers, method: String) {
43-
val requestBody = LINE_SEPARATOR + BODY_TAG + LINE_SEPARATOR + bodyToString(body, header)
43+
val requestBody = body?.let {
44+
LINE_SEPARATOR + BODY_TAG + LINE_SEPARATOR + bodyToString(body, header)
45+
} ?: ""
4446
val tag = builder.getTag(true)
4547
if (builder.logger == null) I.log(builder.type, tag, REQUEST_UP_LINE, builder.isLogHackEnable)
4648
logLines(builder.type, tag, arrayOf(URL_TAG + url), builder.logger, false, builder.isLogHackEnable)
@@ -77,7 +79,7 @@ open class Printer protected constructor() {
7779
val headers = response.headers
7880
val contentLength = responseBody.contentLength()
7981
if (!response.promisesBody()) {
80-
return "End request - Promoses Body"
82+
return "End request - Promises Body"
8183
} else if (bodyHasUnknownEncoding(response.headers)) {
8284
return "encoded body omitted"
8385
} else {
@@ -151,7 +153,7 @@ open class Printer protected constructor() {
151153
headers.forEach { pair ->
152154
builder.append("${pair.first}: ${pair.second}").append(N)
153155
}
154-
return builder.toString()
156+
return builder.dropLast(1).toString()
155157
}
156158

157159
private fun logLines(type: Int, tag: String, lines: Array<String>, logger: Logger?,
@@ -203,7 +205,7 @@ open class Printer protected constructor() {
203205
} catch (e: IOException) {
204206
"{\"err\": \"" + e.message + "\"}"
205207
}
206-
} ?: "{\"err\": \"$requestBody\"}"
208+
} ?: ""
207209
}
208210

209211
private fun bodyHasUnknownEncoding(headers: Headers): Boolean {

0 commit comments

Comments
 (0)