Skip to content

Commit e2c7916

Browse files
Merge pull request #6 from cookpad/revert-5-add_logtype_builder
Revert "Add logType method to PureeLogger"
2 parents 434b616 + 0eba5a8 commit e2c7916

File tree

4 files changed

+75
-79
lines changed

4 files changed

+75
-79
lines changed

demo/src/main/java/com/cookpad/puree/kotlin/demo/DemoApp.kt

+5-9
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,19 @@ class DemoApp : Application() {
4141
)
4242
.filter(
4343
AddTimeFilter(),
44-
ClickLog::class.java, MenuLog::class.java
44+
ClickLog::class.java, MenuLog::class.java, PeriodicLog::class.java
4545
)
4646
.output(
4747
LogcatOutput(),
48-
ClickLog::class.java, MenuLog::class.java
48+
ClickLog::class.java, MenuLog::class.java, PeriodicLog::class.java
4949
)
5050
.output(
5151
LogcatDebugBufferedOutput("logcat_debug"),
5252
ClickLog::class.java, MenuLog::class.java
5353
)
54-
.logType(
55-
logType = PeriodicLog::class.java,
56-
filters = listOf(AddTimeFilter()),
57-
outputs = listOf(
58-
LogcatOutput(),
59-
PurgeableLogcatWarningBufferedOutput("logcat_warning")
60-
)
54+
.output(
55+
PurgeableLogcatWarningBufferedOutput("logcat_warning"),
56+
PeriodicLog::class.java
6157
)
6258
.build()
6359
}

gradle/publishing.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apply plugin: 'signing'
44
ext.publication = [:]
55
ext.publication.version = [
66
'major': '1',
7-
'minor': '3',
7+
'minor': '4',
88
'patch': '0',
99
]
1010
ext.publication.versionName = "${publication.version.major}.${publication.version.minor}.${publication.version.patch}"

puree/src/main/java/com/cookpad/puree/kotlin/PureeLogger.kt

+4-23
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ class PureeLogger private constructor(
5252
private val registeredLogs: Map<Class<out PureeLog>, Configuration>,
5353
private val bufferedOutputs: List<PureeBufferedOutput>
5454
) {
55-
private val scope: CoroutineScope =
56-
CoroutineScope(dispatcher + CoroutineExceptionHandler { _, throwable ->
57-
Log.e(TAG, "Exception thrown", throwable)
58-
})
55+
private val scope: CoroutineScope = CoroutineScope(dispatcher + CoroutineExceptionHandler { _, throwable ->
56+
Log.e(TAG, "Exception thrown", throwable)
57+
})
5958
private var isResumed: Boolean = false
6059

6160
init {
@@ -226,7 +225,7 @@ class PureeLogger private constructor(
226225
* [PureeOutput] should be registered and duplicates are ignored.
227226
* @param logTypes The log types of the objects that will be sent to the [PureeOutput].
228227
*/
229-
fun output(output: PureeOutput, vararg logTypes: Class<out PureeLog>): Builder {
228+
fun output(output: PureeOutput,vararg logTypes: Class<out PureeLog>): Builder {
230229
if (output is PureeBufferedOutput) {
231230
if (output.uniqueId in outputIds) {
232231
throw IllegalArgumentException("Cannot register another PureeBufferedOutput with uniqueId: ${output.uniqueId}.")
@@ -243,24 +242,6 @@ class PureeLogger private constructor(
243242
return this
244243
}
245244

246-
/**
247-
* Registers a log type and associate it with [PureeFilter] and [PureeOutput].
248-
*
249-
* @param logType The log type to be registered.
250-
* @param filters The [PureeFilter]s to use for the log type.
251-
* @param outputs The [PureeOutput]s that will emit this log type.
252-
*/
253-
fun logType(
254-
logType: Class<out PureeLog>,
255-
filters: List<PureeFilter>,
256-
outputs: List<PureeOutput>
257-
): Builder {
258-
filters.forEach { filter(it, logType) }
259-
outputs.forEach { output(it, logType) }
260-
261-
return this
262-
}
263-
264245
/**
265246
* Builds a [PureeLogger] object.
266247
*

puree/src/sharedTest/java/com/cookpad/puree/kotlin/PureeLoggerIntegrationTest.kt

+65-46
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,17 @@ class PureeLoggerIntegrationTest {
5858
).apply {
5959
dispatcher = coroutineDispatcher
6060
clock = this@FilterTests.clock
61-
logType(
62-
logType = SampleLog::class.java,
63-
filters = listOf(object : PureeFilter {
61+
filter(
62+
object : PureeFilter {
6463
override fun applyFilter(log: JSONObject): JSONObject = log.apply {
6564
put("filter1", "test_value")
6665
}
67-
}),
68-
outputs = listOf(output)
66+
},
67+
SampleLog::class.java
68+
)
69+
output(
70+
output,
71+
SampleLog::class.java
6972
)
7073
}.build()
7174

@@ -133,21 +136,25 @@ class PureeLoggerIntegrationTest {
133136
).apply {
134137
dispatcher = coroutineDispatcher
135138
clock = this@FilterTests.clock
136-
logType(
137-
logType = SampleLog::class.java,
138-
filters = listOf(
139-
object : PureeFilter {
140-
override fun applyFilter(log: JSONObject): JSONObject = log.apply {
141-
put("filter1", "test_value")
142-
}
143-
},
144-
object : PureeFilter {
145-
override fun applyFilter(log: JSONObject): JSONObject = log.apply {
146-
put("filter2", "test_value")
147-
}
139+
filter(
140+
object : PureeFilter {
141+
override fun applyFilter(log: JSONObject): JSONObject = log.apply {
142+
put("filter1", "test_value")
143+
}
144+
},
145+
SampleLog::class.java
146+
)
147+
filter(
148+
object : PureeFilter {
149+
override fun applyFilter(log: JSONObject): JSONObject = log.apply {
150+
put("filter2", "test_value")
148151
}
149-
),
150-
outputs = listOf(output)
152+
},
153+
SampleLog::class.java
154+
)
155+
output(
156+
output,
157+
SampleLog::class.java
151158
)
152159
}.build()
153160

@@ -176,22 +183,25 @@ class PureeLoggerIntegrationTest {
176183
).apply {
177184
dispatcher = coroutineDispatcher
178185
clock = this@FilterTests.clock
179-
logType(
180-
logType = SampleLog::class.java,
181-
filters = listOf(
182-
object : PureeFilter {
183-
override fun applyFilter(log: JSONObject): JSONObject = log.apply {
184-
put("filter1", "test_value")
185-
}
186-
},
187-
object : PureeFilter {
188-
override fun applyFilter(log: JSONObject): JSONObject =
189-
JSONObject().apply {
190-
put("filter2", "test_value")
191-
}
186+
filter(
187+
object : PureeFilter {
188+
override fun applyFilter(log: JSONObject): JSONObject = log.apply {
189+
put("filter1", "test_value")
190+
}
191+
},
192+
SampleLog::class.java
193+
)
194+
filter(
195+
object : PureeFilter {
196+
override fun applyFilter(log: JSONObject): JSONObject = JSONObject().apply {
197+
put("filter2", "test_value")
192198
}
193-
),
194-
outputs = listOf(output)
199+
},
200+
SampleLog::class.java
201+
)
202+
output(
203+
output,
204+
SampleLog::class.java
195205
)
196206
}.build()
197207

@@ -241,10 +251,13 @@ class PureeLoggerIntegrationTest {
241251
).apply {
242252
dispatcher = coroutineDispatcher
243253
clock = this@OutputTests.clock
244-
logType(
245-
logType = SampleLog::class.java,
246-
filters = emptyList(),
247-
outputs = listOf(output1, output2)
254+
output(
255+
output1,
256+
SampleLog::class.java
257+
)
258+
output(
259+
output2,
260+
SampleLog::class.java
248261
)
249262
}.build()
250263

@@ -302,10 +315,13 @@ class PureeLoggerIntegrationTest {
302315
).apply {
303316
dispatcher = coroutineDispatcher
304317
clock = this@OutputTests.clock
305-
logType(
306-
logType = SampleLog::class.java,
307-
filters = emptyList(),
308-
outputs = listOf(outputEvery1s, outputEvery2s)
318+
output(
319+
outputEvery1s,
320+
SampleLog::class.java
321+
)
322+
output(
323+
outputEvery2s,
324+
SampleLog::class.java
309325
)
310326
}.build()
311327

@@ -353,10 +369,13 @@ class PureeLoggerIntegrationTest {
353369
).apply {
354370
dispatcher = coroutineDispatcher
355371
clock = this@OutputTests.clock
356-
logType(
357-
logType = SampleLog::class.java,
358-
filters = emptyList(),
359-
outputs = listOf(outputEvery5s, outputEvery10s)
372+
output(
373+
outputEvery5s,
374+
SampleLog::class.java
375+
)
376+
output(
377+
outputEvery10s,
378+
SampleLog::class.java
360379
)
361380
}.build()
362381

0 commit comments

Comments
 (0)