Skip to content

Commit 56d94fb

Browse files
committed
v2.0: coroutine pipeline + pluggable sinks (file/logcat/http), MDC, DSL, AGP 9 toolchain
1 parent 6b2a76a commit 56d94fb

75 files changed

Lines changed: 5390 additions & 4126 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master, main]
6+
pull_request:
7+
branches: [master, main]
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
build:
16+
name: Build and test
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 30
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Set up JDK 17
25+
uses: actions/setup-java@v4
26+
with:
27+
distribution: temurin
28+
java-version: '17'
29+
30+
- name: Set up Gradle
31+
uses: gradle/actions/setup-gradle@v4
32+
with:
33+
cache-read-only: ${{ github.event_name == 'pull_request' }}
34+
35+
- name: Validate Gradle wrapper
36+
uses: gradle/actions/wrapper-validation@v4
37+
38+
- name: Assemble :filelogger
39+
run: ./gradlew :filelogger:assembleRelease --stacktrace
40+
41+
- name: Assemble :filelogger-okhttp
42+
run: ./gradlew :filelogger-okhttp:assembleRelease --stacktrace
43+
44+
- name: Assemble :app (debug)
45+
run: ./gradlew :app:assembleDebug --stacktrace
46+
47+
- name: Compile androidTest sources
48+
run: ./gradlew :app:assembleDebugAndroidTest --stacktrace
49+
50+
- name: Unit tests
51+
run: ./gradlew :filelogger:test --stacktrace
52+
53+
- name: Upload unit test reports
54+
if: always()
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: unit-test-reports
58+
path: |
59+
filelogger/build/reports/tests/
60+
filelogger/build/test-results/
61+
retention-days: 14
62+
63+
- name: Upload library AARs
64+
if: success()
65+
uses: actions/upload-artifact@v4
66+
with:
67+
name: aars
68+
path: |
69+
filelogger/build/outputs/aar/*.aar
70+
filelogger-okhttp/build/outputs/aar/*.aar
71+
retention-days: 14

ARCHITECTURE.md

Lines changed: 329 additions & 0 deletions
Large diffs are not rendered by default.

LOCAL_USAGE.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Using FileLogger locally in another Android app
2+
3+
This repo is **not published to Maven (local or remote) or JitPack**. The two ways to consume it from another local Android project on the same machine are below. Pick one.
4+
5+
---
6+
7+
## Option A — Gradle composite build (recommended for development)
8+
9+
Best when you want to iterate on FileLogger and the consumer app together: changes in this repo show up in the consumer immediately, no rebuild step in the middle.
10+
11+
In the **consumer app's** `settings.gradle` (or `settings.gradle.kts`), add `includeBuild`:
12+
13+
```gradle
14+
pluginManagement {
15+
repositories {
16+
google()
17+
mavenCentral()
18+
gradlePluginPortal()
19+
}
20+
}
21+
dependencyResolutionManagement {
22+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
23+
repositories {
24+
google()
25+
mavenCentral()
26+
}
27+
}
28+
includeBuild('/home/abolfazl/code/FileLogger') {
29+
dependencySubstitution {
30+
substitute module('com.github.aabolfazl:filelogger') using project(':filelogger')
31+
substitute module('com.github.aabolfazl:filelogger-okhttp') using project(':filelogger-okhttp')
32+
}
33+
}
34+
rootProject.name = "your-consumer-app"
35+
include ':app'
36+
```
37+
38+
In the consumer's `app/build.gradle`:
39+
40+
```gradle
41+
dependencies {
42+
implementation 'com.github.aabolfazl:filelogger:2.0.0'
43+
// optional:
44+
implementation 'com.github.aabolfazl:filelogger-okhttp:2.0.0'
45+
}
46+
```
47+
48+
Sync the consumer project. Gradle resolves the substitutions to the local sources. Edit FileLogger code → rebuild the consumer → changes flow through.
49+
50+
**Caveats:**
51+
- Both projects must use compatible AGP/Kotlin versions. FileLogger is on **AGP 9.2.0 / Kotlin 2.2.10 / Gradle 9.4.1**.
52+
- Consumer's `compileSdk` ≥ 36 (FileLogger's compile SDK).
53+
- Consumer's `minSdk` ≥ 26 (FileLogger uses `java.time` natively — no `coreLibraryDesugaring` needed).
54+
- Consumer's `JavaVersion.targetCompatibility` ≥ 11 (FileLogger emits JVM 11 bytecode).
55+
56+
---
57+
58+
## Option B — Drop the AAR into the consumer's `libs/` folder
59+
60+
Best when you want a frozen snapshot of FileLogger and don't plan to edit it.
61+
62+
### Build the AAR
63+
64+
In this repo:
65+
66+
```bash
67+
./gradlew :filelogger:assembleRelease
68+
./gradlew :filelogger-okhttp:assembleRelease # optional
69+
```
70+
71+
The artifacts land at:
72+
73+
- `filelogger/build/outputs/aar/filelogger-release.aar`
74+
- `filelogger-okhttp/build/outputs/aar/filelogger-okhttp-release.aar`
75+
76+
### Wire into the consumer
77+
78+
Copy the AAR(s) into `app/libs/` of the consumer project. Then in the consumer's `app/build.gradle`:
79+
80+
```gradle
81+
android {
82+
// ...
83+
compileSdk 36
84+
defaultConfig { minSdk 26 }
85+
compileOptions {
86+
sourceCompatibility JavaVersion.VERSION_11
87+
targetCompatibility JavaVersion.VERSION_11
88+
}
89+
}
90+
91+
dependencies {
92+
implementation files('libs/filelogger-release.aar')
93+
implementation files('libs/filelogger-okhttp-release.aar') // optional
94+
95+
// FileLogger's runtime dependencies must be declared here too —
96+
// AAR consumers don't get transitive dependencies via flat-file deps.
97+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1'
98+
implementation 'androidx.startup:startup-runtime:1.1.1'
99+
implementation 'androidx.lifecycle:lifecycle-process:2.8.7'
100+
implementation 'androidx.core:core-ktx:1.13.1'
101+
102+
// Required if you use :filelogger-okhttp:
103+
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
104+
}
105+
```
106+
107+
**Caveats:**
108+
- The consumer must declare every runtime transitive dep manually (the AAR-via-`files()` route doesn't carry POM metadata).
109+
- Updates to FileLogger require rebuilding the AAR and re-copying.
110+
- `consumer-rules.pro` from the AAR is honored — your release build's R8/ProGuard will still see the library's keep rules.
111+
112+
---
113+
114+
## Verifying the wire-up
115+
116+
In the consumer's `Application.onCreate` (or anywhere on the main thread):
117+
118+
```kotlin
119+
val config = fileLogger(applicationContext.filesDir.absolutePath) {
120+
defaultTag = "Consumer"
121+
minLevel = LogLevel.Debug
122+
}
123+
FileLogger.init(applicationContext, config)
124+
FileLogger.i(message = "FileLogger wired up")
125+
```
126+
127+
Run the app, then on the device:
128+
129+
```bash
130+
adb shell run-as <your.consumer.package> ls files/fileLogs/
131+
adb shell run-as <your.consumer.package> cat files/fileLogs/$(adb shell run-as <your.consumer.package> ls files/fileLogs/ | head -1)
132+
```
133+
134+
You should see a log file with the `FileLogger wired up` line.

0 commit comments

Comments
 (0)