Skip to content

Commit 128401c

Browse files
author
Hussein Habibi Juybari
committed
Refactor LogTap module and introduce logging utilities
- Move classes to specific subpackages: interceptor, logger, websocket, utils. - Add LogTapInterceptor and LoggingWebSocket classes for enhanced logging. - Introduce newWebSocketWithLogging extension function for WebSocket logging. - Implement utility functions for logging at various levels (verbose, debug, info, warning, error). - Update LogTap.kt with synchronized methods and default constructor for Config. - Modify build.gradle.kts to include LogTap-Noop dependency.
1 parent ea7ebd0 commit 128401c

19 files changed

Lines changed: 2271 additions & 84 deletions

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ All notable changes to this project will be documented in this file.
33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
44
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

6+
### v0.7.0
7+
Refactor LogTap-Noop module and update UI resources
8+
9+
This commit refactors the LogTap-Noop module by:
10+
- Moving classes to more specific subpackages (interceptor, logger, websocket, utils).
11+
- Adding `LogTapInterceptor` and `LoggingWebSocket` classes.
12+
- Introducing `newWebSocketWithLogging` extension function and `LoggingWebSocketListener`.
13+
- Adding UI resources (HTML, CSS, JS) for the LogTap web interface.
14+
- Updating `LogTap.kt` with synchronized methods and a default constructor for `Config`.
15+
- Adding utility functions `isDebuggable`, `logV`, `logD`, `logI`, `logW`, and `logE`.
16+
- Deleting old classes: `LogTapInterceptor`, `LogTapLogcatBridge`, `LogTapLogger`, `LogTapSink`, `LogTapSinkAdapter`, and `WsLogging`.
17+
- Updating the app's build.gradle.kts to use LogTap-Noop.
18+
619
### v0.6.0
720
Refactor LogTap for improved modularity and WebSocket logging
821

LogTap-Noop/src/main/java/com/github/husseinhj/logtap/LogTap.kt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ package com.github.husseinhj.logtap
33
import android.content.Context
44

55
object LogTap {
6-
fun start(context: Context, config: Config) {}
7-
fun stop() {}
8-
fun isRunning(): Boolean = false
6+
data class Config(
7+
val port: Int = 8790,
8+
val capacity: Int = 5000,
9+
val maxBodyBytes: Long = 64_000,
10+
val redactHeaders: Set<String> = setOf("Authorization","Cookie","Set-Cookie"),
11+
val enableOnRelease: Boolean = false
12+
)
913

10-
data class Config(
11-
val port: Int = 8790,
12-
val capacity: Int = 5000,
13-
val maxBodyBytes: Long = 64_000,
14-
val redactHeaders: Set<String> = setOf("Authorization","Cookie","Set-Cookie"),
15-
val enableOnRelease: Boolean = false
16-
)
14+
@Synchronized
15+
fun start(context: Context, config: Config = Config()) {}
16+
17+
@Suppress("unused")
18+
@Synchronized
19+
fun stop() {}
1720
}

LogTap-Noop/src/main/java/com/github/husseinhj/logtap/LogTapInterceptor.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

LogTap-Noop/src/main/java/com/github/husseinhj/logtap/LogTapLogcatBridge.kt

Lines changed: 0 additions & 26 deletions
This file was deleted.

LogTap-Noop/src/main/java/com/github/husseinhj/logtap/LogTapLogger.kt

Lines changed: 0 additions & 16 deletions
This file was deleted.

LogTap-Noop/src/main/java/com/github/husseinhj/logtap/LogTapSink.kt

Lines changed: 0 additions & 6 deletions
This file was deleted.

LogTap-Noop/src/main/java/com/github/husseinhj/logtap/LogTapSinkAdapter.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.

LogTap-Noop/src/main/java/com/github/husseinhj/logtap/WsLogging.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.github.husseinhj.logtap.interceptor
2+
3+
import okhttp3.*
4+
5+
/**
6+
* An OkHttp interceptor that logs HTTP requests and responses to LogTap.
7+
*
8+
* ### Example usage:
9+
* ```kotlin
10+
* val client = OkHttpClient.Builder()
11+
* .addInterceptor(LogTapInterceptor())
12+
* .build()
13+
* ```
14+
*
15+
* This interceptor captures request and response details, including headers and bodies (up to a configured limit),
16+
* while redacting sensitive headers. It handles various edge cases like streaming bodies, WebSocket upgrades,
17+
* and gzip-encoded responses.
18+
*/
19+
class LogTapInterceptor : Interceptor {
20+
override fun intercept(chain: Interceptor.Chain): Response {
21+
return chain.proceed(chain.request())
22+
}
23+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.github.husseinhj.logtap.logger
2+
3+
import kotlinx.coroutines.Dispatchers
4+
import kotlinx.coroutines.SupervisorJob
5+
import kotlinx.coroutines.CoroutineScope
6+
7+
/**
8+
* Collects this process's Logcat lines (any android.util.Log usage by your app & libs)
9+
* and forwards them to the provided sink.
10+
*
11+
* No READ_LOGS permission required (own PID only).
12+
*/
13+
object LogTapLogcatBridge {
14+
15+
/** Your hook to send a log event into LogTap. */
16+
interface Sink {
17+
fun onLog(priority: Char, tag: String, message: String, threadId: Int?, time: String?)
18+
}
19+
20+
/**
21+
* Start tailing logcat for **this** PID.
22+
* @param sink your receiver that forwards to your in-memory queue / WebSocket / server
23+
*/
24+
fun start(sink: Sink, scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)) {}
25+
26+
fun stop() {}
27+
}

0 commit comments

Comments
 (0)