-
Notifications
You must be signed in to change notification settings - Fork 331
Expand file tree
/
Copy pathLogInjectionSmokeTest.groovy
More file actions
881 lines (738 loc) · 30.4 KB
/
LogInjectionSmokeTest.groovy
File metadata and controls
881 lines (738 loc) · 30.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
package datadog.smoketest
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import datadog.environment.JavaVirtualMachine
import datadog.trace.agent.test.server.http.TestHttpServer.HandlerApi.RequestApi
import datadog.trace.api.config.GeneralConfig
import datadog.trace.test.util.Flaky
import java.nio.charset.StandardCharsets
import java.util.zip.GZIPInputStream
import spock.lang.AutoCleanup
import spock.lang.Shared
import static datadog.trace.api.config.TraceInstrumentationConfig.TRACE_128_BIT_TRACEID_LOGGING_ENABLED
import static datadog.trace.api.config.TracerConfig.TRACE_128_BIT_TRACEID_GENERATION_ENABLED
import static java.util.concurrent.TimeUnit.SECONDS
/**
* Each smoketest application is expected to log four lines to the log file:
* - BEFORE FIRST SPAN
* - INSIDE FIRST SPAN
* - AFTER FIRST SPAN
* - INSIDE SECOND SPAN
*
* Additional, each application prints to std out:
* FIRSTTRACEID TRACEID SPANID
* SECONDTRACEID TRACEID SPANID
*/
abstract class LogInjectionSmokeTest extends AbstractSmokeTest {
// Estimate for the amount of time instrumentation, plus request, plus some extra
static final int TIMEOUT_SECS = 30
static final String LOG4J2_BACKEND = "Log4j2"
@Shared
File outputLogFile
@Shared
File outputJsonLogFile
def jsonAdapter = new Moshi.Builder().build().adapter(Types.newParameterizedType(Map, String, Object))
@Shared
boolean noTags = false
@Shared
boolean trace128bits = true
@Shared
boolean appLogCollection = false
@Shared
@AutoCleanup
MockBackend mockBackend = new MockBackend()
def setup() {
mockBackend.reset()
}
@Override
ProcessBuilder createProcessBuilder() {
def jarName = getClass().simpleName
noTags = jarName.endsWith("NoTags")
if (noTags) {
jarName = jarName.substring(0, jarName.length() - 6)
}
trace128bits = jarName.endsWith("128bTid")
if (trace128bits) {
jarName = jarName.substring(0, jarName.length() - 7)
}
appLogCollection = jarName.endsWith("AppLogCollection")
if (appLogCollection) {
jarName = jarName.substring(0, jarName.length() - "AppLogCollection".length())
}
def loggingJar = buildDirectory + "/libs/" + jarName + ".jar"
assert new File(loggingJar).isFile()
outputLogFile = File.createTempFile("logTest", ".log")
outputJsonLogFile = File.createTempFile("logTest", ".log")
List<String> command = new ArrayList<>()
command.add(javaPath())
command.addAll(defaultJavaProperties)
// turn off these features as their debug output can break up our expected logging lines on IBM JVMs
// causing random test failures (we are not testing these features here so they don't need to be on)
command.add("-Ddd.instrumentation.telemetry.enabled=false")
command.removeAll {
it.startsWith("-Ddd.profiling")
}
command.add("-Ddd.profiling.enabled=false")
command.add("-Ddd.remote_config.enabled=true")
command.add("-Ddd.remote_config.url=http://localhost:${server.address.port}/v0.7/config".toString())
command.add("-Ddd.remote_config.poll_interval.seconds=0.2")
command.add("-Ddd.trace.flush.interval=0.3")
command.add("-Ddd.test.logfile=${outputLogFile.absolutePath}" as String)
command.add("-Ddd.test.jsonlogfile=${outputJsonLogFile.absolutePath}" as String)
if (noTags) {
command.add("-Ddd.env=" as String)
command.add("-Ddd.version=" as String)
command.add("-Ddd.service.name=" as String)
}
if (!trace128bits) {
command.add("-Ddd.$TRACE_128_BIT_TRACEID_GENERATION_ENABLED=false" as String)
command.add("-Ddd.$TRACE_128_BIT_TRACEID_LOGGING_ENABLED=false" as String)
}
if (supportsDirectLogSubmission()) {
command.add("-Ddd.$GeneralConfig.AGENTLESS_LOG_SUBMISSION_ENABLED=true" as String)
command.add("-Ddd.$GeneralConfig.AGENTLESS_LOG_SUBMISSION_URL=${mockBackend.intakeUrl}" as String)
}
if (supportsAppLogCollection()) {
command.add("-Ddd.$GeneralConfig.APP_LOGS_COLLECTION_ENABLED=true" as String)
}
command.addAll(additionalArguments())
command.addAll((String[]) ["-jar", loggingJar])
println "COMMANDS: " + command.join(" ")
ProcessBuilder processBuilder = new ProcessBuilder(command)
processBuilder.directory(new File(buildDirectory))
return processBuilder
}
@Override
boolean isErrorLog(String log) {
// Exclude some errors that we consistently get because of the logging setups used here:
if (log.contains('no applicable action for [immediateFlush]')) {
return false
}
if (log.contains('JSONLayout contains an invalid element or attribute')) {
return false
}
if (log.contains('JSONLayout has no parameter that matches element')) {
return false
}
return super.isErrorLog(log)
}
@Override
def logLevel() {
return "debug"
}
@Override
Closure decodedEvpProxyMessageCallback() {
return {
String path, RequestApi request ->
try {
boolean isCompressed = request.getHeader("Content-Encoding").contains("gzip")
byte[] body = request.body
if (body != null) {
if (isCompressed) {
ByteArrayOutputStream output = new ByteArrayOutputStream()
byte[] buffer = new byte[4096]
try (GZIPInputStream input = new GZIPInputStream(new ByteArrayInputStream(body))) {
int bytesRead = input.read(buffer, 0, buffer.length)
output.write(buffer, 0, bytesRead)
}
body = output.toByteArray()
}
final strBody = new String(body, StandardCharsets.UTF_8)
println("evp mesg: " + strBody)
final jsonAdapter = new Moshi.Builder().build().adapter(Types.newParameterizedType(List, Types.newParameterizedType(Map, String, Object)))
List<Map<String, Object>> msg = jsonAdapter.fromJson(strBody)
msg
}
} catch (Throwable t) {
println("=== Failure during EvP proxy decoding ===")
t.printStackTrace(System.out)
throw t
}
}
}
List additionalArguments() {
return []
}
def injectsRawLogs() {
return true
}
def supportsJson() {
return true
}
def supportsDirectLogSubmission() {
return backend() == LOG4J2_BACKEND
}
def supportsAppLogCollection() {
false
}
abstract backend()
def cleanupSpec() {
outputLogFile?.delete()
outputJsonLogFile?.delete()
}
def assertRawLogLinesWithoutInjection(List<String> logLines, String firstTraceId, String firstSpanId, String secondTraceId, String secondSpanId,
String thirdTraceId, String thirdSpanId, String forthTraceId, String forthSpanId) {
// Assert log line starts with backend name.
// This avoids tests inadvertently passing because the incorrect backend is logging
logLines.every {
it.startsWith(backend())
}
assert logLines.size() == 7
assert logLines[0].endsWith("- BEFORE FIRST SPAN")
assert logLines[1].endsWith("- INSIDE FIRST SPAN")
assert logLines[2].endsWith("- AFTER FIRST SPAN")
assert logLines[3].endsWith("- INSIDE SECOND SPAN")
assert logLines[4].endsWith("- INSIDE THIRD SPAN")
assert logLines[5].endsWith("- INSIDE FORTH SPAN")
assert logLines[6].endsWith("- AFTER FORTH SPAN")
return true
}
def assertRawLogLinesWithInjection(List<String> logLines, String firstTraceId, String firstSpanId, String secondTraceId, String secondSpanId,
String thirdTraceId, String thirdSpanId, String forthTraceId, String forthSpanId) {
// Assert log line starts with backend name.
// This avoids tests inadvertently passing because the incorrect backend is logging
logLines.every {
it.startsWith(backend())
}
def tagsPart = noTags ? " " : "${SERVICE_NAME} ${ENV} ${VERSION}"
assert logLines.size() == 7
assert logLines[0].endsWith("- ${tagsPart} - BEFORE FIRST SPAN") || logLines[0].endsWith("- ${tagsPart} 0 0 - BEFORE FIRST SPAN")
assert logLines[1].endsWith("- ${tagsPart} ${firstTraceId} ${firstSpanId} - INSIDE FIRST SPAN")
assert logLines[2].endsWith("- ${tagsPart} - AFTER FIRST SPAN") || logLines[2].endsWith("- ${tagsPart} 0 0 - AFTER FIRST SPAN")
assert logLines[3].endsWith("- ${tagsPart} ${secondTraceId} ${secondSpanId} - INSIDE SECOND SPAN")
assert logLines[4].endsWith("- - INSIDE THIRD SPAN") || logLines[4].endsWith("- 0 0 - INSIDE THIRD SPAN")
assert logLines[5].endsWith("- ${tagsPart} ${forthTraceId} ${forthSpanId} - INSIDE FORTH SPAN")
assert logLines[6].endsWith("- ${tagsPart} - AFTER FORTH SPAN") || logLines[6].endsWith("- ${tagsPart} 0 0 - AFTER FORTH SPAN")
return true
}
def assertJsonLinesWithInjection(List<String> rawLines, String firstTraceId, String firstSpanId, String secondTraceId, String secondSpanId,
String thirdTraceId, String thirdSpanId, String forthTraceId, String forthSpanId) {
def logLines = rawLines.collect {
println it; jsonAdapter.fromJson(it) as Map
}
assert logLines.size() == 7
// Log4j2's KeyValuePair for injecting static values into Json only exists in later versions of Log4j2
// Its tested with Log4j2LatestBackend
if (!getClass().simpleName.contains("Log4j2Backend")) {
assert logLines.every {
it["backend"] == backend()
}
}
return assertParsedJsonLinesWithInjection(logLines, firstTraceId, firstSpanId, secondTraceId, secondSpanId, forthTraceId, forthSpanId)
}
private assertParsedJsonLinesWithInjection(List<Map> logLines, String firstTraceId, String firstSpanId, String secondTraceId, String secondSpanId, String forthTraceId, String forthSpanId) {
assert logLines.every {
getFromContext(it, "dd.service") == noTags ? null : SERVICE_NAME
}
assert logLines.every {
getFromContext(it, "dd.version") == noTags ? null : VERSION
}
assert logLines.every {
getFromContext(it, "dd.env") == noTags ? null : ENV
}
assert getFromContext(logLines[0], "dd.trace_id") == null
assert getFromContext(logLines[0], "dd.span_id") == null
assert logLines[0]["message"] == "BEFORE FIRST SPAN"
assert getFromContext(logLines[1], "dd.trace_id") == firstTraceId
assert getFromContext(logLines[1], "dd.span_id") == firstSpanId
assert logLines[1]["message"] == "INSIDE FIRST SPAN"
assert getFromContext(logLines[2], "dd.trace_id") == null
assert getFromContext(logLines[2], "dd.span_id") == null
assert logLines[2]["message"] == "AFTER FIRST SPAN"
assert getFromContext(logLines[3], "dd.trace_id") == secondTraceId
assert getFromContext(logLines[3], "dd.span_id") == secondSpanId
assert logLines[3]["message"] == "INSIDE SECOND SPAN"
assert getFromContext(logLines[4], "dd.trace_id") == null
assert getFromContext(logLines[4], "dd.span_id") == null
assert logLines[4]["message"] == "INSIDE THIRD SPAN"
assert getFromContext(logLines[5], "dd.trace_id") == forthTraceId
assert getFromContext(logLines[5], "dd.span_id") == forthSpanId
assert logLines[5]["message"] == "INSIDE FORTH SPAN"
assert getFromContext(logLines[6], "dd.trace_id") == null
assert getFromContext(logLines[6], "dd.span_id") == null
assert logLines[6]["message"] == "AFTER FORTH SPAN"
return true
}
private assertParsedJsonLinesWithAppLogCollection(List<Map> logLines, String firstTraceId, String firstSpanId, String secondTraceId, String secondSpanId, String thirdTraceId, String thirdSpanId, String forthTraceId, String forthSpanId) {
assert logLines.every {
getFromContext(it, "dd.service") == noTags ? null : SERVICE_NAME
}
assert logLines.every {
getFromContext(it, "dd.version") == noTags ? null : VERSION
}
assert logLines.every {
getFromContext(it, "dd.env") == noTags ? null : ENV
}
assert getFromContext(logLines[0], "dd.trace_id") == null
assert getFromContext(logLines[0], "dd.span_id") == null
assert logLines[0]["message"] == "BEFORE FIRST SPAN"
assert getFromContext(logLines[1], "dd.trace_id") == firstTraceId
assert getFromContext(logLines[1], "dd.span_id") == firstSpanId
assert logLines[1]["message"] == "INSIDE FIRST SPAN"
assert getFromContext(logLines[2], "dd.trace_id") == null
assert getFromContext(logLines[2], "dd.span_id") == null
assert logLines[2]["message"] == "AFTER FIRST SPAN"
assert getFromContext(logLines[3], "dd.trace_id") == secondTraceId
assert getFromContext(logLines[3], "dd.span_id") == secondSpanId
assert logLines[3]["message"] == "INSIDE SECOND SPAN"
assert getFromContext(logLines[4], "dd.trace_id") == thirdTraceId
assert getFromContext(logLines[4], "dd.span_id") == thirdSpanId
assert logLines[4]["message"] == "INSIDE THIRD SPAN"
assert getFromContext(logLines[5], "dd.trace_id") == forthTraceId
assert getFromContext(logLines[5], "dd.span_id") == forthSpanId
assert logLines[5]["message"] == "INSIDE FORTH SPAN"
assert getFromContext(logLines[6], "dd.trace_id") == null
assert getFromContext(logLines[6], "dd.span_id") == null
assert logLines[6]["message"] == "AFTER FORTH SPAN"
return true
}
def getFromContext(Map logEvent, String key) {
if (logEvent["contextMap"] != null) {
return logEvent["contextMap"][key]
}
return logEvent[key]
}
/**
* Like {@link AbstractSmokeTest#waitForTraceCount} but checks process liveness on every poll
* iteration and dumps diagnostic state on failure, so CI failures produce actionable output
* instead of a bare "Condition not satisfied" after a 30s timeout.
*/
int waitForTraceCountAlive(int count) {
try {
defaultPoll.eventually {
if (traceDecodingFailure != null) {
throw traceDecodingFailure
}
// Check the count BEFORE liveness — the process may have exited normally
// after delivering all traces, and we don't want to treat that as a failure.
if (traceCount.get() >= count) {
return
}
if (testedProcess != null && !testedProcess.isAlive()) {
def lastLines = tailProcessLog(20)
// RuntimeException (not AssertionError) so PollingConditions propagates
// immediately instead of retrying for the full timeout.
throw new RuntimeException(
"Process exited with code ${testedProcess.exitValue()} while waiting for ${count} traces " +
"(received ${traceCount.get()}, RC polls: ${rcClientMessages.size()}).\n" +
"Last process output:\n${lastLines}")
}
assert traceCount.get() >= count
}
} catch (AssertionError e) {
// The default error ("Condition not satisfied after 30s") is useless — enrich with diagnostic state
def alive = testedProcess?.isAlive()
def lastLines = tailProcessLog(30)
throw new AssertionError(
"Timed out waiting for ${count} traces after ${defaultPoll.timeout}s. " +
"traceCount=${traceCount.get()}, process.alive=${alive}, " +
"RC polls received: ${rcClientMessages.size()}.\n" +
"Last process output:\n${lastLines}", e)
}
traceCount.get()
}
private String tailProcessLog(int lines) {
try {
def logFile = new File(logFilePath)
if (!logFile.exists()) return "(log file does not exist: ${logFilePath})"
def allLines = logFile.readLines()
def tail = allLines.size() > lines ? allLines[-lines..-1] : allLines
return tail.join("\n")
} catch (Exception e) {
return "(failed to read log: ${e.message})"
}
}
def parseTraceFromStdOut( String line ) {
if (line == null) {
throw new IllegalArgumentException("Line is null")
}
// there's a race with stdout where lines get combined
// this fixes that
def lineStart = line.indexOf("TRACEID")
def startOfNextLine = line.indexOf("[", lineStart)
def lineEnd = startOfNextLine == -1 ? line.length() : startOfNextLine
def unmangled = line.substring(lineStart, lineEnd)
return unmangled.split(" ")[1..2]
}
@Flaky(condition = () -> JavaVirtualMachine.isIbm8() || JavaVirtualMachine.isOracleJDK8())
def "check raw file injection"() {
when:
def count = waitForTraceCountAlive(2)
def newConfig = """
{"lib_config":
{"log_injection_enabled":false}
}
""".toString()
setRemoteConfig("datadog/2/APM_TRACING/config_overrides/config", newConfig)
count = waitForTraceCountAlive(3)
setRemoteConfig("datadog/2/APM_TRACING/config_overrides/config", """{"lib_config":{}}""".toString())
// Wait for all 4 traces before waiting for process exit to ensure trace delivery is confirmed
count = waitForTraceCountAlive(4)
assert testedProcess.waitFor(TIMEOUT_SECS, SECONDS) : "Process did not exit within ${TIMEOUT_SECS}s"
def exitValue = testedProcess.exitValue()
def logLines = outputLogFile.readLines()
println "log lines: " + logLines
def jsonLogLines = outputJsonLogFile.readLines()
println "json log lines: " + jsonLogLines
def stdOutLines = new File(logFilePath).readLines()
def (String firstTraceId, String firstSpanId) = parseTraceFromStdOut(stdOutLines.find {
it.contains("FIRSTTRACEID")
})
def (String secondTraceId, String secondSpanId) = parseTraceFromStdOut(stdOutLines.find {
it.contains("SECONDTRACEID")
})
def (String thirdTraceId, String thirdSpanId) = parseTraceFromStdOut(stdOutLines.find {
it.contains("THIRDTRACEID")
})
def (String forthTraceId, String forthSpanId) = parseTraceFromStdOut(stdOutLines.find {
it.contains("FORTHTRACEID")
})
then:
exitValue == 0
count == 4
firstTraceId && firstTraceId != "0"
checkTraceIdFormat(firstTraceId)
firstSpanId && firstSpanId != "0"
secondTraceId && secondTraceId != "0"
checkTraceIdFormat(secondTraceId)
secondSpanId && secondSpanId != "0"
thirdTraceId && thirdTraceId != "0"
checkTraceIdFormat(thirdTraceId)
thirdSpanId && thirdSpanId != "0"
forthTraceId && forthTraceId != "0"
checkTraceIdFormat(forthTraceId)
forthSpanId && forthSpanId != "0"
if (injectsRawLogs()) {
assertRawLogLinesWithInjection(logLines, firstTraceId, firstSpanId, secondTraceId, secondSpanId, thirdTraceId, thirdSpanId, forthTraceId, forthSpanId)
} else {
assertRawLogLinesWithoutInjection(logLines, firstTraceId, firstSpanId, secondTraceId, secondSpanId, thirdTraceId, thirdSpanId, forthTraceId, forthSpanId)
}
if (supportsJson()) {
assertJsonLinesWithInjection(jsonLogLines, firstTraceId, firstSpanId, secondTraceId, secondSpanId, thirdTraceId, thirdSpanId, forthTraceId, forthSpanId)
}
if (supportsDirectLogSubmission()) {
assertParsedJsonLinesWithInjection(mockBackend.waitForLogs(7), firstTraceId, firstSpanId, secondTraceId, secondSpanId, forthTraceId, forthSpanId)
}
if (supportsAppLogCollection()) {
def lines = evpProxyMessages.collect {
it.v2
}.flatten() as List<Map<String, Object>>
assertParsedJsonLinesWithAppLogCollection(lines, firstTraceId, firstSpanId, secondTraceId, secondSpanId, thirdTraceId, thirdSpanId, forthTraceId, forthSpanId)
}
}
void checkTraceIdFormat(String traceId) {
if (trace128bits) {
assert traceId.matches("[0-9a-z]{32}")
} else {
assert traceId.matches("\\d+")
}
}
}
abstract class JULBackend extends LogInjectionSmokeTest {
@Shared
def propertiesFile = File.createTempFile("julConfig", ".properties")
def backend() {
"JUL"
}
def injectsRawLogs() {
false
}
def supportsJson() {
false
}
def setupSpec() {
def isWindows = System.getProperty("os.name").toLowerCase().contains("win")
def outputLogFilePath = outputLogFile.absolutePath
if (isWindows) {
// FileHandler pattern only uses / as path delimiter
outputLogFilePath = outputLogFilePath.replace("\\", "/")
}
// JUL doesn't support reading a properties file from the classpath so everything needs
// to be specified in a temp file
propertiesFile.withPrintWriter {
it.println ".level=INFO"
it.println "handlers=java.util.logging.FileHandler"
it.println "java.util.logging.FileHandler.pattern=${outputLogFilePath}"
it.println "java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter"
it.println "java.util.logging.SimpleFormatter.format=JUL:%1\$tF %1\$tT [%4\$-7s] - %5\$s%n"
}
}
def cleanupSpec() {
propertiesFile?.delete()
}
List additionalArguments() {
return ["-Djava.util.logging.config.file=${propertiesFile.absolutePath}" as String]
}
}
class JULInterfaceJULBackend extends JULBackend {
}
class JULInterfaceLog4j2Backend extends LogInjectionSmokeTest {
def backend() {
LOG4J2_BACKEND
}
List additionalArguments() {
return ["-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager"]
}
}
class JULInterfaceLog4j2BackendNoTags extends JULInterfaceLog4j2Backend {}
class JULInterfaceLog4j2Backend128bTid extends JULInterfaceLog4j2Backend {}
class JULInterfaceLog4j2LatestBackend extends JULInterfaceLog4j2Backend {}
class JULInterfaceJBossBackend extends LogInjectionSmokeTest {
def backend() {
"JBoss"
}
def supportsJson() {
false
}
List additionalArguments() {
return ["-Djava.util.logging.manager=org.jboss.logmanager.LogManager"]
}
}
class JULInterfaceJBossBackendNoTags extends JULInterfaceJBossBackend {}
class JULInterfaceJBossBackend128bTid extends JULInterfaceJBossBackend {}
class JULInterfaceJBossLatestBackend extends JULInterfaceJBossBackend {}
class JCLInterfaceJULBackend extends JULBackend {
def backend() {
"JUL"
}
}
class JCLInterfaceLog4j1Backend extends LogInjectionSmokeTest {
def backend() {
"Log4j1"
}
def supportsJson() {
false
}
}
class JCLInterfaceLog4j1BackendNoTags extends JCLInterfaceLog4j1Backend {}
class JCLInterfaceLog4j1LatestBackend extends JCLInterfaceLog4j1Backend {}
class JCLInterfaceLog4j1Backend128bTid extends JCLInterfaceLog4j1Backend {}
class JCLInterfaceLog4j2Backend extends LogInjectionSmokeTest {
def backend() {
LOG4J2_BACKEND
}
// workaround https://github.com/apache/logging-log4j2/issues/1865
List additionalArguments() {
return ['-Dorg.apache.commons.logging.LogFactory=org.apache.logging.log4j.jcl.LogFactoryImpl' as String]
}
}
class JCLInterfaceLog4j2BackendNoTags extends JCLInterfaceLog4j2Backend {}
class JCLInterfaceLog4j2Backend128bTid extends JCLInterfaceLog4j2Backend {}
class JCLInterfaceLog4j2LatestBackend extends JCLInterfaceLog4j2Backend {}
class Log4j1InterfaceLog4j1Backend extends LogInjectionSmokeTest {
def backend() {
"Log4j1"
}
def supportsJson() {
false
}
}
class Log4j1InterfaceLog4j1BackendNoTags extends Log4j1InterfaceLog4j1Backend {}
class Log4j1InterfaceLog4j1Backend128bTid extends Log4j1InterfaceLog4j1Backend {}
class Log4j1InterfaceLog4j1LatestBackend extends Log4j1InterfaceLog4j1Backend {}
class Log4j1InterfaceLog4j2Backend extends LogInjectionSmokeTest {
def backend() {
LOG4J2_BACKEND
}
}
class Log4j1InterfaceLog4j2BackendNoTags extends Log4j1InterfaceLog4j2Backend {}
class Log4j1InterfaceLog4j2Backend128bTid extends Log4j1InterfaceLog4j2Backend {}
class Log4j1InterfaceLog4j2LatestBackend extends Log4j1InterfaceLog4j2Backend {}
class Log4j2InterfaceLog4j2Backend extends LogInjectionSmokeTest {
def backend() {
LOG4J2_BACKEND
}
}
class Log4j2InterfaceLog4j2BackendNoTags extends Log4j2InterfaceLog4j2Backend {}
class Log4j2InterfaceLog4j2Backend128bTid extends Log4j2InterfaceLog4j2Backend {}
class Log4j2InterfaceLog4j2LatestBackend extends Log4j2InterfaceLog4j2Backend {}
class Slf4jInterfaceLogbackBackend extends LogInjectionSmokeTest {
def backend() {
"Logback"
}
}
class Slf4jInterfaceLogbackBackendAppLogCollection extends Slf4jInterfaceLogbackBackend {
@Override
def supportsDirectLogSubmission() {
false
}
@Override
def supportsAppLogCollection() {
true
}
}
class Slf4jInterfaceLogbackBackendNoTags extends Slf4jInterfaceLogbackBackend {}
class Slf4jInterfaceLogbackBackend128bTid extends Slf4jInterfaceLogbackBackend {}
class Slf4jInterfaceLogbackLatestBackend extends Slf4jInterfaceLogbackBackend {}
class Slf4jInterfaceLog4j1Backend extends LogInjectionSmokeTest {
def backend() {
"Log4j1"
}
def supportsJson() {
false
}
}
class Slf4jInterfaceLog4j1BackendNoTags extends Slf4jInterfaceLog4j1Backend {}
class Slf4jInterfaceLog4j1Backend128bTid extends Slf4jInterfaceLog4j1Backend {}
class Slf4jInterfaceLog4j1LatestBackend extends Slf4jInterfaceLog4j1Backend {}
class Slf4jInterfaceLog4j2Backend extends LogInjectionSmokeTest {
def backend() {
LOG4J2_BACKEND
}
}
class Slf4jInterfaceLog4j2BackendNoTags extends Slf4jInterfaceLog4j2Backend {}
class Slf4jInterfaceLog4j2Backend128bTid extends Slf4jInterfaceLog4j2Backend {}
class Slf4jInterfaceLog4j2LatestBackend extends Slf4jInterfaceLog4j2Backend {}
class Slf4jInterfaceLog4j2BackendAppLogCollection extends Slf4jInterfaceLog4j2Backend {
@Override
def supportsDirectLogSubmission() {
false
}
@Override
def supportsAppLogCollection() {
true
}
}
class Slf4jInterfaceSlf4jSimpleBackend extends LogInjectionSmokeTest {
def backend() {
"Slf4jSimple"
}
def injectsRawLogs() {
false
}
def supportsJson() {
false
}
List additionalArguments() {
return ["-Dorg.slf4j.simpleLogger.logFile=${outputLogFile.absolutePath}" as String]
}
}
class Slf4jInterfaceJULBackend extends JULBackend {
}
class Slf4jInterfaceJCLToLog4j1Backend extends LogInjectionSmokeTest {
def backend() {
"Log4j1"
}
def supportsJson() {
false
}
}
class Slf4jInterfaceJCLToLog4j1BackendNoTags extends Slf4jInterfaceJCLToLog4j1Backend {}
class Slf4jInterfaceJCLToLog4j1Backend128bTid extends Slf4jInterfaceJCLToLog4j1Backend {}
class Slf4jInterfaceJCLToLog4j1LatestBackend extends Slf4jInterfaceJCLToLog4j1Backend {}
class Slf4jInterfaceJCLToLog4j2Backend extends LogInjectionSmokeTest {
def backend() {
LOG4J2_BACKEND
}
// workaround https://github.com/apache/logging-log4j2/issues/1865
List additionalArguments() {
return ['-Dorg.apache.commons.logging.LogFactory=org.apache.logging.log4j.jcl.LogFactoryImpl' as String]
}
}
class Slf4jInterfaceJCLToLog4j2BackendNoTags extends Slf4jInterfaceJCLToLog4j2Backend {}
class Slf4jInterfaceJCLToLog4j2Backend128bTid extends Slf4jInterfaceJCLToLog4j2Backend {}
class Slf4jInterfaceJCLToLog4j2LatestBackend extends Slf4jInterfaceJCLToLog4j2Backend {}
class JULInterfaceSlf4jToLogbackBackend extends LogInjectionSmokeTest {
@Shared
def propertiesFile = File.createTempFile("julConfig", ".properties")
def backend() {
"Logback"
}
def setupSpec() {
// JUL doesn't support reading a properties file from the classpath so everything needs
// to be specified in a temp file
propertiesFile.withPrintWriter {
it.println ".level=INFO"
it.println "handlers=org.slf4j.bridge.SLF4JBridgeHandler"
}
}
def cleanupSpec() {
propertiesFile?.delete()
}
List additionalArguments() {
return ["-Djava.util.logging.config.file=${propertiesFile.absolutePath}" as String]
}
}
class JULInterfaceSlf4jToLogbackBackendNoTags extends JULInterfaceSlf4jToLogbackBackend {}
class JULInterfaceSlf4jToLogbackBackend128bTid extends JULInterfaceSlf4jToLogbackBackend {}
class JULInterfaceSlf4jToLogbackLatestBackend extends JULInterfaceSlf4jToLogbackBackend {}
class JCLInterfaceSlf4jToLogbackBackend extends LogInjectionSmokeTest {
def backend() {
"Logback"
}
}
class JCLInterfaceSlf4jToLogbackBackendNoTags extends JCLInterfaceSlf4jToLogbackBackend {}
class JCLInterfaceSlf4jToLogbackBackend128bTid extends JCLInterfaceSlf4jToLogbackBackend {}
class JCLInterfaceSlf4jToLogbackLatestBackend extends JCLInterfaceSlf4jToLogbackBackend {}
class Log4j1InterfaceSlf4jToLogbackBackend extends LogInjectionSmokeTest {
def backend() {
"Logback"
}
}
class Log4j1InterfaceSlf4jToLogbackBackendNoTags extends Log4j1InterfaceSlf4jToLogbackBackend {}
class Log4j1InterfaceSlf4jToLogbackBackend128bTid extends Log4j1InterfaceSlf4jToLogbackBackend {}
class Log4j1InterfaceSlf4jToLogbackLatestBackend extends Log4j1InterfaceSlf4jToLogbackBackend {}
class Log4j2InterfaceSlf4jToLogbackBackend extends LogInjectionSmokeTest {
def backend() {
"Logback"
}
}
class Log4j2InterfaceSlf4jToLogbackBackendNoTags extends Log4j2InterfaceSlf4jToLogbackBackend {}
class Log4j2InterfaceSlf4jToLogbackBackend128bTid extends Log4j2InterfaceSlf4jToLogbackBackend {}
class Log4j2InterfaceSlf4jToLogbackLatestBackend extends Log4j2InterfaceSlf4jToLogbackBackend {}
class JBossInterfaceJBossBackend extends LogInjectionSmokeTest {
def backend() {
"JBoss"
}
def supportsJson() {
false
}
List additionalArguments() {
return ["-Djava.util.logging.manager=org.jboss.logmanager.LogManager"]
}
}
class JBossInterfaceJBossBackendNoTags extends JBossInterfaceJBossBackend {}
class JBossInterfaceJBossBackend128bTid extends JBossInterfaceJBossBackend {}
class JBossInterfaceJBossLatestBackend extends JBossInterfaceJBossBackend {}
class JBossInterfaceLog4j1Backend extends LogInjectionSmokeTest {
def backend() {
"Log4j1"
}
def supportsJson() {
false
}
}
class JBossInterfaceLog4j1BackendNoTags extends JBossInterfaceLog4j1Backend {}
class JBossInterfaceLog4j1Backend128bTid extends JBossInterfaceLog4j1Backend {}
class JBossInterfaceLog4j1LatestBackend extends JBossInterfaceLog4j1Backend {}
class JBossInterfaceLog4j2Backend extends LogInjectionSmokeTest {
def backend() {
LOG4J2_BACKEND
}
}
class JBossInterfaceLog4j2BackendNoTags extends JBossInterfaceLog4j2Backend {}
class JBossInterfaceLog4j2Backend128bTid extends JBossInterfaceLog4j2Backend {}
class JBossInterfaceLog4j2LatestBackend extends JBossInterfaceLog4j2Backend {}
class JBossInterfaceSlf4jToLogbackBackend extends LogInjectionSmokeTest {
def backend() {
"Logback"
}
}
class JBossInterfaceSlf4jToLogbackBackendNoTags extends JBossInterfaceSlf4jToLogbackBackend {}
class JBossInterfaceSlf4jToLogbackBackend128bTid extends JBossInterfaceSlf4jToLogbackBackend {}
class JBossInterfaceSlf4jToLogbackLatestBackend extends JBossInterfaceSlf4jToLogbackBackend {}
class JBossInterfaceJULBackend extends JULBackend {}
class FloggerInterfaceJULBackend extends JULBackend {}
class FloggerInterfaceSlf4jToLogbackBackend extends LogInjectionSmokeTest {
def backend() {
"Logback"
}
List additionalArguments() {
return [
"-Dflogger.backend_factory=com.google.common.flogger.backend.slf4j.Slf4jBackendFactory#getInstance"
]
}
}
class FloggerInterfaceSlf4jToLogbackBackendNoTags extends FloggerInterfaceSlf4jToLogbackBackend {}
class FloggerInterfaceSlf4jToLogbackBackend128bTid extends FloggerInterfaceSlf4jToLogbackBackend {}
class FloggerInterfaceSlf4jToLogbackLatestBackend extends FloggerInterfaceSlf4jToLogbackBackend {}