File: LoggerFinderBackendTest.java

package info (click to toggle)
openjdk-11 11.0.4%2B11-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 757,028 kB
  • sloc: java: 5,016,041; xml: 1,191,974; cpp: 934,731; ansic: 555,697; sh: 24,299; objc: 12,703; python: 3,602; asm: 3,415; makefile: 2,772; awk: 351; sed: 172; perl: 114; jsp: 24; csh: 3
file content (2317 lines) | stat: -rw-r--r-- 107,838 bytes parent folder | download | duplicates (17)
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
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
/*
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

/**
 * @test
 * @bug     8140364
 * @author  danielfuchs
 * @summary  JDK implementation specific unit test for JDK internal artifacts.
 *           This test tests all the public API methods defined in the {@link
 *           java.lang.System.Logger} interface, as well as all the JDK
 *           internal methods defined in the
 *           {@link sun.util.logging.PlatformLogger.Bridge}
 *           interface, with loggers returned by  {@link
 *           java.lang.System.LoggerFinder#getLogger(java.lang.String, java.lang.Class)}
 *           and {@link java.lang.System.LoggerFinder#getLocalizedLogger(java.lang.String,
 *           java.util.ResourceBundle, java.lang.Class)}
 *           (using both a null resource bundle and a non null resource bundle).
 *           It calls both the {@link java.lang.System} factory methods and
 *           {@link jdk.internal.logger.LazyLoggers} to obtains those loggers,
 *           and configure them with all possible known levels.
 * @modules java.base/java.lang:open
 *          java.base/sun.util.logging
 *          java.base/jdk.internal.logger
 *          java.logging/sun.util.logging.internal
 * @build LoggerFinderBackendTest SystemClassLoader
 * @run  main/othervm -Djava.system.class.loader=SystemClassLoader -Dtest.logger.hidesProvider=true LoggerFinderBackendTest
 * @run  main/othervm -Djava.system.class.loader=SystemClassLoader -Dtest.logger.hidesProvider=false LoggerFinderBackendTest
 */


import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.MethodType;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiFunction;
import java.util.function.BooleanSupplier;
import java.util.function.Function;
import java.util.function.Supplier;
import java.lang.System.LoggerFinder;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import sun.util.logging.PlatformLogger.Level;
import java.util.logging.LogManager;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import sun.util.logging.internal.LoggingProviderImpl;

/**
 * @author danielfuchs
 */
public class LoggerFinderBackendTest {

    // whether the implementation of Logger try to do a best
    // effort for logp... If the provider is not hidden, then
    // the logp() implementation comes from LoggerWrapper - which does a
    // best effort. Otherwise, it comes from the default provider
    // which does support logp.
    static final boolean BEST_EFFORT_FOR_LOGP =
            !Boolean.getBoolean("test.logger.hidesProvider");
    static final boolean VERBOSE = false;

    static final Class<java.lang.System.Logger> spiLoggerClass =
            java.lang.System.Logger.class;
    static final Class<java.lang.System.Logger> jdkLoggerClass =
            java.lang.System.Logger.class;
    static final Class<sun.util.logging.PlatformLogger.Bridge> bridgeLoggerClass =
            sun.util.logging.PlatformLogger.Bridge.class;

    /** Use to retrieve the log records that were produced by the JUL backend */
    static class LoggerTesterHandler extends Handler {
        public final List<LogRecord> records =
                Collections.synchronizedList(new ArrayList<>());

        @Override
        public void publish(LogRecord record) {
            record.getSourceClassName(); record.getSourceMethodName();
            records.add(record);
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
            records.clear();
        }

        public void reset() {
            records.clear();
        }
    }

    /** The {@link LoggerTesterHandler} handler is added to the root logger. */
    static final LoggerTesterHandler handler = new LoggerTesterHandler();
    static {
        for (Handler h : Logger.getLogger("").getHandlers()) {
            if (h instanceof ConsoleHandler) {
                Logger.getLogger("").removeHandler(h);
            }
        }
        Logger.getLogger("").addHandler(handler);
    }

    /**
     * A resource handler parameter that will be used when calling out the
     * logrb-like methods - as well as when calling the level-specific
     * methods that take a ResourceBundle parameter.
     */
    public static class ResourceBundeParam extends ResourceBundle {
        Map<String, String> map = Collections.synchronizedMap(new LinkedHashMap<>());
        @Override
        protected Object handleGetObject(String key) {
            map.putIfAbsent(key, "${"+key+"}");
            return map.get(key);
        }

        @Override
        public Enumeration<String> getKeys() {
            return Collections.enumeration(new LinkedHashSet<>(map.keySet()));
        }

    }

    final static ResourceBundle bundleParam =
            ResourceBundle.getBundle(ResourceBundeParam.class.getName());

    /**
     * A resource handler parameter that will be used when creating localized
     * loggers by calling {@link
     * LoggerFinder#getLocalizedLogger(java.lang.String, java.util.ResourceBundle, java.lang.Class)}.
     */
    public static class ResourceBundeLocalized extends ResourceBundle {
        Map<String, String> map = Collections.synchronizedMap(new LinkedHashMap<>());
        @Override
        protected Object handleGetObject(String key) {
            map.putIfAbsent(key, "Localized:${"+key+"}");
            return map.get(key);
        }

        @Override
        public Enumeration<String> getKeys() {
            return Collections.enumeration(new LinkedHashSet<>(map.keySet()));
        }

    }

    /**
     * The Levels enum is used to call all the level-specific methods on
     * a logger instance. To minimize the amount of code it uses reflection
     * to do so.
     */
    static Lookup lookup = MethodHandles.lookup();
    public enum Levels {
        /** Used to call all forms of Logger.log?(SEVERE, ...) */
        SEVERE("severe", bridgeLoggerClass, Level.SEVERE, null, "error", false),
        /** Used to call all forms of Logger.log?(WARNING,...) */
        WARNING("warning", bridgeLoggerClass, Level.WARNING, "warning", "warning", false),
        /** Used to call all forms of Logger.log?(INFO,...) */
        INFO("info", bridgeLoggerClass, Level.INFO, "info", "info", false),
        /** Used to call all forms of Logger.log?(CONFIG,...) */
        CONFIG("config", bridgeLoggerClass, Level.CONFIG, null, "debug", false),
        /** Used to call all forms of Logger.log?(FINE,...) */
        FINE("fine", bridgeLoggerClass, Level.FINE, null, "debug", false),
        /** Used to call all forms of Logger.log?(FINER,...) */
        FINER("finer", bridgeLoggerClass, Level.FINER, null, "trace", false),
        /** Used to call all forms of Logger.log?(FINEST,...) */
        FINEST("finest", bridgeLoggerClass, Level.FINEST, null, "trace", false),
        ;
        public final String method;  // The name of the level-specific method to call
        public final Class<?> definingClass; // which interface j.u.logger.Logger or j.u.logging.spi.Logger defines it
        public final Level platformLevel; // The platform Level it will be mapped to in Jul when Jul is the backend
        public final String jdkExtensionToJUL; // The name of the method called on the JUL logger when JUL is the backend
        public final String julToJdkExtension; // The name of the method called in the jdk extension by the default impl in jdk.internal.logging.Logger
        public final String enableMethod; // The name of the isXxxxEnabled method
        public final boolean hasSpecificIsEnabled;
        Levels(String method, Class<?> definingClass, Level defaultMapping,
                String jdkExtensionToJUL, String julToJdkExtension,
                boolean hasSpecificIsEnabled) {
            this.method = method;
            this.definingClass = definingClass;
            this.platformLevel = defaultMapping;
            this.jdkExtensionToJUL = jdkExtensionToJUL;
            this.julToJdkExtension = julToJdkExtension;
            this.hasSpecificIsEnabled = hasSpecificIsEnabled;
            if (hasSpecificIsEnabled) {
                this.enableMethod = "is" + method.substring(0,1).toUpperCase()
                    + method.substring(1) + "Enabled";
            } else {
                this.enableMethod = "isLoggable";
            }
        }

        /*
         * calls this level specific method - e.g. if this==INFO: logger.info(msg);
         */
        public void level(Object logger, String msg) {
            MethodType mt = MethodType.methodType(void.class, Level.class, String.class);
            invoke("log", logger, mt, platformLevel, msg);
        }

        /*
         * calls this level specific method - e.g. if this==INFO: logger.info(msgSupplier);
         */
        public void level(Object logger, Supplier<String> msgSupplier) {
            MethodType mt = MethodType.methodType(void.class,  Level.class, Supplier.class);
            invoke("log", logger, mt, platformLevel, msgSupplier);
        }

        /*
         * calls this level specific method - e.g. if this==INFO: logger.info(msg, params);
         */
        public void level(Object logger, String msg, Object... params) {
            MethodType mt = MethodType.methodType(void.class,  Level.class, String.class,
                    Object[].class);
            invoke("log", logger, mt, platformLevel, msg, params);
        }

        /*
         * calls this level specific method - e.g. if this==INFO: logger.info(msg, thrown);
         */
        public void level(Object logger, String msg, Throwable thrown) {
            MethodType mt = MethodType.methodType(void.class,  Level.class, String.class,
                    Throwable.class);
            invoke("log", logger, mt, platformLevel, msg, thrown);
        }

        /*
         * calls this level specific method - e.g. if this==INFO: logger.info(msgSupplier, thrown);
         */
        public void level(Object logger, Supplier<String> msgSupplier, Throwable thrown) {
            MethodType mt = MethodType.methodType(void.class,  Level.class,
                     Throwable.class, Supplier.class);
            invoke("log", logger, mt, platformLevel, thrown, msgSupplier);
        }

        /*
         * calls this level specific method - e.g. if this==INFO: logger.info(bundle, msg);
         */
        public void level(Object logger, String msg, ResourceBundle bundle) {
            MethodType mt = MethodType.methodType(void.class, Level.class,
                    ResourceBundle.class, String.class, Object[].class);
            invoke("logrb", logger, mt, platformLevel, bundle, msg, null);
        }

        public void level(Object logger, String msg, ResourceBundle bundle,
                Object... params) {
            MethodType mt = MethodType.methodType(void.class, Level.class,
                    ResourceBundle.class, String.class, Object[].class);
            invoke("logrb", logger, mt, platformLevel, bundle, msg, params);
        }

        public void level(Object logger, String msg, ResourceBundle bundle,
                Throwable thrown) {
            MethodType mt = MethodType.methodType(void.class, Level.class,
                    ResourceBundle.class, String.class, Throwable.class);
            invoke("logrb", logger, mt, platformLevel, bundle, msg, thrown);
        }

        public boolean isEnabled(Object logger) {
            try {
                if (hasSpecificIsEnabled) {
                    MethodType mt = MethodType.methodType(boolean.class);
                    final MethodHandle handle = lookup.findVirtual(definingClass,
                        enableMethod, mt).bindTo(logger);
                    return Boolean.class.cast(handle.invoke());
                } else {
                    MethodType mt = MethodType.methodType(boolean.class,
                        Level.class);
                    final MethodHandle handle = lookup.findVirtual(definingClass,
                        enableMethod, mt).bindTo(logger);
                    return Boolean.class.cast(handle.invoke(platformLevel));
                }
            } catch (Throwable ex) {
                throw new RuntimeException(ex);
            }
        }

        private void invoke(String method, Object logger, MethodType mt, Object... args) {
            try {
                final int last = mt.parameterCount()-1;
                boolean isVarargs = mt.parameterType(last).isArray();
                final MethodHandle handle = lookup.findVirtual(definingClass,
                        method, mt).bindTo(logger);

                final StringBuilder builder = new StringBuilder();
                builder.append(logger.getClass().getSimpleName()).append('.')
                        .append(method).append('(');
                String sep = "";
                int offset = 0;
                Object[] params = args;
                for (int i=0; (i-offset) < params.length; i++) {
                    if (isVarargs && i == last) {
                        offset = last;
                        params = (Object[])args[i];
                        if (params == null) break;
                    }
                    Object p = params[i - offset];
                    String quote = (p instanceof String) ? "\"" : "";
                    builder.append(sep).append(quote).append(p).append(quote);
                    sep = ", ";
                }
                builder.append(')');
                if (verbose) {
                    System.out.println(builder);
                }
                handle.invokeWithArguments(args);
            } catch (Throwable ex) {
                throw new RuntimeException(ex);
            }
        }

    };

    static interface Checker<LogResult, L> extends BiFunction<LogResult, L, Void> {}
    static interface JdkLogTester
            extends BiFunction<sun.util.logging.PlatformLogger.Bridge, Level, Void> {}
    static interface SpiLogTester
            extends BiFunction<java.lang.System.Logger, java.lang.System.Logger.Level, Void> {}

    static interface MethodInvoker<LOGGER, LEVEL> {
        public void logX(LOGGER logger, LEVEL level, Object... args);
    }

    public enum JdkLogMethodInvoker
           implements MethodInvoker<sun.util.logging.PlatformLogger.Bridge, Level> {
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#log(Level, String, Object...)};
         **/
        LOG_STRING_PARAMS("log", MethodType.methodType(void.class,
                Level.class, String.class, Object[].class)),
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#log(Level, String, Throwable)};
         **/
        LOG_STRING_THROWN("log", MethodType.methodType(void.class,
                Level.class, String.class, Throwable.class)),
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#log(Level, Supplier<String>)};
         **/
        LOG_SUPPLIER("log", MethodType.methodType(void.class,
                Level.class, Supplier.class)),
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#log(Level, Throwable, Supplier<String>)};
         **/
        LOG_SUPPLIER_THROWN("log", MethodType.methodType(void.class,
                Level.class, Throwable.class, Supplier.class)),
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#logp(Level, String, String, String)};
         **/
        LOGP_STRING("logp", MethodType.methodType(void.class,
                Level.class, String.class, String.class, String.class)),
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#logp(Level, String, String, String, Object...)};
         **/
        LOGP_STRING_PARAMS("logp", MethodType.methodType(void.class,
                Level.class, String.class, String.class, String.class, Object[].class)),
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#logp(Level, String, String, String, Throwable)};
         **/
        LOGP_STRING_THROWN("logp", MethodType.methodType(void.class,
                Level.class, String.class, String.class, String.class, Throwable.class)),
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#logp(Level, String, String, Supplier<String>)};
         **/
        LOGP_SUPPLIER("logp", MethodType.methodType(void.class,
                Level.class, String.class, String.class, Supplier.class)),
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#logp(Level, String, String, Throwable, Supplier<String>)};
         **/
        LOGP_SUPPLIER_THROWN("logp", MethodType.methodType(void.class,
                Level.class, String.class, String.class,
                Throwable.class, Supplier.class)),
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#logrb(Level, ResourceBundle, String, Object...)};
         **/
        LOGRB_STRING_PARAMS("logrb", MethodType.methodType(void.class,
                Level.class, ResourceBundle.class, String.class, Object[].class)),
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#logrb(Level, ResourceBundle, String, Throwable)};
         **/
        LOGRB_STRING_THROWN("logrb", MethodType.methodType(void.class,
                Level.class, ResourceBundle.class, String.class, Throwable.class)),
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#logrb(Level, String, String, ResourceBundle, String, Object...)};
         **/
        LOGRBP_STRING_PARAMS("logrb", MethodType.methodType(void.class,
                Level.class, String.class, String.class, ResourceBundle.class,
                String.class, Object[].class)),
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#logrb(Level, String, String, ResourceBundle, String, Throwable)};
         **/
        LOGRBP_STRING_THROWN("logrb", MethodType.methodType(void.class,
                Level.class, String.class, String.class, ResourceBundle.class,
                String.class, Throwable.class)),
        ;
        final MethodType mt;
        final String method;
        JdkLogMethodInvoker(String method, MethodType mt) {
            this.mt = mt;
            this.method = method;
        }
        Object[] makeArgs(Level level, Object... rest) {
            List<Object> list = new ArrayList<>(rest == null ? 1 : rest.length + 1);
            list.add(level);
            if (rest != null) {
                list.addAll(Arrays.asList(rest));
            }
            return list.toArray(new Object[list.size()]);
        }

        @Override
        public void logX(sun.util.logging.PlatformLogger.Bridge logger, Level level, Object... args) {
            try {
                MethodHandle handle = lookup.findVirtual(bridgeLoggerClass,
                        method, mt).bindTo(logger);
                final int last = mt.parameterCount()-1;
                boolean isVarargs = mt.parameterType(last).isArray();

                args = makeArgs(level, args);

                final StringBuilder builder = new StringBuilder();
                builder.append(logger.getClass().getSimpleName()).append('.')
                        .append(this.method).append('(');
                String sep = "";
                int offset = 0;
                Object[] params = args;
                for (int i=0; (i-offset) < params.length; i++) {
                    if (isVarargs && i == last) {
                        offset = last;
                        params = (Object[])args[i];
                        if (params == null) break;
                    }
                    Object p = params[i - offset];
                    String quote = (p instanceof String) ? "\"" : "";
                    p = p instanceof Level ? "Level."+p : p;
                    builder.append(sep).append(quote).append(p).append(quote);
                    sep = ", ";
                }
                builder.append(')');
                if (verbose) System.out.println(builder);
                handle.invokeWithArguments(args);
            } catch (Throwable ex) {
                throw new RuntimeException(ex);
            }
        }
    }


    public enum SpiLogMethodInvoker implements MethodInvoker<java.lang.System.Logger,
            java.lang.System.Logger.Level> {
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#log(Level, String, Object...)};
         **/
        LOG_STRING_PARAMS("log", MethodType.methodType(void.class,
                java.lang.System.Logger.Level.class, String.class, Object[].class)),
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#log(Level, String, Throwable)};
         **/
        LOG_STRING_THROWN("log", MethodType.methodType(void.class,
                java.lang.System.Logger.Level.class, String.class, Throwable.class)),
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#log(Level, Supplier<String>)};
         **/
        LOG_SUPPLIER("log", MethodType.methodType(void.class,
                java.lang.System.Logger.Level.class, Supplier.class)),
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#log(Level, Throwable, Supplier<String>)};
         **/
        LOG_SUPPLIER_THROWN("log", MethodType.methodType(void.class,
                java.lang.System.Logger.Level.class, Supplier.class, Throwable.class)),
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#log(Level, Supplier<String>)};
         **/
        LOG_OBJECT("log", MethodType.methodType(void.class,
                java.lang.System.Logger.Level.class, Object.class)),
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#logrb(Level, ResourceBundle, String, Object...)};
         **/
        LOGRB_STRING_PARAMS("log", MethodType.methodType(void.class,
                java.lang.System.Logger.Level.class, ResourceBundle.class,
                String.class, Object[].class)),
        /**
         * Tests {@link
         * jdk.internal.logging.Logger#logrb(Level, ResourceBundle, String, Throwable)};
         **/
        LOGRB_STRING_THROWN("log", MethodType.methodType(void.class,
                java.lang.System.Logger.Level.class, ResourceBundle.class,
                String.class, Throwable.class)),
        ;
        final MethodType mt;
        final String method;
        SpiLogMethodInvoker(String method, MethodType mt) {
            this.mt = mt;
            this.method = method;
        }
        Object[] makeArgs(java.lang.System.Logger.Level level, Object... rest) {
            List<Object> list = new ArrayList<>(rest == null ? 1 : rest.length + 1);
            list.add(level);
            if (rest != null) {
                list.addAll(Arrays.asList(rest));
            }
            return list.toArray(new Object[list.size()]);
        }

        @Override
        public void logX(java.lang.System.Logger logger,
                java.lang.System.Logger.Level level, Object... args) {
            try {
                MethodHandle handle = lookup.findVirtual(spiLoggerClass,
                        method, mt).bindTo(logger);
                final int last = mt.parameterCount()-1;
                boolean isVarargs = mt.parameterType(last).isArray();

                args = makeArgs(level, args);

                final StringBuilder builder = new StringBuilder();
                builder.append(logger.getClass().getSimpleName()).append('.')
                        .append(this.method).append('(');
                String sep = "";
                int offset = 0;
                Object[] params = args;
                for (int i=0; (i-offset) < params.length; i++) {
                    if (isVarargs && i == last) {
                        offset = last;
                        params = (Object[])args[i];
                        if (params == null) break;
                    }
                    Object p = params[i - offset];
                    String quote = (p instanceof String) ? "\"" : "";
                    p = p instanceof Level ? "Level."+p : p;
                    builder.append(sep).append(quote).append(p).append(quote);
                    sep = ", ";
                }
                builder.append(')');
                if (verbose) System.out.println(builder);
                handle.invokeWithArguments(args);
            } catch (Throwable ex) {
                throw new RuntimeException(ex);
            }
        }
    }


    public abstract static class BackendTester<BackendRecord> {
        static final Level[] levelMap = {Level.ALL, Level.FINER, Level.FINE,
            Level.INFO, Level.WARNING, Level.SEVERE, Level.OFF};

        abstract class BackendAdaptor {
            public abstract String getLoggerName(BackendRecord res);
            public abstract Object getLevel(BackendRecord res);
            public abstract String getMessage(BackendRecord res);
            public abstract String getSourceClassName(BackendRecord res);
            public abstract String getSourceMethodName(BackendRecord res);
            public abstract Throwable getThrown(BackendRecord res);
            public abstract ResourceBundle getResourceBundle(BackendRecord res);
            public abstract void setLevel(java.lang.System.Logger logger,
                    Level level);
            public abstract void setLevel(java.lang.System.Logger logger,
                    java.lang.System.Logger.Level level);
            public abstract List<BackendRecord> getBackendRecords();
            public abstract void resetBackendRecords();
            public boolean shouldBeLoggable(Levels level, Level loggerLevel) {
                final Level logLevel = level.platformLevel;
                return shouldBeLoggable(logLevel, loggerLevel);
            }
            public boolean shouldBeLoggable(Level logLevel, Level loggerLevel) {
                return loggerLevel.intValue() != Level.OFF.intValue()
                        && logLevel.intValue() >= loggerLevel.intValue();
            }
            public boolean shouldBeLoggable(java.lang.System.Logger.Level logLevel,
                    java.lang.System.Logger.Level loggerLevel) {
                return loggerLevel != java.lang.System.Logger.Level.OFF
                        && logLevel.ordinal() >= loggerLevel.ordinal();
            }
            public boolean isLoggable(java.lang.System.Logger logger, Level l) {
                return bridgeLoggerClass.cast(logger).isLoggable(l);
            }
            public String getCallerClassName(Levels level, String clazz) {
                return clazz != null ? clazz : Levels.class.getName();
            }
            public String getCallerClassName(MethodInvoker<?,?> logMethod,
                   String clazz) {
                return clazz != null ? clazz : logMethod.getClass().getName();
            }
            public String getCallerMethodName(Levels level, String method) {
                return method != null ? method : "invoke";
            }
            public String getCallerMethodName(MethodInvoker<?,?> logMethod,
                    String method) {
                return method != null ? method : "logX";
            }
            public Object getMappedLevel(Object level) {
                return level;
            }

            public Level toJUL(java.lang.System.Logger.Level level) {
                return levelMap[level.ordinal()];
            }
        }

        public final boolean isSystem;
        public final Class<? extends java.lang.System.Logger> restrictedTo;
        public final ResourceBundle localized;
        public BackendTester(boolean isSystem) {
            this(isSystem,null,null);
        }
        public BackendTester(boolean isSystem, ResourceBundle localized) {
            this(isSystem,null,localized);
        }
        public BackendTester(boolean isSystem,
                Class<? extends java.lang.System.Logger> restrictedTo) {
            this(isSystem, restrictedTo, null);
        }
        public BackendTester(boolean isSystem,
                Class<? extends java.lang.System.Logger> restrictedTo,
                ResourceBundle localized) {
            this.isSystem = isSystem;
            this.restrictedTo = restrictedTo;
            this.localized = localized;
        }

        public java.lang.System.Logger convert(java.lang.System.Logger logger) {
            return logger;
        }

        public static Level[] LEVELS = {
            Level.OFF,
            Level.SEVERE, Level.WARNING, Level.INFO, Level.CONFIG,
            Level.FINE, Level.FINER, Level.FINEST,
            Level.ALL
        };

        abstract BackendAdaptor adaptor();

        protected void checkRecord(Levels test, BackendRecord res, String loggerName,
                Level level, String msg, String className, String methodName,
                Throwable thrown, ResourceBundle bundle, Object... params) {
            checkRecord(test, res, loggerName, level, ()->msg, className,
                    methodName, thrown, bundle, params);

        }
        protected void checkRecord(Levels test, BackendRecord res, String loggerName,
                Level level, Supplier<String> msg, String className, String methodName,
                Throwable thrown, ResourceBundle bundle, Object... params) {
            checkRecord(test.method, res, loggerName, level, msg,
                    className, methodName, thrown, bundle, params);
        }
        protected <L> void checkRecord(String logMethod, BackendRecord res, String loggerName,
                L level, Supplier<String> msg, String className, String methodName,
                Throwable thrown, ResourceBundle bundle, Object... params) {
            final BackendAdaptor analyzer = adaptor();
            if (! Objects.equals(analyzer.getLoggerName(res), loggerName)) {
                throw new RuntimeException(logMethod+": expected logger name "
                        + loggerName + " got " + analyzer.getLoggerName(res));
            }
            if (!Objects.equals(analyzer.getLevel(res), analyzer.getMappedLevel(level))) {
                throw new RuntimeException(logMethod+": expected level "
                        + analyzer.getMappedLevel(level) + " got " + analyzer.getLevel(res));
            }
            if (!Objects.equals(analyzer.getMessage(res), msg.get())) {
                throw new RuntimeException(logMethod+": expected message \""
                        + msg.get() + "\" got \"" + analyzer.getMessage(res) +"\"");
            }
            if (!Objects.equals(analyzer.getSourceClassName(res), className)) {
                throw new RuntimeException(logMethod
                        + ": expected class name \"" + className
                        + "\" got \"" + analyzer.getSourceClassName(res) +"\"");
            }
            if (!Objects.equals(analyzer.getSourceMethodName(res), methodName)) {
                throw new RuntimeException(logMethod
                        + ": expected method name \"" + methodName
                        + "\" got \"" + analyzer.getSourceMethodName(res) +"\"");
            }
            final Throwable thrownRes = analyzer.getThrown(res);
            if (!Objects.equals(thrownRes, thrown)) {
                throw new RuntimeException(logMethod
                        + ": expected throwable \"" + thrown
                        + "\" got \"" + thrownRes + "\"");
            }
            if (!Objects.equals(analyzer.getResourceBundle(res), bundle)) {
                throw new RuntimeException(logMethod
                        + ": expected bundle \"" + bundle
                        + "\" got \"" + analyzer.getResourceBundle(res) +"\"");
            }
        }

        public void testLevel(Levels level, java.lang.System.Logger logger,
                String msg) {
            Runnable test = () -> level.level(logger, msg);
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord(level, res, logger.getName(), l, msg,
                            adaptor().getCallerClassName(level, Levels.class.getName()),
                            adaptor().getCallerMethodName(level, "invoke"),
                            null, localized);
                return null;
            };
            test("msg", level, logger, test, check);
        }

        public void testLevel(Levels level, java.lang.System.Logger logger,
                String msg, Object... params) {
            Runnable test = () -> level.level(logger, msg, (Object[])params);
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord(level, res, logger.getName(), l, msg,
                            adaptor().getCallerClassName(level, Levels.class.getName()),
                            adaptor().getCallerMethodName(level, "invoke"),
                            null, localized, (Object[])params);
                return null;
            };
            test("msg, params", level, logger, test, check);
        }

        public void testLevel(Levels level, java.lang.System.Logger logger,
                String msg, Throwable thrown) {
            Runnable test = () -> level.level(logger, msg, thrown);
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord(level, res, logger.getName(), l, msg,
                            adaptor().getCallerClassName(level, Levels.class.getName()),
                            adaptor().getCallerMethodName(level, "invoke"),
                            thrown, localized);
                return null;
            };
            test("msg, thrown", level, logger, test, check);
        }

        public void testLevel(Levels level, java.lang.System.Logger logger,
                Supplier<String> msg) {
            Runnable test = () -> level.level(logger, msg);
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord(level, res, logger.getName(), l, msg,
                            adaptor().getCallerClassName(level, Levels.class.getName()),
                            adaptor().getCallerMethodName(level, "invoke"),
                            null, null);
                return null;
            };
            test("msgSupplier", level, logger, test, check);
        }

        public void testLevel(Levels level, java.lang.System.Logger logger,
                Supplier<String> msg, Throwable thrown) {
            Runnable test = () -> level.level(logger, msg, thrown);
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord(level, res, logger.getName(), l, msg,
                            adaptor().getCallerClassName(level, Levels.class.getName()),
                            adaptor().getCallerMethodName(level, "invoke"),
                            thrown, null);
                return null;
            };
            test("throw, msgSupplier", level, logger, test, check);
        }

        public void testLevel(Levels level, java.lang.System.Logger logger,
                String msg, ResourceBundle bundle) {
            Runnable test = () -> level.level(logger, msg, bundle);
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord(level, res, logger.getName(), l, msg,
                            adaptor().getCallerClassName(level, Levels.class.getName()),
                            adaptor().getCallerMethodName(level, "invoke"),
                            null, bundle);
                return null;
            };
            test("bundle, msg", level, logger, test, check);
        }

        public void testLevel(Levels level, java.lang.System.Logger logger,
                String msg, ResourceBundle bundle, Object... params) {
            Runnable test = () -> level.level(logger, msg, bundle, (Object[])params);
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord(level, res, logger.getName(), l, msg,
                            adaptor().getCallerClassName(level, Levels.class.getName()),
                            adaptor().getCallerMethodName(level, "invoke"),
                            null, bundle, (Object[])params);
                return null;
            };
            test("bundle, msg, params", level, logger, test, check);
        }

        public void testLevel(Levels level, java.lang.System.Logger logger,
                String msg, ResourceBundle bundle, Throwable thrown) {
            Runnable test = () -> level.level(logger, msg, bundle, thrown);
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord(level, res, logger.getName(), l, msg,
                            adaptor().getCallerClassName(level, Levels.class.getName()),
                            adaptor().getCallerMethodName(level, "invoke"),
                            thrown, bundle);
                return null;
            };
            test("bundle, msg, throwable", level, logger, test, check);
        }

        // System.Logger
        public void testSpiLog(java.lang.System.Logger logger, String msg) {
            Checker<BackendRecord, java.lang.System.Logger.Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l, () -> msg,
                            adaptor().getCallerClassName(
                                    SpiLogMethodInvoker.LOG_STRING_PARAMS,
                                    SpiLogMethodInvoker.class.getName()),
                            adaptor().getCallerMethodName(
                                    SpiLogMethodInvoker.LOG_STRING_PARAMS,
                                    "logX"), null, localized);
                return null;
            };
            SpiLogTester tester = (x, level) -> {
                SpiLogMethodInvoker.LOG_STRING_PARAMS.logX(x, level, msg, (Object[])null);
                return null;
            };
            Function<String, String> nameProducer = (l) -> "log(Level." + l + ", \"" + msg + "\")";
            testSpiLog(logger, tester, check, nameProducer);
        }

        public void testSpiLog(java.lang.System.Logger logger,
                ResourceBundle bundle, String msg) {
            Checker<BackendRecord, java.lang.System.Logger.Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l, () -> msg,
                            adaptor().getCallerClassName(
                                    SpiLogMethodInvoker.LOGRB_STRING_PARAMS,
                                    SpiLogMethodInvoker.class.getName()),
                            adaptor().getCallerMethodName(
                                    SpiLogMethodInvoker.LOGRB_STRING_PARAMS,
                                    "logX"), null, bundle);
                return null;
            };
            SpiLogTester tester = (x, level) -> {
                SpiLogMethodInvoker.LOGRB_STRING_PARAMS.logX(x, level, bundle, msg, (Object[])null);
                return null;
            };
            Function<String, String> nameProducer = (l) -> "log(Level." + l
                    + ", bundle, \"" + msg + "\")";
            testSpiLog(logger, tester, check, nameProducer);
        }

        public void testSpiLog(java.lang.System.Logger logger, String msg, Object... params) {
            Checker<BackendRecord, java.lang.System.Logger.Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l, () -> msg,
                            adaptor().getCallerClassName(
                                    SpiLogMethodInvoker.LOG_STRING_PARAMS,
                                    SpiLogMethodInvoker.class.getName()),
                            adaptor().getCallerMethodName(
                                    SpiLogMethodInvoker.LOG_STRING_PARAMS,
                                    "logX"), null, localized, params);
                return null;
            };
            SpiLogTester tester = (x, level) -> {
                SpiLogMethodInvoker.LOG_STRING_PARAMS.logX(x, level, msg, params);
                return null;
            };
            Function<String, String> nameProducer = (l) -> "log(Level." + l + ", \"" + msg + "\", params...)";
            testSpiLog(logger, tester, check, nameProducer);
        }

        public void testSpiLog(java.lang.System.Logger logger,
                ResourceBundle bundle, String msg, Object... params) {
            Checker<BackendRecord, java.lang.System.Logger.Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l, () -> msg,
                            adaptor().getCallerClassName(
                                    SpiLogMethodInvoker.LOGRB_STRING_PARAMS,
                                    SpiLogMethodInvoker.class.getName()),
                            adaptor().getCallerMethodName(
                                    SpiLogMethodInvoker.LOGRB_STRING_PARAMS,
                                    "logX"), null, bundle, params);
                return null;
            };
            SpiLogTester tester = (x, level) -> {
                SpiLogMethodInvoker.LOGRB_STRING_PARAMS.logX(x, level, bundle, msg, params);
                return null;
            };
            Function<String, String> nameProducer = (l) -> "log(Level." + l
                    + ", bundle, \"" + msg + "\", params...)";
            testSpiLog(logger, tester, check, nameProducer);
        }

        public void testSpiLog(java.lang.System.Logger logger, String msg, Throwable thrown) {
            Checker<BackendRecord, java.lang.System.Logger.Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l, () -> msg,
                           adaptor().getCallerClassName(
                                    SpiLogMethodInvoker.LOG_STRING_THROWN,
                                    SpiLogMethodInvoker.class.getName()),
                            adaptor().getCallerMethodName(
                                    SpiLogMethodInvoker.LOG_STRING_THROWN,
                                    "logX"), thrown, localized);
                return null;
            };
            SpiLogTester tester = (x, level) -> {
                SpiLogMethodInvoker.LOG_STRING_THROWN.logX(x, level, msg, thrown);
                return null;
            };
            Function<String, String> nameProducer = (l) ->
                    "log(Level." + l + ", \"" + msg + "\", thrown)";
            testSpiLog(logger, tester, check, nameProducer);
        }

        public void testSpiLog(java.lang.System.Logger logger,
                ResourceBundle bundle, String msg, Throwable thrown) {
            Checker<BackendRecord, java.lang.System.Logger.Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l, () -> msg,
                            adaptor().getCallerClassName(
                                    SpiLogMethodInvoker.LOGRB_STRING_THROWN,
                                    SpiLogMethodInvoker.class.getName()),
                            adaptor().getCallerMethodName(
                                    SpiLogMethodInvoker.LOGRB_STRING_THROWN,
                                    "logX"), thrown, bundle);
                return null;
            };
            SpiLogTester tester = (x, level) -> {
                SpiLogMethodInvoker.LOGRB_STRING_THROWN.logX(x, level, bundle, msg, thrown);
                return null;
            };
            Function<String, String> nameProducer = (l) ->
                    "log(Level." + l + ", bundle, \"" + msg + "\", thrown)";
            testSpiLog(logger, tester, check, nameProducer);
        }

        public void testSpiLog(java.lang.System.Logger logger, Supplier<String> msg) {
            Checker<BackendRecord, java.lang.System.Logger.Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l, msg,
                            adaptor().getCallerClassName(
                                    SpiLogMethodInvoker.LOG_SUPPLIER,
                                    SpiLogMethodInvoker.class.getName()),
                            adaptor().getCallerMethodName(
                                    SpiLogMethodInvoker.LOG_SUPPLIER,
                                    "logX"), null, null);
                return null;
            };
            SpiLogTester tester = (x, level) -> {
                SpiLogMethodInvoker.LOG_SUPPLIER.logX(x, level, msg);
                return null;
            };
            Function<String, String> nameProducer = (l) ->
                    "log(Level." + l + ", () -> \"" + msg.get() + "\")";
            testSpiLog(logger, tester, check, nameProducer);
        }

        public void testSpiLog(java.lang.System.Logger logger, Object obj) {
            Checker<BackendRecord, java.lang.System.Logger.Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l, () -> obj.toString(),
                            adaptor().getCallerClassName(
                                    SpiLogMethodInvoker.LOG_OBJECT,
                                    SpiLogMethodInvoker.class.getName()),
                            adaptor().getCallerMethodName(
                                    SpiLogMethodInvoker.LOG_OBJECT,
                                    "logX"), null, null);
                return null;
            };
            SpiLogTester tester = (x, level) -> {
                SpiLogMethodInvoker.LOG_OBJECT.logX(x, level, obj);
                return null;
            };
            Function<String, String> nameProducer = (l) ->
                    "log(Level." + l + ", new "+obj.getClass().getSimpleName()+"(\""
                            + obj.toString() + "\"))";
            testSpiLog(logger, tester, check, nameProducer);
        }

        public void testSpiLog(java.lang.System.Logger logger, Throwable thrown, Supplier<String> msg) {
            Checker<BackendRecord, java.lang.System.Logger.Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l, msg,
                            adaptor().getCallerClassName(
                                    SpiLogMethodInvoker.LOG_SUPPLIER_THROWN,
                                    SpiLogMethodInvoker.class.getName()),
                            adaptor().getCallerMethodName(
                                    SpiLogMethodInvoker.LOG_SUPPLIER_THROWN,
                                    "logX"), thrown, null);
                return null;
            };
            SpiLogTester tester = (x, level) -> {
                SpiLogMethodInvoker.LOG_SUPPLIER_THROWN.logX(x, level, msg, thrown);
                return null;
            };
            Function<String, String> nameProducer = (l) ->
                    "log(Level." + l + ", () -> \"" + msg.get() + "\", thrown)";
            testSpiLog(logger, tester, check, nameProducer);
        }


        // JDK

        public void testLog(java.lang.System.Logger logger, String msg) {
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l, () -> msg,
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOG_STRING_PARAMS,
                                    JdkLogMethodInvoker.class.getName()),
                            adaptor().getCallerMethodName(
                                    JdkLogMethodInvoker.LOG_STRING_PARAMS,
                                    "logX"), null, localized);
                return null;
            };
            JdkLogTester tester = (x, level) -> {
                JdkLogMethodInvoker.LOG_STRING_PARAMS.logX(x, level, msg, (Object[])null);
                return null;
            };
            Function<String, String> nameProducer = (l) -> "log(Level." + l + ", \"" + msg + "\")";
            testJdkLog(logger, tester, check, nameProducer);
        }

        public void testLogrb(java.lang.System.Logger logger,
                ResourceBundle bundle, String msg) {
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l, () -> msg,
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOGRB_STRING_PARAMS,
                                    JdkLogMethodInvoker.class.getName()),
                            adaptor().getCallerMethodName(
                                    JdkLogMethodInvoker.LOGRB_STRING_PARAMS,
                                    "logX"), null, bundle);
                return null;
            };
            JdkLogTester tester = (x, level) -> {
                JdkLogMethodInvoker.LOGRB_STRING_PARAMS.logX(x, level, bundle, msg, (Object[])null);
                return null;
            };
            Function<String, String> nameProducer = (l) -> "logrb(Level." + l
                    + ", bundle, \"" + msg + "\")";
            testJdkLog(logger, tester, check, nameProducer);
        }

        public void testLog(java.lang.System.Logger logger, String msg, Object... params) {
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l, () -> msg,
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOG_STRING_PARAMS,
                                    JdkLogMethodInvoker.class.getName()),
                            adaptor().getCallerMethodName(
                                    JdkLogMethodInvoker.LOG_STRING_PARAMS,
                                    "logX"), null, localized, params);
                return null;
            };
            JdkLogTester tester = (x, level) -> {
                JdkLogMethodInvoker.LOG_STRING_PARAMS.logX(x, level, msg, params);
                return null;
            };
            Function<String, String> nameProducer = (l) -> "log(Level." + l + ", \"" + msg + "\", params...)";
            testJdkLog(logger, tester, check, nameProducer);
        }

        public void testLogrb(java.lang.System.Logger logger,
                ResourceBundle bundle, String msg, Object... params) {
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l, () -> msg,
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOGRB_STRING_PARAMS,
                                    JdkLogMethodInvoker.class.getName()),
                            adaptor().getCallerMethodName(
                                    JdkLogMethodInvoker.LOGRB_STRING_PARAMS,
                                    "logX"), null, bundle, params);
                return null;
            };
            JdkLogTester tester = (x, level) -> {
                JdkLogMethodInvoker.LOGRB_STRING_PARAMS.logX(x, level, bundle, msg, params);
                return null;
            };
            Function<String, String> nameProducer = (l) -> "log(Level." + l
                    + ", bundle, \"" + msg + "\", params...)";
            testJdkLog(logger, tester, check, nameProducer);
        }

        public void testLog(java.lang.System.Logger logger, String msg, Throwable thrown) {
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l, () -> msg,
                           adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOG_STRING_THROWN,
                                    JdkLogMethodInvoker.class.getName()),
                            adaptor().getCallerMethodName(
                                    JdkLogMethodInvoker.LOG_STRING_THROWN,
                                    "logX"), thrown, localized);
                return null;
            };
            JdkLogTester tester = (x, level) -> {
                JdkLogMethodInvoker.LOG_STRING_THROWN.logX(x, level, msg, thrown);
                return null;
            };
            Function<String, String> nameProducer = (l) ->
                    "log(Level." + l + ", \"" + msg + "\", thrown)";
            testJdkLog(logger, tester, check, nameProducer);
        }

        public void testLogrb(java.lang.System.Logger logger,
                ResourceBundle bundle, String msg, Throwable thrown) {
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l, () -> msg,
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOGRB_STRING_THROWN,
                                    JdkLogMethodInvoker.class.getName()),
                            adaptor().getCallerMethodName(
                                    JdkLogMethodInvoker.LOGRB_STRING_THROWN,
                                    "logX"), thrown, bundle);
                return null;
            };
            JdkLogTester tester = (x, level) -> {
                JdkLogMethodInvoker.LOGRB_STRING_THROWN.logX(x, level, bundle, msg, thrown);
                return null;
            };
            Function<String, String> nameProducer = (l) ->
                    "log(Level." + l + ", bundle, \"" + msg + "\", thrown)";
            testJdkLog(logger, tester, check, nameProducer);
        }

        public void testLog(java.lang.System.Logger logger, Supplier<String> msg) {
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l, msg,
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOG_SUPPLIER,
                                    JdkLogMethodInvoker.class.getName()),
                            adaptor().getCallerMethodName(
                                    JdkLogMethodInvoker.LOG_SUPPLIER,
                                    "logX"), null, null);
                return null;
            };
            JdkLogTester tester = (x, level) -> {
                JdkLogMethodInvoker.LOG_SUPPLIER.logX(x, level, msg);
                return null;
            };
            Function<String, String> nameProducer = (l) ->
                    "log(Level." + l + ", () -> \"" + msg.get() + "\")";
            testJdkLog(logger, tester, check, nameProducer);
        }

        public void testLog(java.lang.System.Logger logger, Throwable thrown, Supplier<String> msg) {
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l, msg,
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOG_SUPPLIER_THROWN,
                                    JdkLogMethodInvoker.class.getName()),
                            adaptor().getCallerMethodName(
                                    JdkLogMethodInvoker.LOG_SUPPLIER_THROWN,
                                    "logX"), thrown, null);
                return null;
            };
            JdkLogTester tester = (x, level) -> {
                JdkLogMethodInvoker.LOG_SUPPLIER_THROWN.logX(x, level, thrown, msg);
                return null;
            };
            Function<String, String> nameProducer = (l) ->
                    "log(Level." + l + ", () -> \"" + msg.get() + "\", thrown)";
            testJdkLog(logger, tester, check, nameProducer);
        }

        static Supplier<String> logpMessage(ResourceBundle bundle,
                String className, String methodName, Supplier<String> msg) {
            if (BEST_EFFORT_FOR_LOGP && bundle == null
                    && (className != null || methodName != null)) {
                final String cName = className == null ? "" :  className;
                final String mName = methodName == null ? "" : methodName;
                return () -> {
                    String m = msg.get();
                    return String.format("[%s %s] %s", cName, mName, m == null ? "" : m);
                };
            } else {
                return msg;
            }
        }

        public void testLogp(java.lang.System.Logger logger, String className,
                String methodName, String msg) {
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord("logp", res, logger.getName(), l,
                            logpMessage(localized, className, methodName, () -> msg),
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOGP_STRING, className),
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOGP_STRING, methodName),
                            null, localized);
                return null;
            };
            JdkLogTester tester = (x, level) -> {
                JdkLogMethodInvoker.LOGP_STRING.logX(x, level,
                        className, methodName, msg);
                return null;
            };
            Function<String, String> nameProducer = (l) ->
                    "logp(Level." + l + ", class, method, \"" + msg + "\")";
            testJdkLog(logger, tester, check, nameProducer);
        }

        public void testLogrb(java.lang.System.Logger logger, String className,
                String methodName, ResourceBundle bundle, String msg) {
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord("logp", res, logger.getName(), l, () -> msg,
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOGRBP_STRING_PARAMS, className),
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOGRBP_STRING_PARAMS, methodName),
                            null, bundle);
                return null;
            };
            JdkLogTester tester = (x, level) -> {
                JdkLogMethodInvoker.LOGRBP_STRING_PARAMS.logX(x, level,
                        className, methodName, bundle, msg, (Object[])null);
                return null;
            };
            Function<String, String> nameProducer = (l) ->
                    "logp(Level." + l + ", class, method, bundle, \"" + msg + "\")";
            testJdkLog(logger, tester, check, nameProducer);
        }

        public void testLogp(java.lang.System.Logger logger, String className,
                String methodName, String msg, Object... params) {
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord("logp", res, logger.getName(), l,
                            logpMessage(localized, className, methodName, () -> msg),
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOGP_STRING_PARAMS, className),
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOGP_STRING_PARAMS, methodName),
                            null, localized, params);
                return null;
            };
            JdkLogTester tester = (x, level) -> {
                JdkLogMethodInvoker.LOGP_STRING_PARAMS.logX(x, level,
                        className, methodName, msg, params);
                return null;
            };
            Function<String, String> nameProducer = (l) ->
                    "log(Level." + l + ", class, method, \"" + msg + "\", params...)";
            testJdkLog(logger, tester, check, nameProducer);
        }

        public void testLogrb(java.lang.System.Logger logger, String className,
                String methodName, ResourceBundle bundle, String msg,
                Object... params) {
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord("logp", res, logger.getName(), l, () -> msg,
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOGRBP_STRING_PARAMS, className),
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOGRBP_STRING_PARAMS, methodName),
                            null, bundle, params);
                return null;
            };
            JdkLogTester tester = (x, level) -> {
                JdkLogMethodInvoker.LOGRBP_STRING_PARAMS.logX(x, level,
                        className, methodName, bundle, msg, params);
                return null;
            };
            Function<String, String> nameProducer = (l) ->
                    "log(Level." + l + ", class, method, bundle, \""
                            + msg + "\", params...)";
            testJdkLog(logger, tester, check, nameProducer);
        }

        public void testLogp(java.lang.System.Logger logger, String className,
                String methodName, String msg, Throwable thrown) {
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l,
                            logpMessage(localized, className, methodName, () -> msg),
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOGP_STRING_THROWN, className),
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOGP_STRING_THROWN, methodName),
                            thrown, localized);
                return null;
            };
            JdkLogTester tester = (x, level) -> {
                JdkLogMethodInvoker.LOGP_STRING_THROWN.logX(x, level,
                        className, methodName, msg, thrown);
                return null;
            };
            Function<String, String> nameProducer = (l) ->
                    "log(Level." + l + ", class, method, \"" + msg + "\", thrown)";
            testJdkLog(logger, tester, check, nameProducer);
        }

        public void testLogrb(java.lang.System.Logger logger, String className,
                String methodName, ResourceBundle bundle,
                String msg, Throwable thrown) {
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l, () -> msg,
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOGRBP_STRING_THROWN, className),
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOGRBP_STRING_THROWN, methodName),
                            thrown, bundle);
                return null;
            };
            JdkLogTester tester = (x, level) -> {
                JdkLogMethodInvoker.LOGRBP_STRING_THROWN.logX(x, level,
                        className, methodName, bundle, msg, thrown);
                return null;
            };
            Function<String, String> nameProducer = (l) ->
                    "log(Level." + l + ", class, method, bundle, \"" + msg + "\", thrown)";
            testJdkLog(logger, tester, check, nameProducer);

        }

        public void testLogp(java.lang.System.Logger logger, String className,
                String methodName, Supplier<String> msg) {
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l,
                            logpMessage(null, className, methodName, msg),
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOGP_SUPPLIER, className),
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOGP_SUPPLIER, methodName),
                            null, null);
                return null;
            };
            JdkLogTester tester = (x, level) -> {
                JdkLogMethodInvoker.LOGP_SUPPLIER.logX(x, level,
                        className, methodName, msg);
                return null;
            };
            Function<String, String> nameProducer = (l) ->
                    "log(Level." + l + ", class, method, () -> \"" + msg.get() + "\")";
            testJdkLog(logger, tester, check, nameProducer);
        }

        public void testLogp(java.lang.System.Logger logger, String className,
                String methodName, Throwable thrown, Supplier<String> msg) {
            Checker<BackendRecord, Level> check = (res, l) -> {
                checkRecord("log", res, logger.getName(), l,
                            logpMessage(null, className, methodName, msg),
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOGP_SUPPLIER_THROWN, className),
                            adaptor().getCallerClassName(
                                    JdkLogMethodInvoker.LOGP_SUPPLIER_THROWN, methodName),
                            thrown, null);
                return null;
            };
            JdkLogTester tester = (x, level) -> {
                JdkLogMethodInvoker.LOGP_SUPPLIER_THROWN.logX(x, level,
                        className, methodName, thrown, msg);
                return null;
            };
            Function<String, String> nameProducer = (l) ->
                    "log(Level." + l + ", class, method, () -> \"" + msg.get() + "\", thrown)";
            testJdkLog(logger, tester, check, nameProducer);
        }

        private void testJdkLog(java.lang.System.Logger logger,
                JdkLogTester log, Checker<BackendRecord,Level> check,
                Function<String, String> nameProducer) {
            if (restrictedTo != null) {
                if (!bridgeLoggerClass.isAssignableFrom(restrictedTo)) {
                    if (VERBOSE) {
                        System.out.println("Skipping method from "
                            + bridgeLoggerClass);
                    }
                    return;
                }
            }
            System.out.println("Testing Logger." + nameProducer.apply("*")
                     + " on " + logger);
            final BackendAdaptor adaptor = adaptor();
            for (Level loggerLevel : LEVELS) {
                adaptor.setLevel(logger, loggerLevel);
                for (Level l : LEVELS) {
                    check(logger, () -> log.apply(bridgeLoggerClass.cast(logger), l),
                          check, () -> adaptor.isLoggable(logger, l),
                          () -> adaptor.shouldBeLoggable(l, loggerLevel),
                          l, loggerLevel, nameProducer.apply(l.toString()));
                }
            }
        }

        private void testSpiLog(java.lang.System.Logger logger,
                SpiLogTester log, Checker<BackendRecord, java.lang.System.Logger.Level> check,
                Function<String, String> nameProducer) {
            System.out.println("Testing System.Logger." + nameProducer.apply("*")
                     + " on " + logger);
            final BackendAdaptor adaptor = adaptor();
            for (java.lang.System.Logger.Level loggerLevel : java.lang.System.Logger.Level.values()) {

                adaptor.setLevel(logger, loggerLevel);
                for (java.lang.System.Logger.Level l : java.lang.System.Logger.Level.values()) {
                    check(logger, () -> log.apply(logger, l),
                          check, () -> logger.isLoggable(l),
                          () -> adaptor.shouldBeLoggable(l, loggerLevel),
                          l, loggerLevel, nameProducer.apply(l.toString()));
                }
            }
        }

        private void test(String args, Levels level, java.lang.System.Logger logger,
                Runnable test, Checker<BackendRecord, Level> check) {
            if (restrictedTo != null) {
                if (!level.definingClass.isAssignableFrom(restrictedTo)) {
                    if (VERBOSE) {
                        System.out.println("Skipping method from "
                            + level.definingClass);
                    }
                    return;
                }
            }
            String method = args.contains("bundle") ? "logrb" : "log";
            System.out.println("Testing Logger."
                    + method + "(Level." + level.platformLevel
                    + ", "+ args + ")" + " on " + logger);
            final BackendAdaptor adaptor = adaptor();
            for (Level loggerLevel : LEVELS) {
                adaptor.setLevel(logger, loggerLevel);
                check(logger, test, check,
                        () -> level.isEnabled(logger),
                        () -> adaptor.shouldBeLoggable(level, loggerLevel),
                        level.platformLevel, loggerLevel, level.method);
            }
        }

        private <L> void check(java.lang.System.Logger logger,
                Runnable test, Checker<BackendRecord,L> check,
                BooleanSupplier checkLevelEnabled,
                BooleanSupplier shouldBeLoggable,
                L logLevel, L loggerLevel, String logMethod) {
            final BackendAdaptor adaptor = adaptor();
            adaptor.resetBackendRecords();
            test.run();
            final List<BackendRecord> records = adaptor.getBackendRecords();
            if (shouldBeLoggable.getAsBoolean()) {
                if (!checkLevelEnabled.getAsBoolean()) {
                    throw new RuntimeException("Logger is not enabled for "
                            + logMethod
                            + " although logger level is " + loggerLevel);
                }
                if (records.size() != 1) {
                    throw new RuntimeException(loggerLevel + " [" +
                            logLevel + "] : Unexpected record sizes: "
                        + records.toString());
                }
                BackendRecord res = records.get(0);
                check.apply(res, logLevel);
            } else {
                if (checkLevelEnabled.getAsBoolean()) {
                    throw new RuntimeException("Logger is enabled for "
                            + logMethod
                            + " although logger level is " + loggerLevel);
                }
                if (!records.isEmpty()) {
                    throw new RuntimeException(loggerLevel + " [" +
                            logLevel + "] : Unexpected record sizes: "
                        + records.toString());
                }
            }
        }
    }

    public static class JULBackendTester extends BackendTester<LogRecord>{

        public JULBackendTester(boolean isSystem) {
            this(isSystem,null,null);
        }
        public JULBackendTester(boolean isSystem, ResourceBundle localized) {
            this(isSystem,null,localized);
        }
        public JULBackendTester(boolean isSystem,
                Class<? extends java.lang.System.Logger> restrictedTo) {
            this(isSystem, restrictedTo, null);
        }
        public JULBackendTester(boolean isSystem,
                Class<? extends java.lang.System.Logger> restrictedTo,
                ResourceBundle localized) {
            super(isSystem, restrictedTo, localized);
        }

        Logger getBackendLogger(String name) {
            if (isSystem) {
                return LoggingProviderImpl.getLogManagerAccess().demandLoggerFor(
                        LogManager.getLogManager(), name, Thread.class.getModule());
            } else {
                return Logger.getLogger(name);
            }
        }

        class JULBackendAdaptor extends BackendAdaptor {
            @Override
            public String getLoggerName(LogRecord res) {
                return res.getLoggerName();
            }
            @Override
            public Level getLevel(LogRecord res) {
                return Level.valueOf(res.getLevel().getName());
            }
            @Override
            public String getMessage(LogRecord res) {
                return res.getMessage();
            }
            @Override
            public String getSourceClassName(LogRecord res) {
                return res.getSourceClassName();
            }
            @Override
            public String getSourceMethodName(LogRecord res) {
                return res.getSourceMethodName();
            }
            @Override
            public Throwable getThrown(LogRecord res) {
                return res.getThrown();
            }
            @Override
            public ResourceBundle getResourceBundle(LogRecord res) {
                return res.getResourceBundle();
            }
            @Override
            public void setLevel(java.lang.System.Logger logger, Level level) {
                Logger backend = getBackendLogger(logger.getName());
                backend.setLevel(java.util.logging.Level.parse(level.name()));
            }
            @Override
            public void setLevel(java.lang.System.Logger logger, java.lang.System.Logger.Level level) {
                setLevel(logger, toJUL(level));
            }
            @Override
            public List<LogRecord> getBackendRecords() {
                return handler.records;
            }
            @Override
            public void resetBackendRecords() {
                handler.reset();
            }
            @Override
            public Level getMappedLevel(Object level) {
                if (level instanceof java.lang.System.Logger.Level) {
                    return toJUL((java.lang.System.Logger.Level)level);
                }
                return (Level)level;
            }
        }

        final JULBackendAdaptor julAdaptor = new JULBackendAdaptor();

        @Override
        BackendAdaptor adaptor() {
            return julAdaptor;
        }

    }

    public abstract static class BackendTesterFactory {
        public abstract BackendTester createBackendTester(boolean isSystem);
        public abstract  BackendTester createBackendTester(boolean isSystem,
                Class<? extends java.lang.System.Logger> restrictedTo);
        public abstract  BackendTester createBackendTester(boolean isSystem,
                Class<? extends java.lang.System.Logger> restrictedTo,
                ResourceBundle bundle);
        public abstract  BackendTester createBackendTester(boolean isSystem,
                ResourceBundle bundle);
    }

    public static class JULBackendTesterFactory extends BackendTesterFactory {

        @Override
        public BackendTester createBackendTester(boolean isSystem) {
            return new JULBackendTester(isSystem);
        }

        @Override
        public BackendTester createBackendTester(boolean isSystem,
                Class<? extends java.lang.System.Logger> restrictedTo) {
            return new JULBackendTester(isSystem, restrictedTo);
        }

        @Override
        public BackendTester createBackendTester(boolean isSystem,
                Class<? extends java.lang.System.Logger> restrictedTo,
                ResourceBundle bundle) {
            return new JULBackendTester(isSystem, restrictedTo, bundle);
        }

        @Override
        public BackendTester createBackendTester(boolean isSystem,
                ResourceBundle bundle) {
            return new JULBackendTester(isSystem, bundle);
        }
    }

    public static class CustomLoggerFinder extends LoggerFinder {

        static enum CustomLevel { OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL };
        static CustomLevel[] customLevelMap = { CustomLevel.ALL,
            CustomLevel.TRACE, CustomLevel.DEBUG, CustomLevel.INFO,
            CustomLevel.WARN, CustomLevel.ERROR, CustomLevel.OFF
        };
        static class CustomLogRecord {
            public final CustomLevel logLevel;
            public final java.lang.System.Logger logger;
            public final String msg;
            public final Object[] params;
            public final Throwable thrown;
            public final ResourceBundle bundle;

            CustomLogRecord(java.lang.System.Logger producer,
                    CustomLevel level, String msg) {
                this(producer, level, msg, (ResourceBundle)null, (Throwable)null, (Object[])null);
            }

            CustomLogRecord(java.lang.System.Logger producer,
                    CustomLevel level, String msg, ResourceBundle bundle,
                    Throwable thrown, Object... params) {
                this.logger   = producer;
                this.logLevel = level;
                this.msg = msg;
                this.params = params;
                this.thrown = thrown;
                this.bundle = bundle;
            }
        }

        static final List<CustomLogRecord>  records =
                Collections.synchronizedList(new ArrayList<>());

        static class CustomLogger implements java.lang.System.Logger {

            final String name;
            volatile CustomLevel level;
            CustomLogger(String name) {
                this.name = name;
                this.level = CustomLevel.INFO;
            }

            @Override
            public String getName() {
                return name;
            }

            public void setLevel(CustomLevel level) {
                this.level = level;
            }


            @Override
            public boolean isLoggable(java.lang.System.Logger.Level level) {

                return this.level != CustomLevel.OFF && this.level.ordinal()
                        >= customLevelMap[level.ordinal()].ordinal();
            }

            @Override
            public void log(java.lang.System.Logger.Level level, ResourceBundle bundle, String key, Throwable thrown) {
                if (isLoggable(level)) {
                    records.add(new CustomLogRecord(this, customLevelMap[level.ordinal()],
                              key, bundle, thrown));
                }
            }

            @Override
            public void log(java.lang.System.Logger.Level level, ResourceBundle bundle, String format, Object... params) {
                if (isLoggable(level)) {
                    records.add(new CustomLogRecord(this, customLevelMap[level.ordinal()],
                              format, bundle, null, params));
                }
            }

        }

        final Map<String, java.lang.System.Logger> applicationLoggers =
                Collections.synchronizedMap(new HashMap<>());
        final Map<String, java.lang.System.Logger> systemLoggers =
                Collections.synchronizedMap(new HashMap<>());

        @Override
        public java.lang.System.Logger getLogger(String name, Module caller) {
            ClassLoader callerLoader = caller.getClassLoader();
            if (callerLoader == null) {
                systemLoggers.putIfAbsent(name, new CustomLogger(name));
                return systemLoggers.get(name);
            } else {
                applicationLoggers.putIfAbsent(name, new CustomLogger(name));
                return applicationLoggers.get(name);
            }
        }

        CustomLevel fromJul(Level level) {
            if (level.intValue() == Level.OFF.intValue()) {
                return CustomLevel.OFF;
            } else if (level.intValue() > Level.SEVERE.intValue()) {
                return CustomLevel.ERROR;
            } else if (level.intValue() > Level.WARNING.intValue()) {
                return CustomLevel.ERROR;
            } else if (level.intValue() > Level.INFO.intValue()) {
                return CustomLevel.WARN;
            } else if (level.intValue() > Level.CONFIG.intValue()) {
                return CustomLevel.INFO;
            } else if (level.intValue() > Level.FINER.intValue()) {
                return CustomLevel.DEBUG;
            } else if (level.intValue() > Level.FINEST.intValue()) {
                return CustomLevel.TRACE;
            } else if (level.intValue() == Level.ALL.intValue()) {
                return CustomLevel.ALL;
            } else {
                return CustomLevel.TRACE;
            }
        }

        Level toJul(CustomLevel level) {
            switch(level) {
                case OFF: return Level.OFF;
                case FATAL: return Level.SEVERE;
                case ERROR: return Level.SEVERE;
                case WARN: return Level.WARNING;
                case INFO: return Level.INFO;
                case DEBUG: return Level.FINE;
                case TRACE: return Level.FINER;
                case ALL: return Level.ALL;
                default: throw new InternalError("No such level: "+level);
            }
        }

    }

    public static class CustomBackendTester extends
            BackendTester<CustomLoggerFinder.CustomLogRecord> {

        public final CustomLoggerFinder provider;

        public CustomBackendTester(boolean isSystem) {
            this(isSystem, null, null);
        }

        public CustomBackendTester(boolean isSystem,
                Class<? extends java.lang.System.Logger> restrictedTo) {
            this(isSystem, restrictedTo, null);
        }

        public CustomBackendTester(boolean isSystem,
                ResourceBundle localized) {
            this(isSystem, null, localized);
        }

        public CustomBackendTester(boolean isSystem,
                Class<? extends java.lang.System.Logger> restrictedTo,
                ResourceBundle localized) {
            super(isSystem, restrictedTo, localized);
            provider = (CustomLoggerFinder)java.lang.System.LoggerFinder.getLoggerFinder();
        }

        @Override
        public java.lang.System.Logger convert(java.lang.System.Logger logger) {
            if (restrictedTo != null && restrictedTo.isInstance(logger)) {
                return logger;
            } else if (restrictedTo == jdkLoggerClass) {
                return logger;
            } else {
                return java.lang.System.Logger.class.cast(
                        sun.util.logging.PlatformLogger.Bridge.convert(logger));
            }
        }

        class CustomBackendAdaptor extends BackendAdaptor {

            @Override
            public String getLoggerName(CustomLoggerFinder.CustomLogRecord res) {
                return res.logger.getName();
            }

            @Override
            public CustomLoggerFinder.CustomLevel getLevel(CustomLoggerFinder.CustomLogRecord res) {
                return res.logLevel;
            }

            @Override
            public String getMessage(CustomLoggerFinder.CustomLogRecord res) {
                return res.msg;
            }

            @Override // we don't support source class name in our custom provider implementation
            public String getSourceClassName(CustomLoggerFinder.CustomLogRecord res) {
                return null;
            }

            @Override // we don't support source method name in our custom provider implementation
            public String getSourceMethodName(CustomLoggerFinder.CustomLogRecord res) {
                return null;
            }

            @Override
            public Throwable getThrown(CustomLoggerFinder.CustomLogRecord res) {
                return res.thrown;
            }

            @Override
            public ResourceBundle getResourceBundle(CustomLoggerFinder.CustomLogRecord res) {
                return res.bundle;
            }

            @Override
            public void setLevel(java.lang.System.Logger logger, Level level) {
                final CustomLoggerFinder.CustomLogger l =
                        (CustomLoggerFinder.CustomLogger)
                        (isSystem ? provider.getLogger(logger.getName(), Thread.class.getModule()) :
                        provider.getLogger(logger.getName(), LoggerFinderBackendTest.class.getModule()));
                l.setLevel(provider.fromJul(level));
            }
            @Override
            public void setLevel(java.lang.System.Logger logger,
                    java.lang.System.Logger.Level level) {
                setLevel(logger, toJUL(level));
            }

            CustomLoggerFinder.CustomLevel getLevel(java.lang.System.Logger logger) {
                final CustomLoggerFinder.CustomLogger l =
                        (CustomLoggerFinder.CustomLogger)
                        (isSystem ? provider.getLogger(logger.getName(), Thread.class.getModule()) :
                        provider.getLogger(logger.getName(), LoggerFinderBackendTest.class.getModule()));
                return l.level;
            }

            @Override
            public List<CustomLoggerFinder.CustomLogRecord> getBackendRecords() {
                return CustomLoggerFinder.records;
            }

            @Override
            public void resetBackendRecords() {
                CustomLoggerFinder.records.clear();
            }

            @Override
            public boolean shouldBeLoggable(Levels level, Level loggerLevel) {
                return loggerLevel != Level.OFF &&
                       fromLevels(level).ordinal() <= provider.fromJul(loggerLevel).ordinal();
            }

            @Override
            public boolean isLoggable(java.lang.System.Logger logger, Level l) {
                return super.isLoggable(logger, l);
            }

            @Override
            public boolean shouldBeLoggable(Level logLevel, Level loggerLevel) {
                return loggerLevel != Level.OFF &&
                        provider.fromJul(logLevel).ordinal() <= provider.fromJul(loggerLevel).ordinal();
            }

            @Override // we don't support source class name in our custom provider implementation
            public String getCallerClassName(Levels level, String clazz) {
                return null;
            }

            @Override // we don't support source method name in our custom provider implementation
            public String getCallerMethodName(Levels level, String method) {
                return null;
            }

            @Override // we don't support source class name in our custom provider implementation
            public String getCallerClassName(MethodInvoker<?,?> logMethod, String clazz) {
                return null;
            }

            @Override // we don't support source method name in our custom provider implementation
            public String getCallerMethodName(MethodInvoker<?,?> logMethod, String method) {
                return null;
            }

            @Override
            public CustomLoggerFinder.CustomLevel getMappedLevel(Object level) {
                if (level instanceof java.lang.System.Logger.Level) {
                    final int index = ((java.lang.System.Logger.Level)level).ordinal();
                    return CustomLoggerFinder.customLevelMap[index];
                } else if (level instanceof Level) {
                    return provider.fromJul((Level)level);
                }
                return (CustomLoggerFinder.CustomLevel) level;
            }

            CustomLoggerFinder.CustomLevel fromLevels(Levels level) {
                switch(level) {
                    case SEVERE:
                        return CustomLoggerFinder.CustomLevel.ERROR;
                    case WARNING:
                        return CustomLoggerFinder.CustomLevel.WARN;
                    case INFO:
                        return CustomLoggerFinder.CustomLevel.INFO;
                    case CONFIG: case FINE:
                        return CustomLoggerFinder.CustomLevel.DEBUG;
                    case FINER:  case FINEST:
                        return CustomLoggerFinder.CustomLevel.TRACE;
                }
                throw new InternalError("No such level "+level);
            }

        }

        @Override
        BackendAdaptor adaptor() {
            return new CustomBackendAdaptor();
        }

    }

    public static class CustomBackendTesterFactory extends BackendTesterFactory {

        @Override
        public BackendTester createBackendTester(boolean isSystem) {
            return new CustomBackendTester(isSystem);
        }

        @Override
        public BackendTester createBackendTester(boolean isSystem,
                Class<? extends java.lang.System.Logger> restrictedTo) {
            return new CustomBackendTester(isSystem, restrictedTo);
        }

        @Override
        public BackendTester createBackendTester(boolean isSystem,
                Class<? extends java.lang.System.Logger> restrictedTo,
                ResourceBundle bundle) {
            return new CustomBackendTester(isSystem, restrictedTo, bundle);
        }

        @Override
        public BackendTester createBackendTester(boolean isSystem,
                ResourceBundle bundle) {
            return new CustomBackendTester(isSystem, bundle);
        }
    }

    static final Method getLazyLogger;
    static final Method accessLoggerFinder;
    static {
        // jdk.internal.logger.LazyLoggers.getLazyLogger(name, caller);
        try {
            Class<?> lazyLoggers = jdk.internal.logger.LazyLoggers.class;
            getLazyLogger = lazyLoggers.getMethod("getLazyLogger",
                    String.class, Module.class);
            getLazyLogger.setAccessible(true);
            Class<?> loggerFinderLoader =
                    Class.forName("java.lang.System$LoggerFinder");
            accessLoggerFinder = loggerFinderLoader.getDeclaredMethod("accessProvider");
            accessLoggerFinder.setAccessible(true);
        } catch (Throwable ex) {
            throw new ExceptionInInitializerError(ex);
        }
    }

    static java.lang.System.Logger getSystemLogger(String name, Module caller) throws Exception {
        try {
            return java.lang.System.Logger.class.cast(getLazyLogger.invoke(null, name, caller));
        } catch (InvocationTargetException x) {
            Throwable t = x.getTargetException();
            if (t instanceof Exception) {
                throw (Exception)t;
            } else {
                throw (Error)t;
            }
        }
    }
    static java.lang.System.Logger getSystemLogger(String name,
            ResourceBundle bundle, Module caller) throws Exception {
        try {
            LoggerFinder provider = LoggerFinder.class.cast(accessLoggerFinder.invoke(null));
            return provider.getLocalizedLogger(name, bundle, caller);
        } catch (InvocationTargetException x) {
            Throwable t = x.getTargetException();
            if (t instanceof Exception) {
                throw (Exception)t;
            } else {
                throw (Error)t;
            }
        }
    }

    // Change this to 'true' to get more traces...
    public static boolean verbose = false;

    public static void main(String[] argv) throws Exception {

        final AtomicInteger nb = new AtomicInteger(0);
        final boolean hidesProvider = Boolean.getBoolean("test.logger.hidesProvider");
        System.out.println(ClassLoader.getSystemClassLoader());
        final BackendTesterFactory factory;
        if (java.lang.System.LoggerFinder.getLoggerFinder() instanceof CustomLoggerFinder) {
            if (hidesProvider) {
                System.err.println("Custom backend "
                        + java.lang.System.LoggerFinder.getLoggerFinder()
                        + " should have been hidden!");
                throw new RuntimeException(
                        "Custom backend should have been hidden: "
                        + "check value of java.system.class.loader property");
            }
            System.out.println("Using custom backend");
            factory = new CustomBackendTesterFactory();
        } else {
            if (!hidesProvider) {
                System.err.println("Default JUL backend "
                        + java.lang.System.LoggerFinder.getLoggerFinder()
                        + " should have been hidden!");
                throw new RuntimeException(
                        "Default JUL backend should have been hidden: "
                        + "check value of java.system.class.loader property");
            }
            System.out.println("Using JUL backend");
            factory = new JULBackendTesterFactory();
        }

        testBackend(nb, factory);
    }

    public static void testBackend(AtomicInteger nb, BackendTesterFactory factory) throws Exception {

        // Tests all level specifics methods with loggers configured with
        // all possible levels and loggers obtained with all possible
        // entry points from LoggerFactory and JdkLoggerFactory, with
        // JUL as backend.

        // Test a simple application logger with JUL backend
        final BackendTester tester = factory.createBackendTester(false);
        final java.lang.System.Logger logger =
                java.lang.System.LoggerFinder.getLoggerFinder()
                        .getLogger("foo", LoggerFinderBackendTest.class.getModule());

        testLogger(tester, logger, nb);

        // Test a simple system logger with JUL backend
        final java.lang.System.Logger system =
                java.lang.System.LoggerFinder.getLoggerFinder()
                        .getLogger("bar", Thread.class.getModule());
        final BackendTester systemTester = factory.createBackendTester(true);
        testLogger(systemTester, system, nb);

        // Test a localized application logger with null resource bundle and
        // JUL backend
        final java.lang.System.Logger noBundleLogger =
                java.lang.System.LoggerFinder.getLoggerFinder()
                        .getLocalizedLogger("baz", null, LoggerFinderBackendTest.class.getModule());
        final BackendTester noBundleTester =
                factory.createBackendTester(false, spiLoggerClass);
        testLogger(noBundleTester, noBundleLogger, nb);

        // Test a localized system logger with null resource bundle and JUL
        // backend
        final java.lang.System.Logger noBundleSysLogger =
                java.lang.System.LoggerFinder.getLoggerFinder()
                        .getLocalizedLogger("oof", null, Thread.class.getModule());
        final BackendTester noBundleSysTester =
                factory.createBackendTester(true, spiLoggerClass);
        testLogger(noBundleSysTester, noBundleSysLogger, nb);

        // Test a localized application logger with null resource bundle and
        // JUL backend
        try {
            System.getLogger("baz", null);
            throw new RuntimeException("Expected NullPointerException not thrown");
        } catch (NullPointerException x) {
            System.out.println("System.Loggers.getLogger(\"baz\", null): got expected " + x);
        }
        final java.lang.System.Logger noBundleExtensionLogger =
                getSystemLogger("baz", null, LoggerFinderBackendTest.class.getModule());
        final BackendTester noBundleExtensionTester =
                factory.createBackendTester(false, jdkLoggerClass);
        testLogger(noBundleExtensionTester, noBundleExtensionLogger, nb);

        // Test a simple system logger with JUL backend
        final java.lang.System.Logger sysExtensionLogger =
                getSystemLogger("oof", Thread.class.getModule());
        final BackendTester sysExtensionTester =
                factory.createBackendTester(true, jdkLoggerClass);
        testLogger(sysExtensionTester, sysExtensionLogger, nb);

        // Test a localized system logger with null resource bundle and JUL
        // backend
        final java.lang.System.Logger noBundleSysExtensionLogger =
                getSystemLogger("oof", null, Thread.class.getModule());
        final BackendTester noBundleSysExtensionTester =
                factory.createBackendTester(true, jdkLoggerClass);
        testLogger(noBundleSysExtensionTester, noBundleSysExtensionLogger, nb);

        // Test a localized application logger converted to JDK with null
        // resource bundle and JUL backend
        final java.lang.System.Logger noBundleConvertedLogger =
                (java.lang.System.Logger)
                sun.util.logging.PlatformLogger.Bridge.convert(noBundleLogger);
        final BackendTester noBundleJdkTester = factory.createBackendTester(false);
        testLogger(noBundleJdkTester, noBundleConvertedLogger, nb);

        // Test a localized system logger converted to JDK with null resource
        // bundle and JUL backend
        final java.lang.System.Logger noBundleConvertedSysLogger =
                (java.lang.System.Logger)
                sun.util.logging.PlatformLogger.Bridge.convert(noBundleSysLogger);
        final BackendTester noBundleJdkSysTester = factory.createBackendTester(true);
        testLogger(noBundleJdkSysTester, noBundleConvertedSysLogger, nb);

        // Test a localized application logger with resource bundle and JUL
        // backend
        final ResourceBundle bundle =
                ResourceBundle.getBundle(ResourceBundeLocalized.class.getName());
        final java.lang.System.Logger bundleLogger =
                java.lang.System.LoggerFinder.getLoggerFinder()
                        .getLocalizedLogger("toto", bundle, LoggerFinderBackendTest.class.getModule());
        final BackendTester bundleTester =
                factory.createBackendTester(false, spiLoggerClass, bundle);
        testLogger(bundleTester, bundleLogger, nb);

        // Test a localized system logger with resource bundle and JUL backend
        final java.lang.System.Logger bundleSysLogger =
                java.lang.System.LoggerFinder.getLoggerFinder()
                        .getLocalizedLogger("titi", bundle, Thread.class.getModule());
        final BackendTester bundleSysTester =
                factory.createBackendTester(true, spiLoggerClass, bundle);
        testLogger(bundleSysTester, bundleSysLogger, nb);

        // Test a localized Jdk application logger with resource bundle and JUL
        // backend
        final java.lang.System.Logger bundleExtensionLogger =
                System.getLogger("tita", bundle);
        final BackendTester bundleExtensionTester =
                factory.createBackendTester(false, jdkLoggerClass, bundle);
        testLogger(bundleExtensionTester, bundleExtensionLogger, nb);

        // Test a localized Jdk system logger with resource bundle and JUL
        // backend
        final java.lang.System.Logger bundleExtensionSysLogger =
                getSystemLogger("titu", bundle, Thread.class.getModule());
        final BackendTester bundleExtensionSysTester =
                factory.createBackendTester(true, jdkLoggerClass, bundle);
        testLogger(bundleExtensionSysTester, bundleExtensionSysLogger, nb);

        // Test a localized application logger converted to JDK with resource
        // bundle and JUL backend
        final BackendTester bundleJdkTester =
                factory.createBackendTester(false, bundle);
        final java.lang.System.Logger bundleConvertedLogger =
                (java.lang.System.Logger)
                sun.util.logging.PlatformLogger.Bridge.convert(bundleLogger);
        testLogger(bundleJdkTester, bundleConvertedLogger, nb);

        // Test a localized Jdk system logger converted to JDK with resource
        // bundle and JUL backend
        final BackendTester bundleJdkSysTester =
                factory.createBackendTester(true, bundle);
        final java.lang.System.Logger bundleConvertedSysLogger =
                (java.lang.System.Logger)
                sun.util.logging.PlatformLogger.Bridge.convert(bundleSysLogger);
        testLogger(bundleJdkSysTester, bundleConvertedSysLogger, nb);

        // Now need to add tests for all the log/logp/logrb methods...

    }

    private static class FooObj {
        final String s;
        FooObj(String s) {
            this.s = s;
        }

        @Override
        public String toString() {
            return super.toString() +": "+s;
        }

    }

    public static void testLogger(BackendTester tester,
            java.lang.System.Logger spiLogger, AtomicInteger nb) {

        // Test all level-specific method forms:
        // fatal(...) error(...) severe(...) etc...
        java.lang.System.Logger jdkLogger = tester.convert(spiLogger);
        for (Levels l : Levels.values()) {
            java.lang.System.Logger logger =
                    l.definingClass.equals(spiLoggerClass) ? spiLogger : jdkLogger;
            tester.testLevel(l, logger, l.method + "[" + logger.getName()+ "]-"
                    + nb.incrementAndGet());
            tester.testLevel(l, logger, l.method + "[" + logger.getName()+ "]-"
                    + nb.incrementAndGet(),
                    bundleParam);
            final int nbb = nb.incrementAndGet();
            tester.testLevel(l, logger, () -> l.method + "[" + logger.getName()
                    + "]-" + nbb);
        }
        for (Levels l : Levels.values()) {
            java.lang.System.Logger logger =
                    l.definingClass.equals(spiLoggerClass) ? spiLogger : jdkLogger;
            tester.testLevel(l, logger,
                    l.method + "[" + logger.getName()+ "]({0},{1})-"
                    + nb.incrementAndGet(),
                    "One", "Two");
            tester.testLevel(l, logger,
                    l.method + "[" + logger.getName()+ "]({0},{1})-"
                    + nb.incrementAndGet(),
                    bundleParam, "One", "Two");
        }
        final Throwable thrown = new RuntimeException("Test");
        for (Levels l : Levels.values()) {
            java.lang.System.Logger logger =
                    l.definingClass.equals(spiLoggerClass) ? spiLogger : jdkLogger;
            tester.testLevel(l, logger, l.method + "[" + logger.getName()+ "]-"
                    + nb.incrementAndGet(),
                    thrown);
            tester.testLevel(l, logger, l.method + "[" + logger.getName()+ "]-"
                    + nb.incrementAndGet(),
                    bundleParam, thrown);
            final int nbb = nb.incrementAndGet();
            tester.testLevel(l, logger, ()->l.method + "[" + logger.getName()+ "]-"
                    + nbb, thrown);
        }

        java.lang.System.Logger logger = jdkLogger;

         // test System.Logger methods
       tester.testSpiLog(logger, "[" + logger.getName()+ "]-"
                + nb.incrementAndGet());
        tester.testSpiLog(logger, bundleParam, "[" + logger.getName()+ "]-"
                + nb.incrementAndGet());
        tester.testSpiLog(logger, "[" + logger.getName()+ "]-({0},{1})"
                + nb.incrementAndGet(), "One", "Two");
        tester.testSpiLog(logger, bundleParam, "[" + logger.getName()+ "]-({0},{1})"
                + nb.incrementAndGet(), "One", "Two");
        tester.testSpiLog(logger, "[" + logger.getName()+ "]-"
                + nb.incrementAndGet(), thrown);
        tester.testSpiLog(logger, bundleParam, "[" + logger.getName()+ "]-"
                + nb.incrementAndGet(), thrown);
        final int nbb01 = nb.incrementAndGet();
        tester.testSpiLog(logger, () -> "[" + logger.getName()+ "]-" + nbb01);
        final int nbb02 = nb.incrementAndGet();
        tester.testSpiLog(logger, thrown, () -> "[" + logger.getName()+ "]-" + nbb02);
        final int nbb03 = nb.incrementAndGet();
        tester.testSpiLog(logger, new FooObj("[" + logger.getName()+ "]-" + nbb03));

        // Test all log method forms:
        // jdk.internal.logging.Logger.log(...)
        tester.testLog(logger, "[" + logger.getName()+ "]-"
                + nb.incrementAndGet());
        tester.testLogrb(logger, bundleParam, "[" + logger.getName()+ "]-"
                + nb.incrementAndGet());
        tester.testLog(logger, "[" + logger.getName()+ "]-({0},{1})"
                + nb.incrementAndGet(), "One", "Two");
        tester.testLogrb(logger, bundleParam, "[" + logger.getName()+ "]-({0},{1})"
                + nb.incrementAndGet(), "One", "Two");
        tester.testLog(logger, "[" + logger.getName()+ "]-"
                + nb.incrementAndGet(), thrown);
        tester.testLogrb(logger, bundleParam, "[" + logger.getName()+ "]-"
                + nb.incrementAndGet(), thrown);
        final int nbb1 = nb.incrementAndGet();
        tester.testLog(logger, () -> "[" + logger.getName()+ "]-" + nbb1);
        final int nbb2 = nb.incrementAndGet();
        tester.testLog(logger, thrown, () -> "[" + logger.getName()+ "]-" + nbb2);

        // Test all logp method forms
        // jdk.internal.logging.Logger.logp(...)
        tester.testLogp(logger, "clazz" + nb.incrementAndGet(),
                "method" + nb.incrementAndGet(),
                "[" + logger.getName()+ "]-"
                + nb.incrementAndGet());
        tester.testLogrb(logger, "clazz" + nb.incrementAndGet(),
                "method" + nb.incrementAndGet(), bundleParam,
                "[" + logger.getName()+ "]-"
                + nb.incrementAndGet());
        tester.testLogp(logger, "clazz" + nb.incrementAndGet(),
                "method" + nb.incrementAndGet(),
                "[" + logger.getName()+ "]-({0},{1})"
                + nb.incrementAndGet(), "One", "Two");
        tester.testLogrb(logger, "clazz" + nb.incrementAndGet(),
                "method" + nb.incrementAndGet(), bundleParam,
                "[" + logger.getName()+ "]-({0},{1})"
                + nb.incrementAndGet(), "One", "Two");
        tester.testLogp(logger, "clazz" + nb.incrementAndGet(),
                "method" + nb.incrementAndGet(),
                "[" + logger.getName()+ "]-"
                + nb.incrementAndGet(), thrown);
        tester.testLogrb(logger, "clazz" + nb.incrementAndGet(),
                "method" + nb.incrementAndGet(), bundleParam,
                "[" + logger.getName()+ "]-"
                + nb.incrementAndGet(), thrown);
        final int nbb3 = nb.incrementAndGet();
        tester.testLogp(logger, "clazz" + nb.incrementAndGet(),
                "method" + nb.incrementAndGet(),
                () -> "[" + logger.getName()+ "]-" + nbb3);
        final int nbb4 = nb.incrementAndGet();
        tester.testLogp(logger, "clazz" + nb.incrementAndGet(),
                "method" + nb.incrementAndGet(),
                thrown, () -> "[" + logger.getName()+ "]-" + nbb4);
    }

}