Commit ef81d04eef4b1a60ff42bd9ccbe2918b0a5420ec

Pierre Le Marre 2023-09-18T18:17:34

Structured log messages with a message registry Currently there is little structure in the log messages, making difficult to use them for the following use cases: - A user looking for help about a log message: the user probably uses a search engine, thus the results will depend on the proper indexing of our documentation and the various forums. It relies only on the wording of the message, which may change with time. - A user wants to filter the logs resulting of the use of one of the components of xkbcommon. A typical example would be testing xkeyboard-config against libxkbcommon. It requires the use of a pattern (simple words detection or regex). The issue is that the pattern may become silently out-of-sync with xkbcommon. A common practice (e.g. in compilers) is to assign unique error codes to reference theses messages, along with an error index for documentation. Thus this commit implements the following features: - Create a message registry (message-registry.yaml) that defines the log messages produced by xkbcommon. This is a simple YAML file that provides, for each message: - A unique numeric code as a short identifier. It is used in the output message and thus can be easily be filtered to spot errors or searched in the internet. It must not change: if the semantics of message changes, it is better to introduce a new message for clarity. - A unique text identifier, meant for two uses: 1. Generate constants dealing with log information in our code base. 2. Generate human-friendly names for the documentation. - A type: currently warning or error. Used to prefix the constants (see hereinabove) and for basic classification in documentation. - A short description, used as concise and mandatory documentation. - An optionnal detailed description. - Optional examples, intended to help the user to fix issues themself. - Version of xkbcommon it was added. For old entries this often unknown, so they will default to 1.0.0. - Version of xkbcommon it was removed (optional) No entry should ever be deleted from this index, even if the message is not used anymore: it ensures we have unique identifiers along the history of xkbcommon, and that users can refer to the documentation even for older versions. - Add the script update-message-registry.py to generate the following files: - messages.h: message code enumeration for the messages currently used in the code base. Currently a private API. - message.registry.md: the error index documentation page. - Modify the logging functions to use structured messages. This is a work in progress.

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
diff --git a/doc/cool-uris.yaml b/doc/cool-uris.yaml
index b739ee5..9fae6d1 100644
--- a/doc/cool-uris.yaml
+++ b/doc/cool-uris.yaml
@@ -7,6 +7,7 @@ dir_63ce773eee1f9b680e6e312b48cc99ca.html: []
 dir_891596f32582d3133e8915e72908625f.html: []
 dir_d44c64559bbebec7f509842c48db8b23.html: []
 dir_e68e8157741866f444e17edd764ebbae.html: []
+error-index.html: []
 files.html: []
 functions.html: []
 functions_func.html: []
diff --git a/doc/doxygen-extra.css b/doc/doxygen-extra.css
index 104fa0b..569cd2e 100644
--- a/doc/doxygen-extra.css
+++ b/doc/doxygen-extra.css
@@ -31,3 +31,31 @@ a[href^="https://"]::after
     background-size: contain;
     display: inline-block;
 }
+
+/*******************************************************************************
+ * Error index
+ ******************************************************************************/
+
+div.example-container {
+    display: flex;
+    flex-flow: row wrap;
+    justify-content: space-between;
+    gap: 1em;
+}
+
+div.example {
+    flex-grow: 1;
+    overflow-x: auto;
+    margin-top: 1em;
+}
+
+div.example-inner {
+    height: 100%;
+    display: flex;
+    flex-direction: column;
+}
+
+div.example-title {
+    padding: 0 0 1em 0;
+    font-style: italic;
+}
diff --git a/doc/message-registry.md b/doc/message-registry.md
new file mode 100644
index 0000000..69027be
--- /dev/null
+++ b/doc/message-registry.md
@@ -0,0 +1,293 @@
+# Error index {#error-index}
+
+<!--
+NOTE: This file has been generated automatically by “update-message-registry.py”.
+      Do not edit manually!
+-->
+
+This page lists the warnings and errors generated by xkbcommon.
+There are currently 20 entries.
+
+@todo The documentation of the log messages is a work in progress.
+
+## Index
+
+| Code      | Identifier                   | Description | Type |
+| --------- | ---------------------------- | ----------- | ---- |
+| [XKB-034] | `malformed-number-literal` | Warn on malformed number literals | Error |
+| [XKB-060] | `unsupported-modifier-mask` | Warn on unsupported modifier mask | Error |
+| [XKB-107] | `unrecognized-keysym` | Warn on unrecognized keysyms | Warning |
+| [XKB-183] | `cannot-infer-key-type` | Warn if no key type can be inferred | Warning |
+| [XKB-237] | `unsupported-group-index` | Warn when a group index is not supported | Error |
+| [XKB-286] | `undefined-key-type` | Warn if using an undefined key type | Warning |
+| [XKB-305] | `non-base-group-name` | Warn if a group name was defined for group other than the first one | Warning |
+| [XKB-312] | `unsupported-shift-level` | Warn when a shift level is not supported | Error |
+| [XKB-461] | `conflicting-key-symbol` | Warn if there are conflicting keysyms while merging keys | Warning |
+| [XKB-516] | `extra-symbols-ignored` | <span class="todo">TODO:</span> add description | Warning |
+| [XKB-578] | `wrong-field-type` | Warn when a field has not the expected type | Error |
+| [XKB-645] | `unknown-char-escape-sequence` | Warn on unknown escape sequence in string literal | Warning |
+| [XKB-700] | `multiple-groups-at-once` | Warn if a key defines multiple groups at once | Warning |
+| [XKB-769] | `invalid-syntax` | The syntax is invalid and the file cannot be parsed | Error |
+| [XKB-770] | `undefined-keycode` | <span class="todo">TODO:</span> add description | Warning |
+| [XKB-800] | `conflicting-modmap` | Warn if there are conflicting modmap definitions | Warning |
+| [XKB-883] | `conflicting-key-action` | Warn if there are conflicting actions while merging keys | Warning |
+| [XKB-893] | `conflicting-key-type` | Warn if there are conflicting key types while merging groups | Warning |
+| [XKB-935] | `conflicting-key-fields` | Warn if there are conflicting fields while merging keys | Warning |
+| [XKB-965] | `unresolved-keymap-symbol` | Warn if using a symbol not defined in the keymap | Warning |
+
+## Details
+
+### XKB-034 – Malformed number literal {#XKB-034}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Error</dd>
+  <dt>Summary</dt><dd>Warn on malformed number literals</dd>
+</dl>
+
+xkbcommon can parse the following number literal formats:
+
+- *decimal integer:* 1, 123, etc.
+- *decimal floating-point number:* 1.23, etc.
+- *hexadecimal integer:* prefixed with “0x”: 0x123, 0xff, 0xAB, etc.
+
+
+### XKB-060 – Unsupported modifier mask {#XKB-060}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Error</dd>
+  <dt>Summary</dt><dd>Warn on unsupported modifier mask</dd>
+</dl>
+
+### XKB-107 – Unrecognized keysym {#XKB-107}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Warning</dd>
+  <dt>Summary</dt><dd>Warn on unrecognized keysyms</dd>
+</dl>
+
+xkbcommon replaces keysyms it does not recognize by the keysym `NoSymbol`.
+
+You may find the list of supported keysyms in
+`include/xkbcommon/xkbcommon-keysyms.h`.
+
+
+#### Examples
+
+<details>
+  <summary>Unrecognized keysym “`coma`”</summary>
+
+**Error message:**
+
+```
+xkbcommon: WARNING: [XKB-107] de:31:20: unrecognized keysym "coma"
+```
+
+xkbcommon does not recognize the keysym “`coma`”. It is most probably
+a typo for “<code>com<em>m</em>a</code>”.
+See: `XKB_KEY_comma` in `include/xkbcommon/xkbcommon-keysyms.h`.
+
+**Fix:**
+  <div class="example-container">
+    <div class="example">
+      <div class="example-inner">
+        <div class="example-title">Before</div>
+```c
+key <AB08> {[ coma, semicolon, periodcentered, multiply ]};
+```
+</div>
+    </div>
+    <div class="example">
+      <div class="example-inner">
+        <div class="example-title">After</div>
+```c
+key <AB08> {[ comma, semicolon, periodcentered, multiply ]};
+```
+</div>
+    </div>
+  </div>
+</details>
+
+### XKB-183 – Cannot infer key type {#XKB-183}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Warning</dd>
+  <dt>Summary</dt><dd>Warn if no key type can be inferred</dd>
+</dl>
+
+### XKB-237 – Unsupported group index {#XKB-237}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Error</dd>
+  <dt>Summary</dt><dd>Warn when a group index is not supported</dd>
+</dl>
+
+xkbcommon supports group index in the range (1..4).
+
+
+### XKB-286 – Undefined key type {#XKB-286}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Warning</dd>
+  <dt>Summary</dt><dd>Warn if using an undefined key type</dd>
+</dl>
+
+### XKB-305 – Non base group name {#XKB-305}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Warning</dd>
+  <dt>Summary</dt><dd>Warn if a group name was defined for group other than the first one</dd>
+</dl>
+
+### XKB-312 – Unsupported shift level {#XKB-312}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Error</dd>
+  <dt>Summary</dt><dd>Warn when a shift level is not supported</dd>
+</dl>
+
+Shift levels are _one_-indexed. xkbcommon supports two formats of shift levels:
+as numbers and as identifiers `LevelN`, where `N` is in the range (1..8).
+
+
+### XKB-461 – Conflicting key symbol {#XKB-461}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Warning</dd>
+  <dt>Summary</dt><dd>Warn if there are conflicting keysyms while merging keys</dd>
+</dl>
+
+### XKB-516 – Extra symbols ignored {#XKB-516}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Warning</dd>
+  <dt>Summary</dt><dd><span class="todo">TODO:</span> add description</dd>
+</dl>
+
+### XKB-578 – Wrong field type {#XKB-578}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Error</dd>
+  <dt>Summary</dt><dd>Warn when a field has not the expected type</dd>
+</dl>
+
+### XKB-645 – Unknown char escape sequence {#XKB-645}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Warning</dd>
+  <dt>Summary</dt><dd>Warn on unknown escape sequence in string literal</dd>
+</dl>
+
+xkbcommon support the following escape sequences in string literals:
+
+| Escape sequence | Corresponding character             |
+| --------------- | ----------------------------------- |
+| `\b`            | `U+0008` Backspace                  |
+| `\t`            | `U+0009` Character tabulation       |
+| `\n`            | `U+000A` Line feed                  |
+| `\v`            | `U+000B` Vertical tabulation        |
+| `\f`            | `U+000C` Form feed                  |
+| `\r`            | `U+000D` Carriage return            |
+| `\e`            | `U+001B` Escape                     |
+| `\\`            | `U+005C` Backslash                  |
+| `\NNN`          | _Octal_ escape, from `\0` to `\777` |
+
+
+### XKB-700 – Multiple groups at once {#XKB-700}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Warning</dd>
+  <dt>Summary</dt><dd>Warn if a key defines multiple groups at once</dd>
+</dl>
+
+### XKB-769 – Invalid syntax {#XKB-769}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Error</dd>
+  <dt>Summary</dt><dd>The syntax is invalid and the file cannot be parsed</dd>
+</dl>
+
+### XKB-770 – Undefined keycode {#XKB-770}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Warning</dd>
+  <dt>Summary</dt><dd><span class="todo">TODO:</span> add description</dd>
+</dl>
+
+### XKB-800 – Conflicting modmap {#XKB-800}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Warning</dd>
+  <dt>Summary</dt><dd>Warn if there are conflicting modmap definitions</dd>
+</dl>
+
+@todo detailed explanation and examples
+
+
+### XKB-883 – Conflicting key action {#XKB-883}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Warning</dd>
+  <dt>Summary</dt><dd>Warn if there are conflicting actions while merging keys</dd>
+</dl>
+
+### XKB-893 – Conflicting key type {#XKB-893}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Warning</dd>
+  <dt>Summary</dt><dd>Warn if there are conflicting key types while merging groups</dd>
+</dl>
+
+### XKB-935 – Conflicting key fields {#XKB-935}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Warning</dd>
+  <dt>Summary</dt><dd>Warn if there are conflicting fields while merging keys</dd>
+</dl>
+
+### XKB-965 – Unresolved keymap symbol {#XKB-965}
+
+<dl>
+  <dt>Since</dt><dd>1.0.0</dd>
+  <dt>Type</dt><dd>Warning</dd>
+  <dt>Summary</dt><dd>Warn if using a symbol not defined in the keymap</dd>
+</dl>
+
+[XKB-034]: @ref XKB-034
+[XKB-060]: @ref XKB-060
+[XKB-107]: @ref XKB-107
+[XKB-183]: @ref XKB-183
+[XKB-237]: @ref XKB-237
+[XKB-286]: @ref XKB-286
+[XKB-305]: @ref XKB-305
+[XKB-312]: @ref XKB-312
+[XKB-461]: @ref XKB-461
+[XKB-516]: @ref XKB-516
+[XKB-578]: @ref XKB-578
+[XKB-645]: @ref XKB-645
+[XKB-700]: @ref XKB-700
+[XKB-769]: @ref XKB-769
+[XKB-770]: @ref XKB-770
+[XKB-800]: @ref XKB-800
+[XKB-883]: @ref XKB-883
+[XKB-893]: @ref XKB-893
+[XKB-935]: @ref XKB-935
+[XKB-965]: @ref XKB-965
diff --git a/doc/message-registry.md.jinja b/doc/message-registry.md.jinja
new file mode 100644
index 0000000..e1d40d7
--- /dev/null
+++ b/doc/message-registry.md.jinja
@@ -0,0 +1,74 @@
+# Error index { {#--#} #error-index}
+
+{# NOTE: Prevent Doxygen issue by writing the comment after the first header. #}
+<!--
+NOTE: This file has been generated automatically by “{{script}}”.
+      Do not edit manually!
+-->
+
+This page lists the warnings and errors generated by xkbcommon.
+There are currently {{ entries|length }} entries.
+
+@todo The documentation of the log messages is a work in progress.
+
+## Index
+
+| Code      | Identifier                   | Description | Type |
+| --------- | ---------------------------- | ----------- | ---- |
+{% for entry in entries %}
+| [{{entry.message_code}}] | `{{entry.id}}` | {{entry.description|prepend_todo}} | {{entry.type|capitalize}} |
+{% endfor %}
+
+## Details
+
+{% for entry in entries %}
+### {{entry.message_code}} – {{entry.message_name}} { {#--#}#{{entry.message_code}}}
+
+<dl>
+{% if entry.removed %}
+  <dt>Added in</dt><dd>{{entry.added}}</dd>
+  <dt>Removed in</dt><dd>{{entry.removed}}</dd>
+{% else %}
+  <dt>Since</dt><dd>{{entry.added}}</dd>
+{% endif %}
+  <dt>Type</dt><dd>{{entry.type|capitalize}}</dd>
+  <dt>Summary</dt><dd>{{entry.description|prepend_todo}}</dd>
+</dl>
+
+{% if entry.details %}
+{{entry.details}}
+
+{% endif %}
+{% if entry.examples %}
+#### Examples
+
+{% for example in entry.examples %}
+<details>
+  <summary>{{example.name}}</summary>
+
+{{example.description}}
+{% if example.before %}
+**Fix:**
+  <div class="example-container">
+    <div class="example">
+      <div class="example-inner">
+        <div class="example-title">Before</div>
+{{example.before-}}
+      </div>
+    </div>
+    <div class="example">
+      <div class="example-inner">
+        <div class="example-title">After</div>
+{{example.after-}}
+      </div>
+    </div>
+  </div>
+{% endif %}
+</details>
+
+{% endfor %}
+{% endif %}
+{% endfor %}
+{% for entry in entries %}
+[{{entry.message_code}}]: @ref {{entry.message_code}}
+{% endfor %}
diff --git a/doc/message-registry.yaml b/doc/message-registry.yaml
new file mode 100644
index 0000000..fea4658
--- /dev/null
+++ b/doc/message-registry.yaml
@@ -0,0 +1,176 @@
+# Guidelines:
+# • A message code must always have the same meaning forever.
+# • Codes may be retired or introduced in new releases. In order to avoid
+#   clashes, retired codes must not be deleted.
+# • Codes should not themselves reflect classification, e.g. a range for parse
+#   errors and a range for each keymap component.
+# • Codes should not be assigned sequentially because it is misleading.
+# • Codes must be in the range 1..999. This range may be extended once every
+#   code has be assigned.
+#
+# See the following guidelines for futher details on good practices:
+# https://github.com/haskellfoundation/error-message-index/blob/main/tool-developers.md#code-assignment-recommendations
+
+# NOTE: Field “added: ALWAYS” means that the precise version is unknown and
+# anterior to the introduction of the message registry. It will be replaced by
+# the default version 1.0.0 in the generated documentation. While this is deemed
+# good enough to avoid spelunking commit history, a more precise version would
+# be welcome.
+
+# TODO: fix missing detailed description, examples, resolution
+
+- id: "malformed-number-literal"
+  code: 34
+  added: ALWAYS
+  type: error
+  description: "Warn on malformed number literals"
+  details: |
+    xkbcommon can parse the following number literal formats:
+
+    - *decimal integer:* 1, 123, etc.
+    - *decimal floating-point number:* 1.23, etc.
+    - *hexadecimal integer:* prefixed with “0x”: 0x123, 0xff, 0xAB, etc.
+- id: "unsupported-modifier-mask"
+  code: 60
+  added: ALWAYS
+  type: error
+  description: "Warn on unsupported modifier mask"
+- id: "unrecognized-keysym"
+  code: 107
+  added: ALWAYS
+  type: warning
+  description: "Warn on unrecognized keysyms"
+  details: |
+    xkbcommon replaces keysyms it does not recognize by the keysym `NoSymbol`.
+
+    You may find the list of supported keysyms in
+    `include/xkbcommon/xkbcommon-keysyms.h`.
+  examples:
+    - name: Unrecognized keysym “`coma`”
+      description: |
+        **Error message:**
+
+        ```
+        xkbcommon: WARNING: [XKB-107] de:31:20: unrecognized keysym "coma"
+        ```
+
+        xkbcommon does not recognize the keysym “`coma`”. It is most probably
+        a typo for “<code>com<em>m</em>a</code>”.
+        See: `XKB_KEY_comma` in `include/xkbcommon/xkbcommon-keysyms.h`.
+      before: |
+        ```c
+        key <AB08> {[ coma, semicolon, periodcentered, multiply ]};
+        ```
+      after: |
+        ```c
+        key <AB08> {[ comma, semicolon, periodcentered, multiply ]};
+        ```
+- id: "cannot-infer-key-type"
+  code: 183
+  added: ALWAYS
+  type: warning
+  description: "Warn if no key type can be inferred"
+- id: "unsupported-group-index"
+  code: 237
+  added: ALWAYS
+  type: error
+  description: "Warn when a group index is not supported"
+  details: |
+    xkbcommon supports group index in the range (1..{{XKB_MAX_GROUPS}}).
+- id: "undefined-key-type"
+  code: 286
+  added: ALWAYS
+  type: warning
+  description: "Warn if using an undefined key type"
+- id: "non-base-group-name"
+  code: 305
+  added: ALWAYS
+  type: warning
+  description: "Warn if a group name was defined for group other than the first one"
+- id: "unsupported-shift-level"
+  code: 312
+  added: ALWAYS
+  type: error
+  description: "Warn when a shift level is not supported"
+  details: |
+    Shift levels are _one_-indexed. xkbcommon supports two formats of shift levels:
+    as numbers and as identifiers `LevelN`, where `N` is in the range (1..8).
+- id: "conflicting-key-symbol"
+  code: 461
+  added: ALWAYS
+  type: warning
+  description: "Warn if there are conflicting keysyms while merging keys"
+- id: "extra-symbols-ignored"
+  code: 516
+  added: ALWAYS
+  type: warning
+  description: "TODO: add description"
+- id: "wrong-field-type"
+  code: 578
+  added: ALWAYS
+  type: error
+  description: "Warn when a field has not the expected type"
+- id: "unknown-char-escape-sequence"
+  code: 645
+  added: ALWAYS
+  type: warning
+  description: "Warn on unknown escape sequence in string literal"
+  details: |
+    xkbcommon support the following escape sequences in string literals:
+
+    | Escape sequence | Corresponding character             |
+    | --------------- | ----------------------------------- |
+    | `\b`            | `U+0008` Backspace                  |
+    | `\t`            | `U+0009` Character tabulation       |
+    | `\n`            | `U+000A` Line feed                  |
+    | `\v`            | `U+000B` Vertical tabulation        |
+    | `\f`            | `U+000C` Form feed                  |
+    | `\r`            | `U+000D` Carriage return            |
+    | `\e`            | `U+001B` Escape                     |
+    | `\\`            | `U+005C` Backslash                  |
+    | `\NNN`          | _Octal_ escape, from `\0` to `\777` |
+- id: "multiple-groups-at-once"
+  code: 700
+  added: ALWAYS
+  type: warning
+  description: "Warn if a key defines multiple groups at once"
+- id: "invalid-syntax"
+  code: 769
+  added: ALWAYS
+  type: error
+  description: "The syntax is invalid and the file cannot be parsed"
+- id: "undefined-keycode"
+  code: 770
+  added: ALWAYS
+  type: warning
+  description: "TODO: add description"
+- id: "conflicting-modmap"
+  code: 800
+  added: ALWAYS
+  type: warning
+  description: "Warn if there are conflicting modmap definitions"
+  details: |
+    @todo detailed explanation and examples
+- id: "conflicting-key-action"
+  code: 883
+  added: ALWAYS
+  type: warning
+  description: "Warn if there are conflicting actions while merging keys"
+- id: "conflicting-key-type"
+  code: 893
+  added: ALWAYS
+  type: warning
+  description: "Warn if there are conflicting key types while merging groups"
+- id: "conflicting-key-fields"
+  code: 935
+  added: ALWAYS
+  type: warning
+  description: "Warn if there are conflicting fields while merging keys"
+- id: "unresolved-keymap-symbol"
+  code: 965
+  added: ALWAYS
+  type: warning
+  description: "Warn if using a symbol not defined in the keymap"
+
+# TODO: deprecated keysym
+# TODO: unicode keysym when named and recommended keysym exists
diff --git a/meson.build b/meson.build
index 0d6c8ce..f37d416 100644
--- a/meson.build
+++ b/meson.build
@@ -221,6 +221,7 @@ libxkbcommon_sources = [
     'src/keymap.c',
     'src/keymap.h',
     'src/keymap-priv.c',
+    'src/messages-codes.h',
     'src/scanner-utils.h',
     'src/state.c',
     'src/text.c',
@@ -816,6 +817,7 @@ You can disable the documentation with -Denable-docs=false.''')
         'doc/user-configuration.md',
         'doc/rules-format.md',
         'doc/keymap-format-text-v1.md',
+        'doc/message-registry.md',
         'include/xkbcommon/xkbcommon.h',
         'include/xkbcommon/xkbcommon-compose.h',
         'include/xkbcommon/xkbcommon-keysyms.h',
diff --git a/scripts/update-message-registry.py b/scripts/update-message-registry.py
new file mode 100755
index 0000000..785f209
--- /dev/null
+++ b/scripts/update-message-registry.py
@@ -0,0 +1,275 @@
+#!/usr/bin/env python3
+
+from __future__ import annotations
+
+import argparse
+from dataclasses import astuple, dataclass
+from pathlib import Path
+import re
+from typing import Callable, Generic, Sequence, TypeVar
+
+import jinja2
+import yaml
+
+
+@dataclass(order=True)
+class Version:
+    """A semantic version number: MAJOR.MINOR.PATCH."""
+
+    UNKNOWN_VERSION = "ALWAYS"
+    DEFAULT_VERSION = "1.0.0"
+
+    major: int
+    minor: int
+    patch: int = 0
+
+    def __str__(self):
+        return ".".join(map(str, astuple(self)))
+
+    @classmethod
+    def parse(cls, raw_version: str) -> Version:
+        if raw_version == cls.UNKNOWN_VERSION:
+            raw_version = cls.DEFAULT_VERSION
+        version = raw_version.split(".")
+        assert 2 <= len(version) <= 3 and all(
+            n.isdecimal() for n in version
+        ), raw_version
+        return Version(*map(int, version))
+
+
+@dataclass
+class Example:
+    """An example in a message entry."""
+
+    name: str
+    description: str
+    before: str | None
+    after: str | None
+
+    @classmethod
+    def parse(cls, entry) -> Example:
+        name = entry.get("name")
+        assert name, entry
+
+        description = entry.get("description")
+        assert description
+
+        before = entry.get("before")
+        after = entry.get("after")
+        # Either none or both of them
+        assert not (bool(before) ^ bool(after))
+
+        return Example(name=name, description=description, before=before, after=after)
+
+
+@dataclass
+class Entry:
+    """An xkbcommon message entry in the message registry"""
+
+    VALID_TYPES = ("warning", "error")
+
+    code: int
+    """A unique strictly positive integer identifier"""
+    id: str
+    """A unique short human-readable string identifier"""
+    type: str
+    """Log level of the message"""
+    description: str
+    """A short description of the meaning of the message"""
+    details: str
+    """A long description of the meaning of the message"""
+    added: Version
+    """Version of xkbcommon the message has been added"""
+    removed: Version | None
+    """Version of xkbcommon the message has been removed"""
+    examples: tuple[Example, ...]
+    """
+    Optional examples of situations in which the message occurs.
+    If the message is an error or a warning, also provide hints on how to fix it.
+    """
+
+    @classmethod
+    def parse(cls, entry) -> Entry:
+        code = entry.get("code")
+        assert code is not None and isinstance(code, int) and code > 0, entry
+
+        id = entry.get("id")
+        assert id is not None, entry
+
+        type_ = entry.get("type")
+        assert type_ in cls.VALID_TYPES, entry
+
+        description = entry.get("description")
+        assert description is not None, entry
+
+        details = entry.get("details", "")
+
+        raw_added = entry.get("added", "")
+        assert raw_added, entry
+
+        added = Version.parse(raw_added)
+        assert added, entry
+
+        if removed := entry.get("removed"):
+            removed = Version.parse(removed)
+            assert added < removed, entry
+
+        if examples := entry.get("examples", ()):
+            examples = tuple(map(Example.parse, examples))
+
+        return Entry(
+            code=code,
+            id=id,
+            type=type_,
+            description=description,
+            added=added,
+            removed=removed,
+            details=details,
+            examples=examples,
+        )
+
+    @property
+    def message_code(self) -> str:
+        """Format the message code for display"""
+        return f"XKB-{self.code:0>3}"
+
+    @property
+    def message_code_constant(self: Entry) -> str:
+        """Returns the C enumeration member denoting the message code"""
+        id = self.id.replace("-", "_").upper()
+        return f"XKB_{self.type.upper()}_{id}"
+
+    @property
+    def message_name(self: Entry):
+        """Format the message string identifier for display"""
+        return self.id.replace("-", " ").capitalize()
+
+
+def prepend_todo(text: str) -> str:
+    if text.startswith("TODO"):
+        return f"""<span class="todo">{text[:5]}</span>{text[5:]}"""
+    else:
+        return text
+
+
+def load_message_registry(
+    env: jinja2.Environment, constants: dict[str, int], path: Path
+) -> Sequence[Entry]:
+    # Load the message registry YAML file as a Jinja2 template
+    registry_template = env.get_template(str(path))
+
+    # Load message registry
+    message_registry = sorted(
+        map(Entry.parse, yaml.safe_load(registry_template.render(constants))),
+        key=lambda e: e.code,
+    )
+
+    # Check message codes and identifiers are unique
+    codes: set[int] = set()
+    identifiers: set[str] = set()
+    for n, entry in enumerate(message_registry):
+        if entry.code in codes:
+            raise ValueError("Duplicated code in entry #{n}: {entry.code}")
+        if entry.id in identifiers:
+            raise ValueError("Duplicated identifier in entry #{n}: {entry.id}")
+        codes.add(entry.code)
+        identifiers.add(entry.id)
+
+    return message_registry
+
+
+def generate(
+    registry: Sequence[Entry],
+    env: jinja2.Environment,
+    root: Path,
+    file: Path,
+    skip_removed: bool = False,
+):
+    """Generate a file from its Jinja2 template and the message registry"""
+    template_path = file.with_suffix(f"{file.suffix}.jinja")
+    template = env.get_template(str(template_path))
+    path = root / file
+    script = Path(__file__).name
+    with path.open("wt", encoding="utf-8") as fd:
+        entries = (
+            tuple(filter(lambda e: e.removed is None, registry))
+            if skip_removed
+            else registry
+        )
+        fd.writelines(template.generate(entries=entries, script=script))
+
+
+T = TypeVar("T")
+
+
+@dataclass
+class Constant(Generic[T]):
+    name: str
+    pattern: re.Pattern
+    conversion: Callable[[str], T]
+
+
+def read_constants(path: Path, patterns: Sequence[Constant[T]]) -> dict[str, T]:
+    constants: dict[str, T] = {}
+    patternsʹ = list(patterns)
+    with path.open("rt", encoding="utf-8") as fd:
+        for line in fd:
+            for k, constant in enumerate(patternsʹ):
+                if m := constant.pattern.match(line):
+                    constants[constant.name] = constant.conversion(m.group(1))
+                    del patternsʹ[k]
+                    continue  # Expect only one match per line
+            if not patternsʹ:
+                # No more pattern to match
+                break
+    for constant in patternsʹ:
+        print(f"ERROR: could not find constant: {constant.name}.")
+    if patternsʹ:
+        raise ValueError("Some constants were not found.")
+    return constants
+
+
+# Root of the project
+ROOT = Path(__file__).parent.parent
+
+# Parse commands
+parser = argparse.ArgumentParser(description="Generate files from the message registry")
+parser.add_argument(
+    "--root",
+    type=Path,
+    default=ROOT,
+    help="Path to the root of the project (default: %(default)s)",
+)
+
+args = parser.parse_args()
+
+# Read some constants from libxkbcommon that we need
+constants = read_constants(
+    Path(__file__).parent.parent / "src" / "keymap.h",
+    (Constant("XKB_MAX_GROUPS", re.compile("^#define\s+XKB_MAX_GROUPS\s+(\d+)"), int),),
+)
+
+# Configure Jinja
+template_loader = jinja2.FileSystemLoader(args.root, encoding="utf-8")
+jinja_env = jinja2.Environment(
+    loader=template_loader,
+    keep_trailing_newline=True,
+    trim_blocks=True,
+    lstrip_blocks=True,
+)
+jinja_env.filters["prepend_todo"] = prepend_todo
+
+# Load message registry
+message_registry = load_message_registry(
+    jinja_env, constants, Path("doc/message-registry.yaml")
+)
+
+# Generate the files
+generate(
+    message_registry,
+    jinja_env,
+    args.root,
+    Path("src/messages-codes.h"),
+    skip_removed=True,
+)
+generate(message_registry, jinja_env, args.root, Path("doc/message-registry.md"))
diff --git a/src/context.h b/src/context.h
index 488bfad..d5fa117 100644
--- a/src/context.h
+++ b/src/context.h
@@ -27,6 +27,7 @@
 #define CONTEXT_H
 
 #include "atom.h"
+#include "messages-codes.h"
 
 struct xkb_context {
     int refcnt;
@@ -114,16 +115,31 @@ xkb_context_sanitize_rule_names(struct xkb_context *ctx,
  * format is supplied without arguments. Not supplying it would still
  * result in an error, though.
  */
+#define xkb_log_with_code(ctx, level, verbosity, msg_id, fmt, ...) \
+    xkb_log(ctx, level, verbosity, "[XKB-%03d] " fmt, \
+            msg_id, ##__VA_ARGS__)
+#define log_dbg_with_code(ctx, id, ...) \
+    xkb_log_with_code((ctx), XKB_LOG_LEVEL_DEBUG, 0, (id), __VA_ARGS__)
 #define log_dbg(ctx, ...) \
     xkb_log((ctx), XKB_LOG_LEVEL_DEBUG, 0, __VA_ARGS__)
+#define log_info_with_code(ctx, id, ...) \
+    xkb_log_with_code((ctx), XKB_LOG_LEVEL_INFO, 0, (id), __VA_ARGS__)
 #define log_info(ctx, ...) \
     xkb_log((ctx), XKB_LOG_LEVEL_INFO, 0, __VA_ARGS__)
+#define log_warn_with_code(ctx, id, ...) \
+    xkb_log_with_code((ctx), XKB_LOG_LEVEL_WARNING, 0, (id), __VA_ARGS__)
 #define log_warn(ctx, ...) \
-    xkb_log((ctx), XKB_LOG_LEVEL_WARNING, 0,  __VA_ARGS__)
+    xkb_log((ctx), XKB_LOG_LEVEL_WARNING, 0, __VA_ARGS__)
+#define log_err_with_code(ctx, id, ...) \
+    xkb_log_with_code((ctx), XKB_LOG_LEVEL_ERROR, 0, (id), __VA_ARGS__)
 #define log_err(ctx, ...) \
-    xkb_log((ctx), XKB_LOG_LEVEL_ERROR, 0,  __VA_ARGS__)
+    xkb_log((ctx), XKB_LOG_LEVEL_ERROR, 0, __VA_ARGS__)
+#define log_wsgo_with_code(ctx, id, ...) \
+    xkb_log_with_code((ctx), XKB_LOG_LEVEL_CRITICAL, 0, (id), __VA_ARGS__)
 #define log_wsgo(ctx, ...) \
     xkb_log((ctx), XKB_LOG_LEVEL_CRITICAL, 0, __VA_ARGS__)
+#define log_vrb_with_code(ctx, vrb, id, ...) \
+    xkb_log_with_code((ctx), XKB_LOG_LEVEL_WARNING, (vrb), (id), __VA_ARGS__)
 #define log_vrb(ctx, vrb, ...) \
     xkb_log((ctx), XKB_LOG_LEVEL_WARNING, (vrb), __VA_ARGS__)
 
diff --git a/src/messages-codes.h b/src/messages-codes.h
new file mode 100644
index 0000000..64a6177
--- /dev/null
+++ b/src/messages-codes.h
@@ -0,0 +1,62 @@
+// NOTE: This file has been generated automatically by “update-message-registry.py”.
+//       Do not edit manually!
+
+#ifndef MESSAGES_H
+#define MESSAGES_H
+
+#include <stdint.h>
+
+/**
+ * @name Codes of the log messages
+ *
+ * @added 1.6.0
+ *
+ */
+enum xkb_message_code {
+    _XKB_LOG_MESSAGE_MIN_CODE = 34,
+    /** Warn on malformed number literals */
+    XKB_ERROR_MALFORMED_NUMBER_LITERAL = 34,
+    /** Warn on unsupported modifier mask */
+    XKB_ERROR_UNSUPPORTED_MODIFIER_MASK = 60,
+    /** Warn on unrecognized keysyms */
+    XKB_WARNING_UNRECOGNIZED_KEYSYM = 107,
+    /** Warn if no key type can be inferred */
+    XKB_WARNING_CANNOT_INFER_KEY_TYPE = 183,
+    /** Warn when a group index is not supported */
+    XKB_ERROR_UNSUPPORTED_GROUP_INDEX = 237,
+    /** Warn if using an undefined key type */
+    XKB_WARNING_UNDEFINED_KEY_TYPE = 286,
+    /** Warn if a group name was defined for group other than the first one */
+    XKB_WARNING_NON_BASE_GROUP_NAME = 305,
+    /** Warn when a shift level is not supported */
+    XKB_ERROR_UNSUPPORTED_SHIFT_LEVEL = 312,
+    /** Warn if there are conflicting keysyms while merging keys */
+    XKB_WARNING_CONFLICTING_KEY_SYMBOL = 461,
+    /** TODO: add description */
+    XKB_WARNING_EXTRA_SYMBOLS_IGNORED = 516,
+    /** Warn when a field has not the expected type */
+    XKB_ERROR_WRONG_FIELD_TYPE = 578,
+    /** Warn on unknown escape sequence in string literal */
+    XKB_WARNING_UNKNOWN_CHAR_ESCAPE_SEQUENCE = 645,
+    /** Warn if a key defines multiple groups at once */
+    XKB_WARNING_MULTIPLE_GROUPS_AT_ONCE = 700,
+    /** The syntax is invalid and the file cannot be parsed */
+    XKB_ERROR_INVALID_SYNTAX = 769,
+    /** TODO: add description */
+    XKB_WARNING_UNDEFINED_KEYCODE = 770,
+    /** Warn if there are conflicting modmap definitions */
+    XKB_WARNING_CONFLICTING_MODMAP = 800,
+    /** Warn if there are conflicting actions while merging keys */
+    XKB_WARNING_CONFLICTING_KEY_ACTION = 883,
+    /** Warn if there are conflicting key types while merging groups */
+    XKB_WARNING_CONFLICTING_KEY_TYPE = 893,
+    /** Warn if there are conflicting fields while merging keys */
+    XKB_WARNING_CONFLICTING_KEY_FIELDS = 935,
+    /** Warn if using a symbol not defined in the keymap */
+    XKB_WARNING_UNRESOLVED_KEYMAP_SYMBOL = 965,
+    _XKB_LOG_MESSAGE_MAX_CODE = 965
+};
+
+typedef uint32_t xkb_message_code_t;
+
+#endif
diff --git a/src/messages-codes.h.jinja b/src/messages-codes.h.jinja
new file mode 100644
index 0000000..2195af4
--- /dev/null
+++ b/src/messages-codes.h.jinja
@@ -0,0 +1,26 @@
+// NOTE: This file has been generated automatically by “{{script}}”.
+//       Do not edit manually!
+
+#ifndef MESSAGES_H
+#define MESSAGES_H
+
+#include <stdint.h>
+
+/**
+ * @name Codes of the log messages
+ *
+ * @added 1.6.0
+ *
+ */
+enum xkb_message_code {
+    _XKB_LOG_MESSAGE_MIN_CODE = {{ entries[0].code }},
+    {% for entry in entries %}
+    /** {{ entry.description }} */
+    {{ entry.message_code_constant }} = {{ entry.code }},
+    {% endfor %}
+    _XKB_LOG_MESSAGE_MAX_CODE = {{ entries[-1].code }}
+};
+
+typedef uint32_t xkb_message_code_t;
+
+#endif
diff --git a/src/scanner-utils.h b/src/scanner-utils.h
index cede0ff..f4c799e 100644
--- a/src/scanner-utils.h
+++ b/src/scanner-utils.h
@@ -57,15 +57,28 @@ struct scanner {
     void *priv;
 };
 
+#define scanner_log_with_code(scanner, level, log_msg_id, fmt, ...) \
+    xkb_log_with_code((scanner)->ctx, (level), 0, log_msg_id, \
+                    "%s:%zu:%zu: " fmt "\n", \
+                    (scanner)->file_name, \
+                    (scanner)->token_line, \
+                    (scanner)->token_column, ##__VA_ARGS__)
+
 #define scanner_log(scanner, level, fmt, ...) \
     xkb_log((scanner)->ctx, (level), 0, \
             "%s:%zu:%zu: " fmt "\n", \
-             (scanner)->file_name, \
-             (scanner)->token_line, (scanner)->token_column, ##__VA_ARGS__)
+            (scanner)->file_name, \
+            (scanner)->token_line, (scanner)->token_column, ##__VA_ARGS__)
+
+#define scanner_err_with_code(scanner, id, fmt, ...) \
+    scanner_log_with_code(scanner, XKB_LOG_LEVEL_ERROR, id, fmt, ##__VA_ARGS__)
 
 #define scanner_err(scanner, fmt, ...) \
     scanner_log(scanner, XKB_LOG_LEVEL_ERROR, fmt, ##__VA_ARGS__)
 
+#define scanner_warn_with_code(scanner, id, fmt, ...) \
+    scanner_log_with_code(scanner, XKB_LOG_LEVEL_WARNING, id, fmt, ##__VA_ARGS__)
+
 #define scanner_warn(scanner, fmt, ...) \
     scanner_log(scanner, XKB_LOG_LEVEL_WARNING, fmt, ##__VA_ARGS__)
 
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c
index e2d4c40..1410aab 100644
--- a/src/xkbcomp/action.c
+++ b/src/xkbcomp/action.c
@@ -190,10 +190,11 @@ fieldText(enum action_field field)
 /***====================================================================***/
 
 static inline bool
-ReportMismatch(struct xkb_context *ctx, enum xkb_action_type action,
-               enum action_field field, const char *type)
+ReportMismatch(struct xkb_context *ctx, xkb_message_code_t code,
+               enum xkb_action_type action, enum action_field field,
+               const char *type)
 {
-    log_err(ctx,
+    log_err_with_code(ctx, code,
             "Value of %s field must be of type %s; "
             "Action %s definition ignored\n",
             fieldText(field), type, ActionTypeText(action));
@@ -243,7 +244,8 @@ CheckBooleanFlag(struct xkb_context *ctx, enum xkb_action_type action,
         return ReportActionNotArray(ctx, action, field);
 
     if (!ExprResolveBoolean(ctx, value, &set))
-        return ReportMismatch(ctx, action, field, "boolean");
+        return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE,
+                              action, field, "boolean");
 
     if (set)
         *flags_inout |= flag;
@@ -274,7 +276,7 @@ CheckModifierField(struct xkb_context *ctx, const struct xkb_mod_set *mods,
     }
 
     if (!ExprResolveModMask(ctx, value, MOD_BOTH, mods, mods_rtrn))
-        return ReportMismatch(ctx, action,
+        return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, action,
                               ACTION_FIELD_MODIFIERS, "modifier mask");
 
     *flags_inout &= ~ACTION_MODS_LOOKUP_MODMAP;
@@ -300,7 +302,8 @@ CheckAffectField(struct xkb_context *ctx, enum xkb_action_type action,
         return ReportActionNotArray(ctx, action, ACTION_FIELD_AFFECT);
 
     if (!ExprResolveEnum(ctx, value, &flags, lockWhich))
-        return ReportMismatch(ctx, action, ACTION_FIELD_AFFECT,
+        return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE,
+                              action, ACTION_FIELD_AFFECT,
                               "lock, unlock, both, neither");
 
     *flags_inout &= ~(ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK);
@@ -359,8 +362,8 @@ CheckGroupField(struct xkb_context *ctx, enum xkb_action_type action,
     }
 
     if (!ExprResolveGroup(ctx, spec, &idx))
-        return ReportMismatch(ctx, action, ACTION_FIELD_GROUP,
-                              "integer (range 1..8)");
+        return ReportMismatch(ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX, action,
+                              ACTION_FIELD_GROUP, "integer (range 1..8)");
 
     /* +n, -n are relative, n is absolute. */
     if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) {
@@ -416,7 +419,8 @@ HandleMovePtr(struct xkb_context *ctx, const struct xkb_mod_set *mods,
             return ReportActionNotArray(ctx, action->type, field);
 
         if (!ExprResolveInteger(ctx, value, &val))
-            return ReportMismatch(ctx, action->type, field, "integer");
+            return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, action->type,
+                                  field, "integer");
 
         if (val < INT16_MIN || val > INT16_MAX) {
             log_err(ctx,
@@ -462,8 +466,8 @@ HandlePtrBtn(struct xkb_context *ctx, const struct xkb_mod_set *mods,
             return ReportActionNotArray(ctx, action->type, field);
 
         if (!ExprResolveButton(ctx, value, &btn))
-            return ReportMismatch(ctx, action->type, field,
-                                  "integer (range 1..5)");
+            return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, action->type,
+                                  field, "integer (range 1..5)");
 
         if (btn < 0 || btn > 5) {
             log_err(ctx,
@@ -487,7 +491,8 @@ HandlePtrBtn(struct xkb_context *ctx, const struct xkb_mod_set *mods,
             return ReportActionNotArray(ctx, action->type, field);
 
         if (!ExprResolveInteger(ctx, value, &val))
-            return ReportMismatch(ctx, action->type, field, "integer");
+            return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, action->type,
+                                  field, "integer");
 
         if (val < 0 || val > 255) {
             log_err(ctx,
@@ -524,8 +529,8 @@ HandleSetPtrDflt(struct xkb_context *ctx, const struct xkb_mod_set *mods,
             return ReportActionNotArray(ctx, action->type, field);
 
         if (!ExprResolveEnum(ctx, value, &val, ptrDflts))
-            return ReportMismatch(ctx, action->type, field,
-                                  "pointer component");
+            return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, action->type,
+                                  field, "pointer component");
         return true;
     }
     else if (field == ACTION_FIELD_BUTTON || field == ACTION_FIELD_VALUE) {
@@ -546,8 +551,8 @@ HandleSetPtrDflt(struct xkb_context *ctx, const struct xkb_mod_set *mods,
         }
 
         if (!ExprResolveButton(ctx, button, &btn))
-            return ReportMismatch(ctx, action->type, field,
-                                  "integer (range 1..5)");
+            return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, action->type,
+                                  field, "integer (range 1..5)");
 
         if (btn < 0 || btn > 5) {
             log_err(ctx,
@@ -594,8 +599,8 @@ HandleSwitchScreen(struct xkb_context *ctx, const struct xkb_mod_set *mods,
         }
 
         if (!ExprResolveInteger(ctx, scrn, &val))
-            return ReportMismatch(ctx, action->type, field,
-                                  "integer (0..255)");
+            return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, action->type,
+                                  field, "integer (0..255)");
 
         if (val < 0 || val > 255) {
             log_err(ctx,
@@ -630,8 +635,8 @@ HandleSetLockControls(struct xkb_context *ctx, const struct xkb_mod_set *mods,
             return ReportActionNotArray(ctx, action->type, field);
 
         if (!ExprResolveMask(ctx, value, &mask, ctrlMaskNames))
-            return ReportMismatch(ctx, action->type, field,
-                                  "controls mask");
+            return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, action->type,
+                                  field, "controls mask");
 
         act->ctrls = mask;
         return true;
@@ -658,7 +663,8 @@ HandlePrivate(struct xkb_context *ctx, const struct xkb_mod_set *mods,
             return ReportActionNotArray(ctx, action->type, field);
 
         if (!ExprResolveInteger(ctx, value, &type))
-            return ReportMismatch(ctx, ACTION_TYPE_PRIVATE, field, "integer");
+            return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE,
+                                  ACTION_TYPE_PRIVATE, field, "integer");
 
         if (type < 0 || type > 255) {
             log_err(ctx,
@@ -696,7 +702,8 @@ HandlePrivate(struct xkb_context *ctx, const struct xkb_mod_set *mods,
             size_t len;
 
             if (!ExprResolveString(ctx, value, &val))
-                return ReportMismatch(ctx, action->type, field, "string");
+                return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE,
+                                      action->type, field, "string");
 
             str = xkb_atom_text(ctx, val);
             len = strlen(str);
@@ -731,7 +738,8 @@ HandlePrivate(struct xkb_context *ctx, const struct xkb_mod_set *mods,
             }
 
             if (!ExprResolveInteger(ctx, value, &datum))
-                return ReportMismatch(ctx, act->type, field, "integer");
+                return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, act->type,
+                                      field, "integer");
 
             if (datum < 0 || datum > 255) {
                 log_err(ctx,
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index b8922c9..121f5f2 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -124,7 +124,8 @@ static inline bool
 ReportSIBadType(CompatInfo *info, SymInterpInfo *si, const char *field,
                 const char *wanted)
 {
-    return ReportBadType(info->ctx, "symbol interpretation", field,
+    return ReportBadType(info->ctx, XKB_ERROR_WRONG_FIELD_TYPE,
+                         "symbol interpretation", field,
                          siText(si, info), wanted);
 }
 
@@ -132,7 +133,8 @@ static inline bool
 ReportLedBadType(CompatInfo *info, LedInfo *ledi, const char *field,
                  const char *wanted)
 {
-    return ReportBadType(info->ctx, "indicator map", field,
+    return ReportBadType(info->ctx, XKB_ERROR_WRONG_FIELD_TYPE,
+                         "indicator map", field,
                          xkb_atom_text(info->ctx, ledi->led.name),
                          wanted);
 }
diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c
index bbdf038..f935ce6 100644
--- a/src/xkbcomp/expr.c
+++ b/src/xkbcomp/expr.c
@@ -407,8 +407,9 @@ ExprResolveGroup(struct xkb_context *ctx, const ExprDef *expr,
         return false;
 
     if (result <= 0 || result > XKB_MAX_GROUPS) {
-        log_err(ctx, "Group index %u is out of range (1..%d)\n",
-                result, XKB_MAX_GROUPS);
+        log_err_with_code(ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX,
+                          "Group index %u is out of range (1..%d)\n",
+                          result, XKB_MAX_GROUPS);
         return false;
     }
 
@@ -429,7 +430,8 @@ ExprResolveLevel(struct xkb_context *ctx, const ExprDef *expr,
         return false;
 
     if (result < 1) {
-        log_err(ctx, "Shift level %d is out of range\n", result);
+        log_err_with_code(ctx, XKB_ERROR_UNSUPPORTED_SHIFT_LEVEL,
+                          "Shift level %d is out of range\n", result);
         return false;
     }
 
@@ -658,8 +660,9 @@ ExprResolveKeySym(struct xkb_context *ctx, const ExprDef *expr,
         return false;
 
     if (val < XKB_KEYSYM_MIN) {
-        log_warn(ctx, "unrecognized keysym \"-0x%x\" (%d)\n",
-                 (unsigned int) -val, val);
+        log_warn_with_code(ctx, XKB_WARNING_UNRECOGNIZED_KEYSYM,
+                           "unrecognized keysym \"-0x%x\" (%d)\n",
+                           (unsigned int) -val, val);
         return false;
     }
 
@@ -674,7 +677,9 @@ ExprResolveKeySym(struct xkb_context *ctx, const ExprDef *expr,
         return true;
     }
 
-    log_warn(ctx, "unrecognized keysym \"0x%x\" (%d)\n", val, val);
+    log_warn_with_code(ctx, XKB_WARNING_UNRECOGNIZED_KEYSYM,
+                       "unrecognized keysym \"0x%x\" (%d)\n",
+                       (unsigned int) val, val);
     return false;
 
 }
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index b8abf36..35c84b7 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -472,7 +472,8 @@ HandleLedNameDef(KeyNamesInfo *info, LedNameDef *def,
         char buf[20];
         snprintf(buf, sizeof(buf), "%u", def->ndx);
         info->errorCount++;
-        return ReportBadType(info->ctx, "indicator", "name", buf, "string");
+        return ReportBadType(info->ctx, XKB_ERROR_WRONG_FIELD_TYPE,
+                             "indicator", "name", buf, "string");
     }
 
     ledi.merge = merge;
diff --git a/src/xkbcomp/parser.y b/src/xkbcomp/parser.y
index 7cf2039..1beb30b 100644
--- a/src/xkbcomp/parser.y
+++ b/src/xkbcomp/parser.y
@@ -46,16 +46,16 @@ struct parser_param {
     bool more_maps;
 };
 
-#define parser_err(param, fmt, ...) \
-    scanner_err((param)->scanner, fmt, ##__VA_ARGS__)
+#define parser_err(param, error_id, fmt, ...) \
+    scanner_err_with_code((param)->scanner, error_id, fmt, ##__VA_ARGS__)
 
-#define parser_warn(param, fmt, ...) \
-    scanner_warn((param)->scanner, fmt, ##__VA_ARGS__)
+#define parser_warn(param, warning_id, fmt, ...) \
+    scanner_warn_with_code((param)->scanner, warning_id, fmt, ##__VA_ARGS__)
 
 static void
 _xkbcommon_error(struct parser_param *param, const char *msg)
 {
-    parser_err(param, "%s", msg);
+    parser_err(param, XKB_ERROR_INVALID_SYNTAX, "%s", msg);
 }
 
 static bool
@@ -728,7 +728,12 @@ KeySyms         :       OBRACE KeySymList CBRACE
 KeySym          :       IDENT
                         {
                             if (!resolve_keysym($1, &$$)) {
-                                parser_warn(param, "unrecognized keysym \"%s\"", $1);
+                                parser_warn(
+                                    param,
+                                    XKB_WARNING_UNRECOGNIZED_KEYSYM,
+                                    "unrecognized keysym \"%s\"",
+                                    $1
+                                );
                                 $$ = XKB_KEY_NoSymbol;
                             }
                             free($1);
@@ -737,7 +742,12 @@ KeySym          :       IDENT
                 |       Integer
                         {
                             if ($1 < XKB_KEYSYM_MIN) {
-                                parser_warn(param, "unrecognized keysym \"%"PRId64"\"", $1);
+                                parser_warn(
+                                    param,
+                                    XKB_WARNING_UNRECOGNIZED_KEYSYM,
+                                    "unrecognized keysym \"%"PRId64"\"",
+                                    $1
+                                );
                                 $$ = XKB_KEY_NoSymbol;
                             }
                             /* Special case for digits 0..9 */
@@ -748,7 +758,11 @@ KeySym          :       IDENT
                                 if ($1 <= XKB_KEYSYM_MAX) {
                                     $$ = (xkb_keysym_t) $1;
                                 } else {
-                                    parser_warn(param, "unrecognized keysym \"0x%"PRIx64"\"", $1);
+                                    parser_warn(
+                                        param, XKB_WARNING_UNRECOGNIZED_KEYSYM,
+                                        "unrecognized keysym \"0x%"PRIx64"\" "
+                                        "(%"PRId64")", $1, $1
+                                    );
                                     $$ = XKB_KEY_NoSymbol;
                                 }
                             }
diff --git a/src/xkbcomp/scanner.c b/src/xkbcomp/scanner.c
index e502216..e78f102 100644
--- a/src/xkbcomp/scanner.c
+++ b/src/xkbcomp/scanner.c
@@ -100,7 +100,10 @@ skip_more_whitespace_and_comments:
                 else if (scanner_chr(s, 'e'))  scanner_buf_append(s, '\033');
                 else if (scanner_oct(s, &o))   scanner_buf_append(s, (char) o);
                 else {
-                    scanner_warn(s, "unknown escape sequence in string literal");
+                    // TODO: display actual sequence! See: scanner_peek(s).
+                    //       require escaping any potential control character
+                    scanner_warn_with_code(s, XKB_WARNING_UNKNOWN_CHAR_ESCAPE_SEQUENCE,
+                                           "unknown escape sequence in string literal");
                     /* Ignore. */
                 }
             } else {
@@ -171,7 +174,8 @@ skip_more_whitespace_and_comments:
     /* Number literal (hexadecimal / decimal / float). */
     if (number(s, &yylval->num, &tok)) {
         if (tok == ERROR_TOK) {
-            scanner_err(s, "malformed number literal");
+            scanner_err_with_code(s, XKB_ERROR_MALFORMED_NUMBER_LITERAL,
+                                  "malformed number literal");
             return ERROR_TOK;
         }
         return tok;
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index f990529..e438139 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -61,6 +61,10 @@
 #include "include.h"
 #include "keysym.h"
 
+
+// TODO: convert log_err to log_err_with_code
+// TODO: convert log_vrb to log_vrb_with_code
+
 enum key_repeat {
     KEY_REPEAT_UNDEFINED = 0,
     KEY_REPEAT_YES = 1,
@@ -240,13 +244,15 @@ MergeGroups(SymbolsInfo *info, GroupInfo *into, GroupInfo *from, bool clobber,
             xkb_atom_t use = (clobber ? from->type : into->type);
             xkb_atom_t ignore = (clobber ? into->type : from->type);
 
-            if (report)
-                log_warn(info->ctx,
+            if (report) {
+                log_warn_with_code(info->ctx,
+                         XKB_WARNING_CONFLICTING_KEY_TYPE,
                          "Multiple definitions for group %d type of key %s; "
                          "Using %s, ignoring %s\n",
                          group + 1, KeyNameText(info->ctx, key_name),
                          xkb_atom_text(info->ctx, use),
                          xkb_atom_text(info->ctx, ignore));
+            }
 
             into->type = use;
         }
@@ -284,13 +290,15 @@ MergeGroups(SymbolsInfo *info, GroupInfo *into, GroupInfo *from, bool clobber,
             use = (clobber ? &fromLevel->action : &intoLevel->action);
             ignore = (clobber ? &intoLevel->action : &fromLevel->action);
 
-            if (report)
-                log_warn(info->ctx,
+            if (report) {
+                log_warn_with_code(info->ctx,
+                         XKB_WARNING_CONFLICTING_KEY_ACTION,
                          "Multiple actions for level %d/group %u on key %s; "
                          "Using %s, ignoring %s\n",
                          i + 1, group + 1, KeyNameText(info->ctx, key_name),
                          ActionTypeText(use->type),
                          ActionTypeText(ignore->type));
+            }
 
             intoLevel->action = *use;
         }
@@ -307,13 +315,15 @@ MergeGroups(SymbolsInfo *info, GroupInfo *into, GroupInfo *from, bool clobber,
             fromLevel->num_syms = 0;
         }
         else if (!XkbLevelsSameSyms(fromLevel, intoLevel)) {
-            if (report)
-                log_warn(info->ctx,
+            if (report) {
+                log_warn_with_code(info->ctx,
+                         XKB_WARNING_CONFLICTING_KEY_SYMBOL,
                          "Multiple symbols for level %d/group %u on key %s; "
                          "Using %s, ignoring %s\n",
                          i + 1, group + 1, KeyNameText(info->ctx, key_name),
                          (clobber ? "from" : "to"),
                          (clobber ? "to" : "from"));
+            }
 
             if (clobber) {
                 ClearLevelInfo(intoLevel);
@@ -406,12 +416,14 @@ MergeKeys(SymbolsInfo *info, KeyInfo *into, KeyInfo *from, bool same_file)
         into->defined |= KEY_FIELD_GROUPINFO;
     }
 
-    if (collide)
-        log_warn(info->ctx,
+    if (collide) {
+        log_warn_with_code(info->ctx,
+                 XKB_WARNING_CONFLICTING_KEY_FIELDS,
                  "Symbol map for key %s redefined; "
                  "Using %s definition for conflicting fields\n",
                  KeyNameText(info->ctx, into->name),
                  (clobber ? "first" : "last"));
+    }
 
     ClearKeyInfo(from);
     InitKeyInfo(info->ctx, from);
@@ -464,21 +476,23 @@ AddModMapEntry(SymbolsInfo *info, ModMapEntry *new)
         use = (clobber ? new->modifier : old->modifier);
         ignore = (clobber ? old->modifier : new->modifier);
 
-        if (new->haveSymbol)
-            log_warn(info->ctx,
+        if (new->haveSymbol) {
+            log_warn_with_code(info->ctx,
+                     XKB_WARNING_CONFLICTING_MODMAP,
                      "Symbol \"%s\" added to modifier map for multiple modifiers; "
                      "Using %s, ignoring %s\n",
                      KeysymText(info->ctx, new->u.keySym),
                      ModIndexText(info->ctx, &info->mods, use),
                      ModIndexText(info->ctx, &info->mods, ignore));
-        else
-            log_warn(info->ctx,
+        } else {
+            log_warn_with_code(info->ctx,
+                     XKB_WARNING_CONFLICTING_MODMAP,
                      "Key \"%s\" added to modifier map for multiple modifiers; "
                      "Using %s, ignoring %s\n",
                      KeyNameText(info->ctx, new->u.keyName),
                      ModIndexText(info->ctx, &info->mods, use),
                      ModIndexText(info->ctx, &info->mods, ignore));
-
+        }
         old->modifier = use;
         return true;
     }
@@ -639,7 +653,7 @@ GetGroupIndex(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
     }
 
     if (!ExprResolveGroup(info->ctx, arrayNdx, ndx_rtrn)) {
-        log_err(info->ctx,
+        log_err_with_code(info->ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX,
                 "Illegal group index for %s of key %s\n"
                 "Definition with non-integer array index ignored\n",
                 name, KeyInfoText(info, keyi));
@@ -812,7 +826,7 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
             keyi->defined |= KEY_FIELD_DEFAULT_TYPE;
         }
         else if (!ExprResolveGroup(info->ctx, arrayNdx, &ndx)) {
-            log_err(info->ctx,
+            log_err_with_code(info->ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX,
                     "Illegal group index for type of key %s; "
                     "Definition with non-integer array index ignored\n",
                     KeyInfoText(info, keyi));
@@ -924,7 +938,7 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
         xkb_layout_index_t grp;
 
         if (!ExprResolveGroup(info->ctx, value, &grp)) {
-            log_err(info->ctx,
+            log_err_with_code(info->ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX,
                     "Illegal group index for redirect of key %s; "
                     "Definition with non-integer group ignored\n",
                     KeyInfoText(info, keyi));
@@ -960,7 +974,7 @@ SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value)
     }
 
     if (!ExprResolveGroup(info->ctx, arrayNdx, &group)) {
-        log_err(info->ctx,
+        log_err_with_code(info->ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX,
                 "Illegal index in group name definition; "
                 "Definition with non-integer array index ignored\n");
         return false;
@@ -980,7 +994,8 @@ SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value)
         group_to_use = info->explicit_group;
     }
     else {
-        log_warn(info->ctx,
+        log_warn_with_code(info->ctx,
+                 XKB_WARNING_NON_BASE_GROUP_NAME,
                  "An explicit group was specified for the '%s' map, "
                  "but it provides a name for a group other than Group1 (%d); "
                  "Ignoring group name '%s'\n",
@@ -1098,12 +1113,14 @@ SetExplicitGroup(SymbolsInfo *info, KeyInfo *keyi)
         }
     }
 
-    if (warn)
-        log_warn(info->ctx,
+    if (warn) {
+        log_warn_with_code(info->ctx,
+                 XKB_WARNING_MULTIPLE_GROUPS_AT_ONCE,
                  "For the map %s an explicit group specified, "
                  "but key %s has more than one group defined; "
                  "All groups except first one will be ignored\n",
                  info->name, KeyInfoText(info, keyi));
+    }
 
     darray_resize0(keyi->groups, info->explicit_group + 1);
     if (info->explicit_group > 0) {
@@ -1371,7 +1388,8 @@ FindTypeForGroup(struct xkb_keymap *keymap, KeyInfo *keyi,
     }
 
     if (type_name == XKB_ATOM_NONE) {
-        log_warn(keymap->ctx,
+        log_warn_with_code(keymap->ctx,
+                 XKB_WARNING_CANNOT_INFER_KEY_TYPE,
                  "Couldn't find an automatic type for key '%s' group %d with %lu levels; "
                  "Using the default type\n",
                  KeyNameText(keymap->ctx, keyi->name), group + 1,
@@ -1384,7 +1402,8 @@ FindTypeForGroup(struct xkb_keymap *keymap, KeyInfo *keyi,
             break;
 
     if (i >= keymap->num_types) {
-        log_warn(keymap->ctx,
+        log_warn_with_code(keymap->ctx,
+                 XKB_WARNING_UNDEFINED_KEY_TYPE,
                  "The type \"%s\" for key '%s' group %d was not previously defined; "
                  "Using the default type\n",
                  xkb_atom_text(keymap->ctx, type_name),
@@ -1417,7 +1436,8 @@ CopySymbolsDefToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info,
      */
     key = XkbKeyByName(keymap, keyi->name, false);
     if (!key) {
-        log_vrb(info->ctx, 5,
+        log_vrb_with_code(info->ctx, 5,
+                XKB_WARNING_UNDEFINED_KEYCODE,
                 "Key %s not found in keycodes; Symbols ignored\n",
                 KeyInfoText(info, keyi));
         return false;
@@ -1460,7 +1480,8 @@ CopySymbolsDefToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info,
         if (type->num_levels < darray_size(groupi->levels)) {
             struct xkb_level *leveli;
 
-            log_vrb(info->ctx, 1,
+            log_vrb_with_code(info->ctx, 1,
+                    XKB_WARNING_EXTRA_SYMBOLS_IGNORED,
                     "Type \"%s\" has %d levels, but %s has %d levels; "
                     "Ignoring extra symbols\n",
                     xkb_atom_text(keymap->ctx, type->name), type->num_levels,
@@ -1512,7 +1533,8 @@ CopyModMapDefToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info,
     if (!entry->haveSymbol) {
         key = XkbKeyByName(keymap, entry->u.keyName, true);
         if (!key) {
-            log_vrb(info->ctx, 5,
+            log_vrb_with_code(info->ctx, 5,
+                    XKB_WARNING_UNDEFINED_KEYCODE,
                     "Key %s not found in keycodes; "
                     "Modifier map entry for %s not updated\n",
                     KeyNameText(info->ctx, entry->u.keyName),
@@ -1523,7 +1545,8 @@ CopyModMapDefToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info,
     else {
         key = FindKeyForSymbol(keymap, entry->u.keySym);
         if (!key) {
-            log_vrb(info->ctx, 5,
+            log_vrb_with_code(info->ctx, 5,
+                    XKB_WARNING_UNRESOLVED_KEYMAP_SYMBOL,
                     "Key \"%s\" not found in symbol map; "
                     "Modifier map entry for %s not updated\n",
                     KeysymText(info->ctx, entry->u.keySym),
diff --git a/src/xkbcomp/types.c b/src/xkbcomp/types.c
index 3feaf41..e8e82df 100644
--- a/src/xkbcomp/types.c
+++ b/src/xkbcomp/types.c
@@ -89,10 +89,10 @@ ReportTypeShouldBeArray(KeyTypesInfo *info, KeyTypeInfo *type,
 }
 
 static inline bool
-ReportTypeBadType(KeyTypesInfo *info, KeyTypeInfo *type,
-                  const char *field, const char *wanted)
+ReportTypeBadType(KeyTypesInfo *info, xkb_message_code_t code,
+                  KeyTypeInfo *type, const char *field, const char *wanted)
 {
-    return ReportBadType(info->ctx, "key type", field,
+    return ReportBadType(info->ctx, code, "key type", field,
                          TypeTxt(info, type), wanted);
 }
 
@@ -340,7 +340,8 @@ SetMapEntry(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
 
     if (!ExprResolveModMask(info->ctx, arrayNdx, MOD_BOTH, &info->mods,
                             &entry.mods.mods))
-        return ReportTypeBadType(info, type, "map entry", "modifier mask");
+        return ReportTypeBadType(info, XKB_ERROR_UNSUPPORTED_MODIFIER_MASK,
+                                 type, "map entry", "modifier mask");
 
     if (entry.mods.mods & (~type->mods)) {
         log_vrb(info->ctx, 1,
@@ -354,9 +355,9 @@ SetMapEntry(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
     }
 
     if (!ExprResolveLevel(info->ctx, value, &entry.level)) {
-        log_err(info->ctx,
-                "Level specifications in a key type must be integer; "
-                "Ignoring malformed level specification\n");
+        log_err_with_code(info->ctx, XKB_ERROR_UNSUPPORTED_SHIFT_LEVEL,
+                          "Level specifications in a key type must be integer; "
+                          "Ignoring malformed level specification\n");
         return false;
     }
 
@@ -429,8 +430,8 @@ SetPreserve(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
         return ReportTypeShouldBeArray(info, type, "preserve entry");
 
     if (!ExprResolveModMask(info->ctx, arrayNdx, MOD_BOTH, &info->mods, &mods))
-        return ReportTypeBadType(info, type, "preserve entry",
-                                 "modifier mask");
+        return ReportTypeBadType(info, XKB_ERROR_UNSUPPORTED_MODIFIER_MASK,
+                                 type, "preserve entry", "modifier mask");
 
     if (mods & ~type->mods) {
         const char *before, *after;
@@ -526,7 +527,8 @@ SetLevelName(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
         return ReportTypeShouldBeArray(info, type, "level name");
 
     if (!ExprResolveLevel(info->ctx, arrayNdx, &level))
-        return ReportTypeBadType(info, type, "level name", "integer");
+        return ReportTypeBadType(info, XKB_ERROR_UNSUPPORTED_SHIFT_LEVEL,
+                                 type, "level name", "integer");
 
     if (!ExprResolveString(info->ctx, value, &level_name)) {
         log_err(info->ctx,
diff --git a/src/xkbcomp/xkbcomp-priv.h b/src/xkbcomp/xkbcomp-priv.h
index 6cb774d..5a7765f 100644
--- a/src/xkbcomp/xkbcomp-priv.h
+++ b/src/xkbcomp/xkbcomp-priv.h
@@ -101,10 +101,10 @@ ReportShouldBeArray(struct xkb_context *ctx, const char *type,
 }
 
 static inline bool
-ReportBadType(struct xkb_context *ctx, const char *type, const char *field,
-              const char *name, const char *wanted)
+ReportBadType(struct xkb_context *ctx, xkb_message_code_t code, const char *type,
+              const char *field, const char *name, const char *wanted)
 {
-    log_err(ctx, "The %s %s field must be a %s; "
+    log_err_with_code(ctx, code, "The %s %s field must be a %s; "
             "Ignoring illegal assignment in %s\n",
             type, field, wanted, name);
     return false;