mirror of
https://github.com/gabime/spdlog.git
synced 2026-01-02 09:57:55 +08:00
Compare commits
2744 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b91b06917 | ||
|
|
fb9eb1e3ec | ||
|
|
a4fd3a73f0 | ||
|
|
4b8483c9d2 | ||
|
|
d5c3b5fc2c | ||
|
|
38f4339e77 | ||
|
|
31984a2fca | ||
|
|
7c8a866006 | ||
|
|
7ff6dd716c | ||
|
|
08a9604a57 | ||
|
|
f467be8edb | ||
|
|
ffbb35368d | ||
|
|
7dfb474632 | ||
|
|
2ef467be7d | ||
|
|
adaf0554be | ||
|
|
04004e57c2 | ||
|
|
3d83e402ca | ||
|
|
83c9ede9e6 | ||
|
|
166843ff3a | ||
|
|
ed6919bf8e | ||
|
|
08c727e4f8 | ||
|
|
daf1b97b8f | ||
|
|
e62be8b43f | ||
|
|
58dac85596 | ||
|
|
1379f68bda | ||
|
|
2f169568b7 | ||
|
|
fe9be2e1ee | ||
|
|
730aa35d98 | ||
|
|
19d1939d3b | ||
|
|
82153ec409 | ||
|
|
98a8b75eb4 | ||
|
|
96195adaad | ||
|
|
75c8a196bb | ||
|
|
17eb1e1fd7 | ||
|
|
2a0db06e7b | ||
|
|
dcf664ee1d | ||
|
|
65a2d8a49f | ||
|
|
c55e7f6d14 | ||
|
|
3b6f36c43b | ||
|
|
3b7e2a034b | ||
|
|
3c9963a495 | ||
|
|
21e0810791 | ||
|
|
e6cddd1028 | ||
|
|
a0f371efed | ||
|
|
032d93acf7 | ||
|
|
e26e3692d1 | ||
|
|
551860d079 | ||
|
|
0d8f1f1dd4 | ||
|
|
7a0e2ff8a8 | ||
|
|
ec34d6ddc6 | ||
|
|
70c65cf61b | ||
|
|
9f5611c146 | ||
|
|
82bb5114e2 | ||
|
|
3566e0f027 | ||
|
|
912491d307 | ||
|
|
dba5d7d214 | ||
|
|
c9b96bc974 | ||
|
|
aa9eaae6f6 | ||
|
|
50f3c88694 | ||
|
|
03e20348e2 | ||
|
|
693062a8bf | ||
|
|
bb4b719ccf | ||
|
|
92d83f3219 | ||
|
|
2057f67015 | ||
|
|
fefda8dd15 | ||
|
|
7fe73d96b9 | ||
|
|
ddf14d67df | ||
|
|
0ef49d7df6 | ||
|
|
bb3d25b626 | ||
|
|
15814dba5b | ||
|
|
eccaa62e9d | ||
|
|
63535f140b | ||
|
|
9fea0e5fa8 | ||
|
|
7c6f737990 | ||
|
|
1d2138fdbe | ||
|
|
0641ddec58 | ||
|
|
fb3969d540 | ||
|
|
62534f2e4e | ||
|
|
eacd4d6b2a | ||
|
|
14a202580b | ||
|
|
f20fe2a121 | ||
|
|
50ea0cc1aa | ||
|
|
6ea6b065ba | ||
|
|
c7fc302710 | ||
|
|
64a013fd16 | ||
|
|
9c1b76fe72 | ||
|
|
3fc14822ef | ||
|
|
968dcfbc6b | ||
|
|
67628a459a | ||
|
|
89a01c4bba | ||
|
|
5c4f5f42c8 | ||
|
|
9dab02aa2c | ||
|
|
4b301e710a | ||
|
|
fba921b6d8 | ||
|
|
79422fe1dc | ||
|
|
905312eadd | ||
|
|
24afd40000 | ||
|
|
7c6512ff72 | ||
|
|
850ee25648 | ||
|
|
30f0681ab4 | ||
|
|
d808eb8eca | ||
|
|
419b4bd983 | ||
|
|
1d66ca8c0b | ||
|
|
d94311ad6b | ||
|
|
c122eaf749 | ||
|
|
0e95bba098 | ||
|
|
496c5fd145 | ||
|
|
8563a6ab59 | ||
|
|
e4d81a5be9 | ||
|
|
eab1f6d5f5 | ||
|
|
4effc91705 | ||
|
|
a3d3df0a56 | ||
|
|
15fcde8ee3 | ||
|
|
e01fa1a5fd | ||
|
|
04bd12e0b5 | ||
|
|
a2de13630b | ||
|
|
c1f101af13 | ||
|
|
8d9283d790 | ||
|
|
754be3eec6 | ||
|
|
5884f4de2a | ||
|
|
8888f5875e | ||
|
|
dec6a3f61f | ||
|
|
ffa651d39a | ||
|
|
f9566a0101 | ||
|
|
9df7863b95 | ||
|
|
085e1330d0 | ||
|
|
5559847331 | ||
|
|
dc24a858f2 | ||
|
|
7ea98fba29 | ||
|
|
8d81cca86c | ||
|
|
06be4409e6 | ||
|
|
15829cfb84 | ||
|
|
4ee50804d3 | ||
|
|
587b7dad28 | ||
|
|
01646c54d3 | ||
|
|
d896daec63 | ||
|
|
d60a4c7b50 | ||
|
|
f0b96d2ad1 | ||
|
|
aefd4510c3 | ||
|
|
8d6a121b73 | ||
|
|
02c3ca5016 | ||
|
|
8815f81e5d | ||
|
|
a627f5c43a | ||
|
|
390428aae1 | ||
|
|
1bde4831a0 | ||
|
|
8f526df1a9 | ||
|
|
e1f5a45900 | ||
|
|
b95e493471 | ||
|
|
4a31ed38d3 | ||
|
|
06e4631dde | ||
|
|
e750d2219e | ||
|
|
8a4f3b1ba7 | ||
|
|
ca7c846089 | ||
|
|
232aace328 | ||
|
|
50d7f59951 | ||
|
|
5a207ad9ce | ||
|
|
87b8401011 | ||
|
|
8e10782a58 | ||
|
|
167bf989d8 | ||
|
|
dd8dc8105a | ||
|
|
c577b54b06 | ||
|
|
a145ba62b8 | ||
|
|
c923915805 | ||
|
|
276788a60e | ||
|
|
e9938a8839 | ||
|
|
34e0c8f227 | ||
|
|
989589dd0b | ||
|
|
8319d1bc16 | ||
|
|
c8b81a6958 | ||
|
|
7bd1c1e1a4 | ||
|
|
57384f7be3 | ||
|
|
bb687e7aad | ||
|
|
7bb480a051 | ||
|
|
286218aeeb | ||
|
|
b05d9362ea | ||
|
|
95587b7601 | ||
|
|
f743a881b2 | ||
|
|
5370076dcc | ||
|
|
69d412b526 | ||
|
|
77d350af57 | ||
|
|
9622d7f318 | ||
|
|
e96cb12df6 | ||
|
|
0992a41053 | ||
|
|
fbd1ebcebf | ||
|
|
d61f0a5d5e | ||
|
|
9294adb335 | ||
|
|
885b796447 | ||
|
|
3954caccc1 | ||
|
|
6c799d04f8 | ||
|
|
aaebfbb5c6 | ||
|
|
91bf60a316 | ||
|
|
ce3922cff1 | ||
|
|
c539f36551 | ||
|
|
eaab457156 | ||
|
|
d513f44a18 | ||
|
|
83d274eb55 | ||
|
|
26b6461b24 | ||
|
|
e6e2ffbf51 | ||
|
|
32d83ee246 | ||
|
|
3834b911cd | ||
|
|
efa89d0880 | ||
|
|
287d83acae | ||
|
|
aa5d9aff6c | ||
|
|
1ce7f5e499 | ||
|
|
947b42b86f | ||
|
|
e2e8099ad9 | ||
|
|
f70670d26c | ||
|
|
77b07b3a10 | ||
|
|
4789065700 | ||
|
|
24fe442d03 | ||
|
|
feaab0dd9f | ||
|
|
a3e05332b0 | ||
|
|
45b100c677 | ||
|
|
3379f242e1 | ||
|
|
ae0eb75402 | ||
|
|
944a542769 | ||
|
|
2a4aa8f2d1 | ||
|
|
68e71cfc49 | ||
|
|
7e3700f650 | ||
|
|
70f397f75d | ||
|
|
306ddde049 | ||
|
|
8c3ff3a0c4 | ||
|
|
4813a123fa | ||
|
|
f4204e05bd | ||
|
|
90c5055b77 | ||
|
|
8a0f87406b | ||
|
|
3b93c53e33 | ||
|
|
3fe640e270 | ||
|
|
ffbdc8f610 | ||
|
|
ea66477ac0 | ||
|
|
c6206a3191 | ||
|
|
d0c30a6a5c | ||
|
|
15ee3f7999 | ||
|
|
235e12c67e | ||
|
|
d10bef50d9 | ||
|
|
d03d514bad | ||
|
|
1161d640a1 | ||
|
|
f9c9f5cb6a | ||
|
|
eb7d87685b | ||
|
|
8590436aaf | ||
|
|
9797b353c0 | ||
|
|
d53e8abc74 | ||
|
|
efcca400bf | ||
|
|
83d5f3dbad | ||
|
|
bc7e80c7ae | ||
|
|
70f7a8252d | ||
|
|
5782891494 | ||
|
|
959244b3cd | ||
|
|
82a672a4d3 | ||
|
|
ecb29c4f99 | ||
|
|
ec523b967c | ||
|
|
ef10d4b636 | ||
|
|
c10acd23ce | ||
|
|
b1b6a22955 | ||
|
|
7ba9a04fae | ||
|
|
0fd0e13d21 | ||
|
|
f5c927b46e | ||
|
|
69dd70e31a | ||
|
|
5309ddb702 | ||
|
|
61b11e77b9 | ||
|
|
bd00a0081a | ||
|
|
57868277db | ||
|
|
754838c558 | ||
|
|
eb256827f1 | ||
|
|
2b88112c36 | ||
|
|
9b3a4e28c5 | ||
|
|
cc343cd168 | ||
|
|
08648e58ad | ||
|
|
2a101ac559 | ||
|
|
9a7a9f6871 | ||
|
|
9390881046 | ||
|
|
a8efa85b86 | ||
|
|
2fb5e75950 | ||
|
|
af8354575d | ||
|
|
9163bbde14 | ||
|
|
837fb9b155 | ||
|
|
5abca1748f | ||
|
|
8dc7ba7e3d | ||
|
|
b169859ce9 | ||
|
|
c7b60db679 | ||
|
|
c542ef5457 | ||
|
|
4f36d1933a | ||
|
|
857158d5d9 | ||
|
|
2bdddc61e8 | ||
|
|
463af69d41 | ||
|
|
a0e631802c | ||
|
|
a3934472c9 | ||
|
|
c1ffe29b7e | ||
|
|
976d3d20b6 | ||
|
|
0773e11883 | ||
|
|
4bb3b56102 | ||
|
|
967554e4c5 | ||
|
|
605f037e4e | ||
|
|
030bcb8890 | ||
|
|
60457b6794 | ||
|
|
6eef69e4ac | ||
|
|
7ac740a029 | ||
|
|
6dffd7c6e8 | ||
|
|
968048ced6 | ||
|
|
f36b2c5f93 | ||
|
|
1800775b9d | ||
|
|
dcd5904bdc | ||
|
|
218e859867 | ||
|
|
2ed4e161e0 | ||
|
|
84bee1d484 | ||
|
|
d1a47cd553 | ||
|
|
2896bbe77d | ||
|
|
1797166190 | ||
|
|
6de0ffa15f | ||
|
|
66de161355 | ||
|
|
96403787f7 | ||
|
|
5e59b396b0 | ||
|
|
e28eadcd52 | ||
|
|
5654205d6b | ||
|
|
f3bf9e78c3 | ||
|
|
2a1959c2ce | ||
|
|
ab86471489 | ||
|
|
9d04001fbc | ||
|
|
425f137938 | ||
|
|
98dacff8e0 | ||
|
|
cff3e27115 | ||
|
|
6d520df916 | ||
|
|
fc81e0390b | ||
|
|
b16a8951bc | ||
|
|
a34fb3761c | ||
|
|
73eb6bc1f5 | ||
|
|
9448d74495 | ||
|
|
7d3b5a1b10 | ||
|
|
9a7448e4c8 | ||
|
|
433cac487e | ||
|
|
2d801bbd80 | ||
|
|
7c0afada60 | ||
|
|
ea1c829764 | ||
|
|
e315bcb2a9 | ||
|
|
e63d110baa | ||
|
|
5683d16b36 | ||
|
|
7d9cf59649 | ||
|
|
31a7dc6e1e | ||
|
|
3a405ba958 | ||
|
|
392917f855 | ||
|
|
ac2955cb48 | ||
|
|
96bed42974 | ||
|
|
3d5ddea136 | ||
|
|
a3ef3ab7a4 | ||
|
|
25f64bcfb6 | ||
|
|
b777497b0d | ||
|
|
98415979d2 | ||
|
|
5c93f5ff34 | ||
|
|
9c1e1c85aa | ||
|
|
89ccf2a6ab | ||
|
|
8488b027e9 | ||
|
|
ad18d4e1cb | ||
|
|
3289e5ecae | ||
|
|
c0c1b49fa3 | ||
|
|
3979bd15f7 | ||
|
|
536da46a2c | ||
|
|
ce6bccb194 | ||
|
|
d8164fe398 | ||
|
|
768de091ee | ||
|
|
2718d4671b | ||
|
|
e1c7e6fde4 | ||
|
|
fb40b49ef0 | ||
|
|
fd91561734 | ||
|
|
4bb1c9589b | ||
|
|
82069b2455 | ||
|
|
767ef493f7 | ||
|
|
5ae1ace844 | ||
|
|
bcc24961a0 | ||
|
|
a7a537216c | ||
|
|
af2f24de07 | ||
|
|
5882bfd0ad | ||
|
|
3eea04bcd3 | ||
|
|
b19ceb6d0a | ||
|
|
cead430eed | ||
|
|
ef846a6502 | ||
|
|
75b1da2c12 | ||
|
|
90e92438c8 | ||
|
|
1faeb5b6fa | ||
|
|
501e3480ca | ||
|
|
b3ab35cf8e | ||
|
|
b2372fd076 | ||
|
|
1f2561c548 | ||
|
|
ac6b7ec87e | ||
|
|
f755cfc0e7 | ||
|
|
db76ab6c9f | ||
|
|
9d6dd2a691 | ||
|
|
19d4e60561 | ||
|
|
866744e40e | ||
|
|
75028b3d40 | ||
|
|
90127164de | ||
|
|
e6b894665c | ||
|
|
243a840da7 | ||
|
|
32b2fa8877 | ||
|
|
4965d6ef68 | ||
|
|
11770fc7e5 | ||
|
|
8f7400731e | ||
|
|
d8829e7714 | ||
|
|
55f84d458b | ||
|
|
a8b74096b2 | ||
|
|
aacea38f9d | ||
|
|
820baa886c | ||
|
|
202260719f | ||
|
|
647fc3ab56 | ||
|
|
39b6ead2bc | ||
|
|
bc3ef7d334 | ||
|
|
69149a3c76 | ||
|
|
5993e78aac | ||
|
|
7c054b6dba | ||
|
|
54d402e094 | ||
|
|
6a53d6354b | ||
|
|
a38add8456 | ||
|
|
e1ee0c62a7 | ||
|
|
d7db2cf3aa | ||
|
|
6cac90b89a | ||
|
|
2ecc00e9c6 | ||
|
|
92daf6954b | ||
|
|
d94830814f | ||
|
|
11ddcb2e91 | ||
|
|
f530b2dbaa | ||
|
|
213b2c0151 | ||
|
|
b4004586e0 | ||
|
|
27c518d509 | ||
|
|
ea6d8fde1d | ||
|
|
b9cb721b92 | ||
|
|
1d6dbc2a56 | ||
|
|
b5b5043d42 | ||
|
|
d109e1dcd0 | ||
|
|
a98d3ab0c7 | ||
|
|
8014d6c31a | ||
|
|
3aceda041b | ||
|
|
7d0531b076 | ||
|
|
47e04cf043 | ||
|
|
81ce5fcdb7 | ||
|
|
cedfeeb95f | ||
|
|
2312489bdc | ||
|
|
811bc4c7a9 | ||
|
|
1f8d36071e | ||
|
|
bffceb90b0 | ||
|
|
371bc8ebe2 | ||
|
|
2ee8bac78e | ||
|
|
d8d23a6606 | ||
|
|
76dfc7e7c0 | ||
|
|
7e635fca68 | ||
|
|
bed324e414 | ||
|
|
72a7ec3eb9 | ||
|
|
64ed6b495c | ||
|
|
4338b9cd23 | ||
|
|
b73616ce29 | ||
|
|
01b3724c48 | ||
|
|
4b8ff51a29 | ||
|
|
8b8bc20f30 | ||
|
|
3cd06a3d40 | ||
|
|
c3fa8f60e2 | ||
|
|
169f827957 | ||
|
|
62e55e7a7f | ||
|
|
b85c509ec6 | ||
|
|
b1eb4953fa | ||
|
|
5ece88e5a8 | ||
|
|
826d8ba4b2 | ||
|
|
326f8870c2 | ||
|
|
7990ed8f2b | ||
|
|
da1e671d42 | ||
|
|
a29cef5787 | ||
|
|
9ce7295191 | ||
|
|
36eb173030 | ||
|
|
ca44ce50ab | ||
|
|
91280df07e | ||
|
|
5a6b6cafa8 | ||
|
|
4f4da7f114 | ||
|
|
199cc0a6d8 | ||
|
|
4fb4e2bd86 | ||
|
|
c17b5d9cd1 | ||
|
|
3a7188505f | ||
|
|
32bab0e103 | ||
|
|
f0e1f22bbc | ||
|
|
1f61f5e019 | ||
|
|
31cefdce79 | ||
|
|
95b8ee9b32 | ||
|
|
d7985e3965 | ||
|
|
dfcb74b129 | ||
|
|
6a96c7f902 | ||
|
|
6940f4fd46 | ||
|
|
1f1897e3a4 | ||
|
|
0f50ad92d6 | ||
|
|
5384512f25 | ||
|
|
230cad163d | ||
|
|
3a6ee663ba | ||
|
|
931cd2fb54 | ||
|
|
8fdcf0365b | ||
|
|
32701af60b | ||
|
|
31cf79a70d | ||
|
|
d1eb68154f | ||
|
|
c174c15138 | ||
|
|
8222ca4837 | ||
|
|
62a4b8ce4e | ||
|
|
ea1af20840 | ||
|
|
1fba68bfe2 | ||
|
|
4c5ee9bb10 | ||
|
|
dd173bc544 | ||
|
|
fcc8a95a95 | ||
|
|
9fcf609b67 | ||
|
|
af1785b897 | ||
|
|
57a9fd0841 | ||
|
|
f9c24d9fa8 | ||
|
|
e4f92bed48 | ||
|
|
c65aa4e488 | ||
|
|
e539d6ae42 | ||
|
|
0ca574ae16 | ||
|
|
069a2e8fc9 | ||
|
|
42d1f40a18 | ||
|
|
040874224b | ||
|
|
706ad70591 | ||
|
|
1262a249a6 | ||
|
|
2a861d28bd | ||
|
|
febc1e233d | ||
|
|
763ff37348 | ||
|
|
2d57e3b57e | ||
|
|
b25aaecf6a | ||
|
|
d07e8cb576 | ||
|
|
bcd0a2b820 | ||
|
|
7f09c88817 | ||
|
|
150ba9e6dd | ||
|
|
8be5b41a2f | ||
|
|
ceb71825b2 | ||
|
|
2a6d3e9f3b | ||
|
|
6b67054071 | ||
|
|
13f45c531b | ||
|
|
937ce23537 | ||
|
|
60f5cb73a8 | ||
|
|
0e9ccd73ef | ||
|
|
839ea957ab | ||
|
|
262acfdeb5 | ||
|
|
a4d8817745 | ||
|
|
66407f5b48 | ||
|
|
4641347c3f | ||
|
|
51bcff820e | ||
|
|
7372596126 | ||
|
|
da14258533 | ||
|
|
927cc29444 | ||
|
|
5a589438d2 | ||
|
|
d8c061aa6e | ||
|
|
3cab260814 | ||
|
|
654dbc5c32 | ||
|
|
78e86ba01f | ||
|
|
435827fe5a | ||
|
|
f29f369a12 | ||
|
|
5a63426d1c | ||
|
|
05e3a73b16 | ||
|
|
c92d12bc18 | ||
|
|
6df64c6c34 | ||
|
|
0b9ff5210a | ||
|
|
85a009ad64 | ||
|
|
287a00d364 | ||
|
|
3c93f7690a | ||
|
|
a4e9917575 | ||
|
|
edc51df1bd | ||
|
|
ff88b13c35 | ||
|
|
dd0d0f68c4 | ||
|
|
8512000f36 | ||
|
|
f0cd9d1530 | ||
|
|
50e8b2d982 | ||
|
|
4f80077339 | ||
|
|
c5a09ebc49 | ||
|
|
d7de159455 | ||
|
|
18495bf25d | ||
|
|
ad0e89cbfb | ||
|
|
6a9d561671 | ||
|
|
545c301877 | ||
|
|
7aa00607ea | ||
|
|
bd5a81df70 | ||
|
|
4accce5d7b | ||
|
|
4d7308f26d | ||
|
|
678a79c0be | ||
|
|
fbba6dff20 | ||
|
|
fdb1f5926e | ||
|
|
b59b4a2b45 | ||
|
|
6c975fa13b | ||
|
|
c627c66560 | ||
|
|
130ff0c8db | ||
|
|
31d6935b97 | ||
|
|
14a29c03eb | ||
|
|
a7e2bf161e | ||
|
|
070dd181df | ||
|
|
7147da468f | ||
|
|
9125bda301 | ||
|
|
a4743370e2 | ||
|
|
867df8cf87 | ||
|
|
8a0b2231b1 | ||
|
|
3499dfeeb4 | ||
|
|
3c0e036cc9 | ||
|
|
bced424855 | ||
|
|
5fba2867f5 | ||
|
|
b5d361fc21 | ||
|
|
0674e79066 | ||
|
|
5f67ef4d6f | ||
|
|
1bb1f05d73 | ||
|
|
77429b2e2e | ||
|
|
a3c47cc682 | ||
|
|
0145223be1 | ||
|
|
f3b61c70ba | ||
|
|
7768c6271c | ||
|
|
d011332616 | ||
|
|
93b9132b0a | ||
|
|
936697e5b1 | ||
|
|
cf6cdc5ba6 | ||
|
|
ec81b321c2 | ||
|
|
23fce5ffaa | ||
|
|
7fa59cf555 | ||
|
|
29b24f9e72 | ||
|
|
523a075f82 | ||
|
|
06f9953fa8 | ||
|
|
b8fdc9bf5d | ||
|
|
7130676697 | ||
|
|
5ca5fdff9f | ||
|
|
81de01c02c | ||
|
|
b60512731b | ||
|
|
1eaf98cc10 | ||
|
|
34f88d4382 | ||
|
|
57e5814364 | ||
|
|
de67ebdda1 | ||
|
|
f44fa31f51 | ||
|
|
64e0724bd6 | ||
|
|
afb1699e0a | ||
|
|
b75edfafca | ||
|
|
26f69ee9d2 | ||
|
|
61879237e9 | ||
|
|
fb3ddf749d | ||
|
|
7d805c2231 | ||
|
|
5f8877b665 | ||
|
|
834840636c | ||
|
|
dfe1009080 | ||
|
|
6c95f4c816 | ||
|
|
d7690d8e7e | ||
|
|
68f42a5b90 | ||
|
|
ab7b325906 | ||
|
|
a26e174b36 | ||
|
|
866fdaa6db | ||
|
|
03315853df | ||
|
|
ca747c7572 | ||
|
|
1f608a81e8 | ||
|
|
822f972842 | ||
|
|
298a200f69 | ||
|
|
beefee7929 | ||
|
|
1eafcfab70 | ||
|
|
9e8e52c048 | ||
|
|
1f0c2f9f36 | ||
|
|
fc93ddbefe | ||
|
|
ffd929c590 | ||
|
|
d546201f12 | ||
|
|
799802f93b | ||
|
|
3d7ee64661 | ||
|
|
876880fb3f | ||
|
|
afb69071d5 | ||
|
|
0d8197cc9d | ||
|
|
e36b69a0ec | ||
|
|
0ef5228a77 | ||
|
|
e05b8542a0 | ||
|
|
41efc971ad | ||
|
|
d89a1e66d8 | ||
|
|
d3dee23e6c | ||
|
|
5f5e70e96e | ||
|
|
128cbe5a06 | ||
|
|
6d587f5181 | ||
|
|
9b4b373121 | ||
|
|
aa7490d187 | ||
|
|
c03c925e29 | ||
|
|
38929f856d | ||
|
|
bd0198de2d | ||
|
|
ece96216c4 | ||
|
|
a9347017db | ||
|
|
2eedf1fa28 | ||
|
|
0a875d7b2d | ||
|
|
173d06578f | ||
|
|
b299855ef2 | ||
|
|
8338a48c5b | ||
|
|
cd4f6c1466 | ||
|
|
37dd6bb159 | ||
|
|
714cf12822 | ||
|
|
ee00f2e07d | ||
|
|
c203b4df8e | ||
|
|
56adf64ccf | ||
|
|
91019f4f46 | ||
|
|
3cf94968e7 | ||
|
|
ebeb3707b1 | ||
|
|
b3ce5ed379 | ||
|
|
78fbc69c94 | ||
|
|
4ccbb5a71a | ||
|
|
e6265c04ae | ||
|
|
184fae06d7 | ||
|
|
76fb40d954 | ||
|
|
757e9f8ec6 | ||
|
|
fc51c095ba | ||
|
|
36b4b9dac9 | ||
|
|
083ea59fbd | ||
|
|
c1aeefb0c9 | ||
|
|
3c1ee54112 | ||
|
|
a49456f7f2 | ||
|
|
52dc210423 | ||
|
|
b1478d98f0 | ||
|
|
5ee969e4f6 | ||
|
|
7f8a61e79d | ||
|
|
69cac816aa | ||
|
|
2f2d04b3e8 | ||
|
|
9cd9c98f59 | ||
|
|
f2461f1430 | ||
|
|
a732a0dc85 | ||
|
|
4c2ce2c82c | ||
|
|
4cea9b8729 | ||
|
|
53c9b70ea3 | ||
|
|
71105e0b07 | ||
|
|
c432fdd987 | ||
|
|
d8199b607d | ||
|
|
b7836c33ae | ||
|
|
d497f494f0 | ||
|
|
0b48976be4 | ||
|
|
5b03dc1796 | ||
|
|
ec8b0beddd | ||
|
|
7536192058 | ||
|
|
5afff7821f | ||
|
|
8fb112158a | ||
|
|
792d618c02 | ||
|
|
93f59d04e9 | ||
|
|
666bec5017 | ||
|
|
2382c87aa3 | ||
|
|
caa0e54396 | ||
|
|
28b9adf794 | ||
|
|
584d77237e | ||
|
|
d9ec02d400 | ||
|
|
5568b16ed5 | ||
|
|
eab522e743 | ||
|
|
4cfdc8c5c8 | ||
|
|
2a4c34b878 | ||
|
|
729d7f6d88 | ||
|
|
3540ba32e9 | ||
|
|
32fedcf90c | ||
|
|
626efad307 | ||
|
|
cc30229abb | ||
|
|
a087dee98a | ||
|
|
f096c615c3 | ||
|
|
f81cb9f365 | ||
|
|
7e95963940 | ||
|
|
3f49f0f247 | ||
|
|
4cb1187871 | ||
|
|
fe782edc53 | ||
|
|
702cf4f54a | ||
|
|
0c84e21022 | ||
|
|
ee74321ac3 | ||
|
|
e45c11f98a | ||
|
|
c211288576 | ||
|
|
4fefd51e08 | ||
|
|
ad08f13aac | ||
|
|
6638c23cfc | ||
|
|
378a42c887 | ||
|
|
9abcf38b90 | ||
|
|
8715f51c61 | ||
|
|
37cbab363e | ||
|
|
afdcfc710e | ||
|
|
16bc6d04ad | ||
|
|
ac6908a139 | ||
|
|
28e415fb3e | ||
|
|
ab2e72340a | ||
|
|
da9c16278a | ||
|
|
b5d6c939fd | ||
|
|
fda2b361da | ||
|
|
6636ff05e6 | ||
|
|
9e17fafe1b | ||
|
|
1f58535920 | ||
|
|
8dd012096a | ||
|
|
f81970191a | ||
|
|
b8b16e49a5 | ||
|
|
2c21d9ecf8 | ||
|
|
2a45eff693 | ||
|
|
5bf8728cfa | ||
|
|
e3e4c4bc95 | ||
|
|
0c611af552 | ||
|
|
f304ca3daf | ||
|
|
d93cea97ec | ||
|
|
cabbe65be4 | ||
|
|
8a6b5b9e62 | ||
|
|
c15262c493 | ||
|
|
9a12e4a885 | ||
|
|
f52d526e1e | ||
|
|
e1a4b28039 | ||
|
|
b3560d1567 | ||
|
|
c6d144dab9 | ||
|
|
d5c000394d | ||
|
|
58e2b455fb | ||
|
|
2ab86a46d0 | ||
|
|
569b851b80 | ||
|
|
232df72b82 | ||
|
|
e65efdbbe1 | ||
|
|
29b41741cb | ||
|
|
17f21df441 | ||
|
|
94d2a84995 | ||
|
|
aac187d3a0 | ||
|
|
8d46977060 | ||
|
|
ca1eaedf7b | ||
|
|
8bd5f4f883 | ||
|
|
dc030ec53c | ||
|
|
1756c5d37f | ||
|
|
2b4e07dd91 | ||
|
|
0df2582674 | ||
|
|
24e47efae0 | ||
|
|
10b640d773 | ||
|
|
ff80d10820 | ||
|
|
126a9fb261 | ||
|
|
4001032858 | ||
|
|
ad779e4865 | ||
|
|
701ef17227 | ||
|
|
5d6af189f1 | ||
|
|
518bf36aa9 | ||
|
|
5b7dfefc7e | ||
|
|
484bf07379 | ||
|
|
0ded003703 | ||
|
|
95aa159bdd | ||
|
|
ba120e524b | ||
|
|
a6945d046f | ||
|
|
108c656e66 | ||
|
|
2d77ef92b0 | ||
|
|
f6901606f5 | ||
|
|
849e90bd01 | ||
|
|
e86be93b4a | ||
|
|
698516f3f5 | ||
|
|
da621e4402 | ||
|
|
ea92864a4d | ||
|
|
a5fa6eb356 | ||
|
|
cbaf4880ad | ||
|
|
b813bb863d | ||
|
|
30fb78813b | ||
|
|
a3ad8b5f26 | ||
|
|
24a551c14e | ||
|
|
8e359baaec | ||
|
|
85bdfc8695 | ||
|
|
c466e2d8f8 | ||
|
|
d75de3d3b2 | ||
|
|
c8ba643f53 | ||
|
|
591eedcf36 | ||
|
|
48e35f9c3e | ||
|
|
89c4b1aabe | ||
|
|
6ff1b83038 | ||
|
|
4008f31add | ||
|
|
c475418975 | ||
|
|
a31ae23db1 | ||
|
|
44a4517e2b | ||
|
|
ff9313e6dd | ||
|
|
c47ae3b15d | ||
|
|
6aafa89d20 | ||
|
|
acbf18d0dd | ||
|
|
8826011c81 | ||
|
|
d6a78cb85b | ||
|
|
7812a4c89f | ||
|
|
ef540c1243 | ||
|
|
8ffbc0f114 | ||
|
|
21ba38972b | ||
|
|
d54b8e89c0 | ||
|
|
14eecc6e2a | ||
|
|
99fda0ed22 | ||
|
|
8e055a4086 | ||
|
|
d4967358a5 | ||
|
|
bae78f7b6c | ||
|
|
f97dcc72dc | ||
|
|
dd10e41b27 | ||
|
|
c0d10efabf | ||
|
|
fecb3f4307 | ||
|
|
9bb66c00e9 | ||
|
|
1ec50cdcfc | ||
|
|
5906ce844a | ||
|
|
2e66a27081 | ||
|
|
497fa60f57 | ||
|
|
2d1217006b | ||
|
|
444df2b287 | ||
|
|
8ee1c167b9 | ||
|
|
486dc5102e | ||
|
|
a1d9f501e3 | ||
|
|
4501f21ae7 | ||
|
|
649424b8ea | ||
|
|
a15f5137ef | ||
|
|
410e641dff | ||
|
|
c5fd8a0b97 | ||
|
|
5df9b11141 | ||
|
|
e159052e6d | ||
|
|
23f47ebc47 | ||
|
|
58e7f68004 | ||
|
|
29e5930090 | ||
|
|
deb178a0b1 | ||
|
|
e185926beb | ||
|
|
0d10e21c2f | ||
|
|
ed27592537 | ||
|
|
df45d78d14 | ||
|
|
c98b29aa67 | ||
|
|
388679b00e | ||
|
|
119467c580 | ||
|
|
c2550ac24a | ||
|
|
12ee35a3d1 | ||
|
|
eb3220622e | ||
|
|
8f26e819ad | ||
|
|
b6b1c2f95d | ||
|
|
9ce9804a88 | ||
|
|
ddaa61ca9a | ||
|
|
4646bd082a | ||
|
|
53aca9c3d0 | ||
|
|
aa1e794213 | ||
|
|
45e3b678b0 | ||
|
|
bd99496423 | ||
|
|
e471ec884e | ||
|
|
b400705a1c | ||
|
|
cb35191fc1 | ||
|
|
1945a93b33 | ||
|
|
dfd12e6dac | ||
|
|
ba29e1d75d | ||
|
|
8f6d123586 | ||
|
|
d368ed586c | ||
|
|
87095a9f1f | ||
|
|
dd6d203488 | ||
|
|
f463ebf54a | ||
|
|
3547d7e24f | ||
|
|
a9c01aba78 | ||
|
|
f237947bdc | ||
|
|
890df3d90b | ||
|
|
14783585b6 | ||
|
|
243c4beac7 | ||
|
|
fe9cb54e0d | ||
|
|
dabec32748 | ||
|
|
6faa5fc95b | ||
|
|
dbbec6cdb4 | ||
|
|
43923cf038 | ||
|
|
2ccba49b01 | ||
|
|
362fdc6ceb | ||
|
|
7bb53541e4 | ||
|
|
c07b3aeef9 | ||
|
|
fb47935a7b | ||
|
|
ec3538c2ee | ||
|
|
84e15d1ee2 | ||
|
|
5b4c4f3f77 | ||
|
|
aecdfc60a0 | ||
|
|
816ede3a17 | ||
|
|
353c79ca71 | ||
|
|
e93115f436 | ||
|
|
197c9639bb | ||
|
|
a358a38b84 | ||
|
|
16d76e2293 | ||
|
|
536e583cbe | ||
|
|
9049f9aeb9 | ||
|
|
bee3e63e1b | ||
|
|
d8f13cbd5b | ||
|
|
0f39da5490 | ||
|
|
28fef35a12 | ||
|
|
1344d44a5a | ||
|
|
61ed2a670e | ||
|
|
db1bc035f7 | ||
|
|
8de6cdaa82 | ||
|
|
fe1a4f5fb6 | ||
|
|
d38f89cae8 | ||
|
|
9c90fe8264 | ||
|
|
b85a666f72 | ||
|
|
5ba95f6816 | ||
|
|
dc38b7c3c4 | ||
|
|
6484b03dd9 | ||
|
|
29235d9b4b | ||
|
|
4b3687f1a6 | ||
|
|
e7e8b75a4c | ||
|
|
e98265a49b | ||
|
|
e87f69bdb6 | ||
|
|
70d2832c0d | ||
|
|
7636f1f659 | ||
|
|
1523c83650 | ||
|
|
a6987efaec | ||
|
|
6491abb519 | ||
|
|
8faabb4e3a | ||
|
|
2838c2c8a5 | ||
|
|
3315bad009 | ||
|
|
3eeced78b5 | ||
|
|
c23430b438 | ||
|
|
0e49bfff51 | ||
|
|
3ed40d04a9 | ||
|
|
70b36aa55d | ||
|
|
0f83b33d4f | ||
|
|
b83106bed4 | ||
|
|
21413e599a | ||
|
|
5f4cc7b036 | ||
|
|
9aa26fb969 | ||
|
|
7f74012a0d | ||
|
|
96ebef093f | ||
|
|
a19f4bba0c | ||
|
|
c24b957e17 | ||
|
|
5ba2f77230 | ||
|
|
a09f490804 | ||
|
|
082d6fbea9 | ||
|
|
37372960a8 | ||
|
|
0035a0c98d | ||
|
|
036cc5d575 | ||
|
|
14950926ed | ||
|
|
baa3b1a07e | ||
|
|
2a09f66a44 | ||
|
|
e50b62c770 | ||
|
|
13d8b0f17f | ||
|
|
9e0c658b29 | ||
|
|
74fec56927 | ||
|
|
514f304a47 | ||
|
|
7f85a5c988 | ||
|
|
14d626d961 | ||
|
|
7560cacb3f | ||
|
|
3cd9bcdab9 | ||
|
|
32f1efdc99 | ||
|
|
bcc9f03457 | ||
|
|
4c845bf02b | ||
|
|
c727864393 | ||
|
|
4548573a75 | ||
|
|
385246730d | ||
|
|
e06d21a4c0 | ||
|
|
c132d2ae8c | ||
|
|
ece31100e0 | ||
|
|
ce4e1ac54b | ||
|
|
ef61fb11f0 | ||
|
|
42f2b11ec8 | ||
|
|
ac87cbb0d1 | ||
|
|
c65de3d689 | ||
|
|
1433fa4209 | ||
|
|
d51149e5ac | ||
|
|
ffd813435a | ||
|
|
d75fd2c7f9 | ||
|
|
cdad84aa46 | ||
|
|
0fdb545d8c | ||
|
|
a5f5ff70e0 | ||
|
|
4f0e320236 | ||
|
|
68aed6a5eb | ||
|
|
6811112208 | ||
|
|
9ebc4b24d9 | ||
|
|
b990080a52 | ||
|
|
efbe3e4d57 | ||
|
|
7b14a65b2b | ||
|
|
5887744d8b | ||
|
|
8bf718671a | ||
|
|
c858b14c03 | ||
|
|
12df172575 | ||
|
|
7fa751d36e | ||
|
|
7a7611e977 | ||
|
|
ec8763adf2 | ||
|
|
f2d1d573f5 | ||
|
|
a530b87fd0 | ||
|
|
6c21789aed | ||
|
|
616866fcf4 | ||
|
|
faf06bcfe5 | ||
|
|
cd376a5c43 | ||
|
|
6ba5ab6d67 | ||
|
|
1bee3218b4 | ||
|
|
802eaadd2d | ||
|
|
ee22eed23d | ||
|
|
ab72de5f7a | ||
|
|
a32cea24fd | ||
|
|
af0d805be4 | ||
|
|
181c22f798 | ||
|
|
87133ef6b7 | ||
|
|
1ef2f014ee | ||
|
|
0a92d1d684 | ||
|
|
ff5221b693 | ||
|
|
db484cc4b8 | ||
|
|
6442963f49 | ||
|
|
0f7b95ce47 | ||
|
|
632a2e0894 | ||
|
|
e9635c7b2d | ||
|
|
8e3b1338a5 | ||
|
|
9d3dde0900 | ||
|
|
c5abaeddca | ||
|
|
ca2cd6f3e7 | ||
|
|
7d07e0312a | ||
|
|
e1c73fd8f4 | ||
|
|
b83ab21283 | ||
|
|
8001156ca8 | ||
|
|
57e31f0a58 | ||
|
|
51fadf6b7e | ||
|
|
2a6a8aa0a0 | ||
|
|
aa264a7fb2 | ||
|
|
5e35c2b6ab | ||
|
|
0385372314 | ||
|
|
efbff95ec7 | ||
|
|
2a9edb2153 | ||
|
|
be14e60d9e | ||
|
|
ef4641cad7 | ||
|
|
100f30043f | ||
|
|
1574b5b0a2 | ||
|
|
012fe99ab1 | ||
|
|
8ff5a3e096 | ||
|
|
65317eb019 | ||
|
|
ac3e26b0ff | ||
|
|
e86f450428 | ||
|
|
7b2776fdc7 | ||
|
|
2a16d1d230 | ||
|
|
53e1c9ab11 | ||
|
|
410abc4626 | ||
|
|
a2e28443f0 | ||
|
|
c1af0a3f21 | ||
|
|
bb5e1ee2f9 | ||
|
|
3aee89c8fd | ||
|
|
44e1f9f682 | ||
|
|
37d76b961c | ||
|
|
1305663d99 | ||
|
|
8f4efe57a2 | ||
|
|
0613dbc4a2 | ||
|
|
0ed0d69368 | ||
|
|
2ffbbee1f6 | ||
|
|
b9d2f2537b | ||
|
|
69dc173979 | ||
|
|
ded8b5ebd4 | ||
|
|
ed58ae9f98 | ||
|
|
f7f790b4b3 | ||
|
|
fe74c80992 | ||
|
|
fa659bf7ad | ||
|
|
9b41649601 | ||
|
|
1b3438f5a5 | ||
|
|
3eed64e5c4 | ||
|
|
0fac33781d | ||
|
|
3135b6a33d | ||
|
|
2686ae2322 | ||
|
|
a709e29586 | ||
|
|
dd46579cb4 | ||
|
|
f4b7210e7b | ||
|
|
05a0b0d7b0 | ||
|
|
c1f4d7506a | ||
|
|
b6ba0be550 | ||
|
|
23dfb4e2f9 | ||
|
|
7a10e31982 | ||
|
|
de89c4fd01 | ||
|
|
5d4956d34b | ||
|
|
42c5eb59c9 | ||
|
|
09cc6e7754 | ||
|
|
4a5bc41e89 | ||
|
|
0ade18828d | ||
|
|
91046e6ca4 | ||
|
|
17e1ba8ae2 | ||
|
|
c47c854f15 | ||
|
|
e931866b35 | ||
|
|
7828a065bf | ||
|
|
3e689e700e | ||
|
|
a9964afcf7 | ||
|
|
95c19876c6 | ||
|
|
5efccfa5e2 | ||
|
|
89e737a258 | ||
|
|
8fbc853b0d | ||
|
|
2e008b319c | ||
|
|
ff6e3c95f2 | ||
|
|
7e9385405f | ||
|
|
592ea36a86 | ||
|
|
e059ebf99d | ||
|
|
609480ed78 | ||
|
|
4271185936 | ||
|
|
aacae62591 | ||
|
|
47cbf3828d | ||
|
|
46d418164d | ||
|
|
ede8d84884 | ||
|
|
53d223b45f | ||
|
|
ac35dd5a6f | ||
|
|
9e19012cb0 | ||
|
|
1234cda3b3 | ||
|
|
710a0e3a45 | ||
|
|
b7f24b2456 | ||
|
|
fc594b551a | ||
|
|
f39ccccc0c | ||
|
|
f0a4ddd78b | ||
|
|
c691769e46 | ||
|
|
19dc30567e | ||
|
|
a453bccff0 | ||
|
|
aa2053a575 | ||
|
|
3d8f71c4d2 | ||
|
|
6aaaabbc4d | ||
|
|
42c36f48ed | ||
|
|
a5f4139102 | ||
|
|
030d85a9b3 | ||
|
|
adcfb7fb55 | ||
|
|
cec365888a | ||
|
|
55bfa8dd11 | ||
|
|
e99759fe45 | ||
|
|
17c6e6ee3f | ||
|
|
7fff900a1a | ||
|
|
c67974e4c8 | ||
|
|
a36696e02e | ||
|
|
9b80ca6c41 | ||
|
|
22f514aabf | ||
|
|
211478e13e | ||
|
|
5e33a7e58b | ||
|
|
b2e31721e8 | ||
|
|
de0dbfa359 | ||
|
|
f93459579f | ||
|
|
2b81c40b90 | ||
|
|
233e97c5e4 | ||
|
|
fc1ce48dc7 | ||
|
|
fd5562eebe | ||
|
|
0695d9cb5f | ||
|
|
456b24134d | ||
|
|
f8ba24afee | ||
|
|
eebb921c9f | ||
|
|
e17ee87f38 | ||
|
|
18e3f07f7d | ||
|
|
9ce39a470f | ||
|
|
23572369fc | ||
|
|
01b350de96 | ||
|
|
365e470a32 | ||
|
|
a42b40656c | ||
|
|
40160f2a57 | ||
|
|
90b33b1552 | ||
|
|
5567ed01e5 | ||
|
|
cbe9448650 | ||
|
|
5b345534dc | ||
|
|
c8dc318fb3 | ||
|
|
23cb1a1080 | ||
|
|
21cf8d7d3c | ||
|
|
3cf4d34094 | ||
|
|
16d78ae5db | ||
|
|
62b4b7af83 | ||
|
|
9799ecac6a | ||
|
|
dccb766095 | ||
|
|
c97983a91c | ||
|
|
680fb07fd5 | ||
|
|
cfd0ea197c | ||
|
|
48d4ed9bc0 | ||
|
|
3bed78356e | ||
|
|
8923922f30 | ||
|
|
7542e42e4f | ||
|
|
7a9b23e4f4 | ||
|
|
47253ba2a1 | ||
|
|
69b54dd9e4 | ||
|
|
36138617fc | ||
|
|
231ca50700 | ||
|
|
c7613f3e91 | ||
|
|
05d5546eb1 | ||
|
|
cefe67726e | ||
|
|
1ac2dcc537 | ||
|
|
3a68eecb28 | ||
|
|
54a8259b42 | ||
|
|
32b6f1619f | ||
|
|
99b8c5d379 | ||
|
|
5deb7c55e1 | ||
|
|
9cd25dd216 | ||
|
|
4a9ccf7e38 | ||
|
|
2963b9f07f | ||
|
|
a4a9bc4d8e | ||
|
|
a16a029790 | ||
|
|
97fea81599 | ||
|
|
ccffb6ecd6 | ||
|
|
63b5a1a4d8 | ||
|
|
dfc777803a | ||
|
|
934a9bb23e | ||
|
|
7097f7a894 | ||
|
|
537fd7c4ba | ||
|
|
d5048b8b0c | ||
|
|
0348556aac | ||
|
|
d6329b9dce | ||
|
|
34f3d29d93 | ||
|
|
cd701761f9 | ||
|
|
23c2c00d69 | ||
|
|
fa501b46cf | ||
|
|
38dc0a5c5d | ||
|
|
685cc4edbc | ||
|
|
78369375e3 | ||
|
|
6587058f74 | ||
|
|
30f738e49a | ||
|
|
726ca01e5c | ||
|
|
83b40b8cda | ||
|
|
db0d0438ff | ||
|
|
3c527488e7 | ||
|
|
99abcf6ded | ||
|
|
7009727559 | ||
|
|
ae02fba141 | ||
|
|
76cdeb62e3 | ||
|
|
ae9627c64c | ||
|
|
58875bdcd7 | ||
|
|
616caa5d30 | ||
|
|
8236ee3ff6 | ||
|
|
19f2804661 | ||
|
|
c62ba5f48d | ||
|
|
22bee8128a | ||
|
|
39150eb8c7 | ||
|
|
1b14fa53ef | ||
|
|
cf55e5d4f8 | ||
|
|
1a1ea028f6 | ||
|
|
814c3445a3 | ||
|
|
075dcee042 | ||
|
|
fe97a03033 | ||
|
|
f593aad786 | ||
|
|
4a8c602a59 | ||
|
|
7143dbc46a | ||
|
|
e69699e12c | ||
|
|
d6dbdbf27a | ||
|
|
a0dae55a69 | ||
|
|
7f15fb2a21 | ||
|
|
d5aa8db36f | ||
|
|
357b6c9d8c | ||
|
|
b0c4794305 | ||
|
|
071206ef59 | ||
|
|
63ab8e6341 | ||
|
|
741b0d6e82 | ||
|
|
3041faffab | ||
|
|
30ee690401 | ||
|
|
22a169bc31 | ||
|
|
ac19803d03 | ||
|
|
95485ee89b | ||
|
|
bc61f69058 | ||
|
|
0b86d6a451 | ||
|
|
0317731dc9 | ||
|
|
3dedb52163 | ||
|
|
ad393b83a2 | ||
|
|
01dac453db | ||
|
|
03abdf49a0 | ||
|
|
83b9149930 | ||
|
|
5ca5cbd447 | ||
|
|
597e89efe3 | ||
|
|
683e44f5f8 | ||
|
|
0b36d4e360 | ||
|
|
67606e2460 | ||
|
|
b6c6b30c0d | ||
|
|
e5935f0ced | ||
|
|
75c15e8028 | ||
|
|
4831ae17d9 | ||
|
|
22655d7554 | ||
|
|
ff0e430e46 | ||
|
|
e86dc8c338 | ||
|
|
0814de6371 | ||
|
|
34bc6907d0 | ||
|
|
a6dd1a2b4b | ||
|
|
4fe5d3d5e3 | ||
|
|
937fe7e909 | ||
|
|
89ab1e679d | ||
|
|
559984b2fe | ||
|
|
3ac9540351 | ||
|
|
d5709c9d70 | ||
|
|
891cc95add | ||
|
|
0246b5657a | ||
|
|
26ca1fb9f3 | ||
|
|
6b4355b76f | ||
|
|
90bd9692f5 | ||
|
|
8878185628 | ||
|
|
15066d1d37 | ||
|
|
abaae6e28b | ||
|
|
2170de8819 | ||
|
|
300ec667f6 | ||
|
|
348c4380d6 | ||
|
|
98388d18de | ||
|
|
bbc5753b96 | ||
|
|
564eecaa3b | ||
|
|
0480920058 | ||
|
|
d977dd4395 | ||
|
|
ca402379a9 | ||
|
|
903bf2135d | ||
|
|
1f732585b2 | ||
|
|
224de0601e | ||
|
|
9b84337830 | ||
|
|
a4665c27df | ||
|
|
3337015346 | ||
|
|
42c466296a | ||
|
|
a9fcf9db47 | ||
|
|
f3b55fcab0 | ||
|
|
b56b6509b1 | ||
|
|
ac85e383a9 | ||
|
|
2b326e90b8 | ||
|
|
3e8be645d2 | ||
|
|
81444265f4 | ||
|
|
5716ab70ec | ||
|
|
faaef7686d | ||
|
|
9e6f5b6b2d | ||
|
|
d28465bf60 | ||
|
|
867fec260b | ||
|
|
f5309d902a | ||
|
|
82823e50dd | ||
|
|
394f79e9d3 | ||
|
|
595bbbd3e4 | ||
|
|
2127572c33 | ||
|
|
7d6c927684 | ||
|
|
9d2d4c82df | ||
|
|
515ce9bebb | ||
|
|
7698bb0ae1 | ||
|
|
c89a5148b2 | ||
|
|
c37adba77b | ||
|
|
95cc3dec3f | ||
|
|
42c4a91041 | ||
|
|
d253dad2ee | ||
|
|
7f0265e674 | ||
|
|
b9726ba66d | ||
|
|
b20ffa7369 | ||
|
|
854abdf5e6 | ||
|
|
d0fc8a572c | ||
|
|
8bc1ca0e44 | ||
|
|
d38bd138cd | ||
|
|
7766bc25d1 | ||
|
|
34244656a6 | ||
|
|
619849c793 | ||
|
|
927b2b3942 | ||
|
|
76389e057f | ||
|
|
0a14e491ab | ||
|
|
1f7f1c1ffb | ||
|
|
6440733002 | ||
|
|
02802af97f | ||
|
|
a8169a3d6b | ||
|
|
9ba7fc94a5 | ||
|
|
48b71a02d7 | ||
|
|
18ed04b990 | ||
|
|
d09e03606c | ||
|
|
b2017f5653 | ||
|
|
c16eb80d7f | ||
|
|
0c56f98a92 | ||
|
|
490940cd53 | ||
|
|
92d27b0aa3 | ||
|
|
ca9c83f824 | ||
|
|
fc900e2432 | ||
|
|
e3257e56ab | ||
|
|
7d2337c6eb | ||
|
|
58629f1fea | ||
|
|
132ec0a5fc | ||
|
|
c2b47430fb | ||
|
|
7906592230 | ||
|
|
f57378d8ba | ||
|
|
1ccdc225af | ||
|
|
3e4df86ac0 | ||
|
|
7054cf7a35 | ||
|
|
2a7fc9e30e | ||
|
|
f1b4f15dbb | ||
|
|
c98152e9d0 | ||
|
|
7c34859e0c | ||
|
|
dd38e096b2 | ||
|
|
ea89efbed7 | ||
|
|
61408a0f29 | ||
|
|
cca004efe4 | ||
|
|
da3f3da92c | ||
|
|
f0c35819bd | ||
|
|
ff616002cf | ||
|
|
e1c79869b6 | ||
|
|
bd43403f5a | ||
|
|
d3997cc4d1 | ||
|
|
5b0b8579b2 | ||
|
|
c927de137c | ||
|
|
eb23d505f8 | ||
|
|
2400cf16a4 | ||
|
|
bbe3ace533 | ||
|
|
3b87eb3d08 | ||
|
|
d43a17304e | ||
|
|
21d41b8e81 | ||
|
|
332eaaf916 | ||
|
|
0a5ada6411 | ||
|
|
963f8d3485 | ||
|
|
60a8c5f1c9 | ||
|
|
d1a1024465 | ||
|
|
0d7ff9ac47 | ||
|
|
752d5685dc | ||
|
|
c6c517431f | ||
|
|
ee54f54ced | ||
|
|
2c5c96e159 | ||
|
|
a10763138e | ||
|
|
208eb0ca07 | ||
|
|
f0403fa9e4 | ||
|
|
3f86b250e6 | ||
|
|
d1819f5f76 | ||
|
|
19c7e63858 | ||
|
|
7efdcc26fe | ||
|
|
3ab3970dd2 | ||
|
|
5ab487dbae | ||
|
|
55fbc2c78e | ||
|
|
643426e2b2 | ||
|
|
f31a834613 | ||
|
|
683080be53 | ||
|
|
d14b8a9ad6 | ||
|
|
0f87ba6c93 | ||
|
|
02bfa0898c | ||
|
|
f5313f92f1 | ||
|
|
e41a258b93 | ||
|
|
ffa85cda1a | ||
|
|
0123d41647 | ||
|
|
2b0481deed | ||
|
|
1389f86675 | ||
|
|
cf6bb88af2 | ||
|
|
8e19a267bd | ||
|
|
3b55709e7f | ||
|
|
f78bca4ad8 | ||
|
|
713feca582 | ||
|
|
26c20ed91d | ||
|
|
e399249f31 | ||
|
|
b4a1b4b59a | ||
|
|
b309a88bea | ||
|
|
e88bee49a6 | ||
|
|
ec12770693 | ||
|
|
5b3a18319e | ||
|
|
3b73278348 | ||
|
|
0ca2cb625e | ||
|
|
67561f97ec | ||
|
|
b667bae65d | ||
|
|
54be9bd8b9 | ||
|
|
06d0299639 | ||
|
|
84851e230f | ||
|
|
52aed9e0de | ||
|
|
ead9a550fd | ||
|
|
cf80b492a3 | ||
|
|
69f3d2678e | ||
|
|
8038bc2fc8 | ||
|
|
f20b12cf3f | ||
|
|
c8bd53509c | ||
|
|
006124d816 | ||
|
|
efd73ac956 | ||
|
|
b7d7334451 | ||
|
|
8284865f9a | ||
|
|
1f8b04cbd1 | ||
|
|
b3402a0b9f | ||
|
|
4037959945 | ||
|
|
d7313a3274 | ||
|
|
8302086942 | ||
|
|
6095db951b | ||
|
|
817d2764b6 | ||
|
|
62189602cb | ||
|
|
0120dcc787 | ||
|
|
6bfc0ec3a7 | ||
|
|
f999d879d5 | ||
|
|
c861e2d9cf | ||
|
|
e696978d11 | ||
|
|
fbf2e942a9 | ||
|
|
d18f282938 | ||
|
|
c10be7eaec | ||
|
|
05ecad4263 | ||
|
|
4cdb159ccb | ||
|
|
fccb25586f | ||
|
|
ab2f3307eb | ||
|
|
db26a103d6 | ||
|
|
32902f79ad | ||
|
|
fab33dd230 | ||
|
|
daaa025356 | ||
|
|
ffe272c165 | ||
|
|
6e763d2776 | ||
|
|
c71b433a35 | ||
|
|
0b91d55269 | ||
|
|
9f41903067 | ||
|
|
64de8807e2 | ||
|
|
3848cbe24a | ||
|
|
15ac7b08f7 | ||
|
|
e47ecc1828 | ||
|
|
c09641cf47 | ||
|
|
92467db591 | ||
|
|
ea5e7182ab | ||
|
|
d38d53d9dd | ||
|
|
c9e094d9fc | ||
|
|
af75985ec6 | ||
|
|
4b7c05903b | ||
|
|
695912c7cf | ||
|
|
5c06306ccc | ||
|
|
d4fd17f64f | ||
|
|
76d94e69ae | ||
|
|
0f42744f5c | ||
|
|
e8daf7c73b | ||
|
|
0cf1af5bbf | ||
|
|
a343328a21 | ||
|
|
53a56b82af | ||
|
|
64dd4dc219 | ||
|
|
9e9da42c64 | ||
|
|
5c410f4ca2 | ||
|
|
0778211116 | ||
|
|
574563d711 | ||
|
|
e9d0b424d5 | ||
|
|
eef981e05f | ||
|
|
9f24f4bc69 | ||
|
|
5da9818676 | ||
|
|
ff59b07986 | ||
|
|
1b6d4fd277 | ||
|
|
7b19890deb | ||
|
|
5370443ece | ||
|
|
ad4fb1cf84 | ||
|
|
7f8169f0da | ||
|
|
66e8652862 | ||
|
|
05cbdbc1ef | ||
|
|
38584a1fca | ||
|
|
d96d8c49ac | ||
|
|
4bb623a0a3 | ||
|
|
3aa94a0997 | ||
|
|
ccad4ae04f | ||
|
|
346b9ae5a1 | ||
|
|
12f36debae | ||
|
|
87acec6a91 | ||
|
|
58a5e654f9 | ||
|
|
e278953191 | ||
|
|
573ddf8aec | ||
|
|
4f32243214 | ||
|
|
601bdfb1b4 | ||
|
|
90454a93b2 | ||
|
|
640921cd3f | ||
|
|
fccee959b1 | ||
|
|
67a8ecf2bf | ||
|
|
d8701890b2 | ||
|
|
2435f46d06 | ||
|
|
4bece787c8 | ||
|
|
d4ce938679 | ||
|
|
033fe9f133 | ||
|
|
25b10dc264 | ||
|
|
a9c3630d1b | ||
|
|
f3d99f41d4 | ||
|
|
fdb46b857f | ||
|
|
8d06df9775 | ||
|
|
a8d6e60ec6 | ||
|
|
4e643fa42c | ||
|
|
eb234bbf91 | ||
|
|
db1a221427 | ||
|
|
5378f35239 | ||
|
|
622f5eb967 | ||
|
|
966d827d35 | ||
|
|
bed56d3e52 | ||
|
|
24173d5ebc | ||
|
|
60853b5e54 | ||
|
|
da2ff552c5 | ||
|
|
742df52236 | ||
|
|
1b4621962f | ||
|
|
0a36828ff3 | ||
|
|
85ea4297b9 | ||
|
|
34cc3419fa | ||
|
|
46fcd2e844 | ||
|
|
23f0cdf901 | ||
|
|
26bdf66659 | ||
|
|
cf6f1dd01e | ||
|
|
286eb59081 | ||
|
|
40bb28e9b6 | ||
|
|
aac085a9be | ||
|
|
58e68901c7 | ||
|
|
8e69c6e492 | ||
|
|
4d98a14cb1 | ||
|
|
5bf99dfd61 | ||
|
|
bc42415ceb | ||
|
|
284e6a80ac | ||
|
|
0243882238 | ||
|
|
877eee408e | ||
|
|
8dd54de326 | ||
|
|
09d729bfba | ||
|
|
9caaca742e | ||
|
|
ac95c3ffbf | ||
|
|
9715d80030 | ||
|
|
a0a1e5c078 | ||
|
|
d7ba1fdd3d | ||
|
|
2544fca519 | ||
|
|
0b55e2c332 | ||
|
|
b105046202 | ||
|
|
de20255c71 | ||
|
|
1a1c37db7c | ||
|
|
a87700a28c | ||
|
|
1f8e9ad0fc | ||
|
|
e13e978af4 | ||
|
|
28e334c728 | ||
|
|
15a9427112 | ||
|
|
010b0e1d75 | ||
|
|
cd5ddca00d | ||
|
|
f18e1fccfd | ||
|
|
773b8c5a54 | ||
|
|
fc3d18ed64 | ||
|
|
68ed281461 | ||
|
|
65ada37399 | ||
|
|
9f539d7028 | ||
|
|
c73a5ff918 | ||
|
|
9858d4e918 | ||
|
|
0dfb1d264e | ||
|
|
a056b9115b | ||
|
|
62ecc04212 | ||
|
|
4a0f4fc186 | ||
|
|
3a61dcd360 | ||
|
|
04d0240f8d | ||
|
|
13ebfc0779 | ||
|
|
d70d5aa9d8 | ||
|
|
70d3c2cd3e | ||
|
|
6fbe0dec2c | ||
|
|
9d3591dcd5 | ||
|
|
8992f36fbf | ||
|
|
3d203aa7c4 | ||
|
|
cd8d7e6de9 | ||
|
|
5d4e6f17ee | ||
|
|
49f707ec93 | ||
|
|
6a305df46d | ||
|
|
35e9482574 | ||
|
|
dac61d4e9c | ||
|
|
d52e825bbc | ||
|
|
4fa463dff6 | ||
|
|
ebaa16f403 | ||
|
|
175741ed1d | ||
|
|
8d9d9899b7 | ||
|
|
cff7448fb2 | ||
|
|
0f8f510ebb | ||
|
|
3812c22f86 | ||
|
|
2b3000dddc | ||
|
|
b278baf94e | ||
|
|
4119b72d50 | ||
|
|
da2c15ecb4 | ||
|
|
25a702fc22 | ||
|
|
ab178057db | ||
|
|
c44cf5a720 | ||
|
|
98ca01bf2d | ||
|
|
d0ed873ab6 | ||
|
|
0f24399887 | ||
|
|
abbbda6f74 | ||
|
|
1a5ee7ab83 | ||
|
|
3a258ee5c9 | ||
|
|
4d41fdf0fc | ||
|
|
1586c4b0c7 | ||
|
|
9198e97401 | ||
|
|
346267c82f | ||
|
|
529f72325f | ||
|
|
1cf1209586 | ||
|
|
36774529a4 | ||
|
|
27dcb1008c | ||
|
|
e8a9c7b13e | ||
|
|
7be59851d5 | ||
|
|
15cf9ec365 | ||
|
|
c44c904161 | ||
|
|
9e3d8d1650 | ||
|
|
7b9668fe01 | ||
|
|
2334c48e02 | ||
|
|
afb949a417 | ||
|
|
c9bb85c91d | ||
|
|
13e1667d61 | ||
|
|
3c106c9cec | ||
|
|
1988668d10 | ||
|
|
484d7f91e5 | ||
|
|
53d58f222f | ||
|
|
d5a72b1eaf | ||
|
|
6b5ebab6ae | ||
|
|
8107df08a8 | ||
|
|
dc29500931 | ||
|
|
31fc1aca53 | ||
|
|
0db4b04ad3 | ||
|
|
1aa9ea92e2 | ||
|
|
2698f54a9c | ||
|
|
6f977248bf | ||
|
|
046fd62dc4 | ||
|
|
da60dda2dd | ||
|
|
d25fb08a75 | ||
|
|
79e105243c | ||
|
|
2d4e531ac9 | ||
|
|
52403ad9ed | ||
|
|
2d264855cc | ||
|
|
c172c72be9 | ||
|
|
79259fdb3f | ||
|
|
cee35f7d24 | ||
|
|
1f5f17622e | ||
|
|
e8f7f80f2b | ||
|
|
6db8beeade | ||
|
|
4f66313440 | ||
|
|
89b5bcfdc7 | ||
|
|
26f706ebe3 | ||
|
|
0cb38085a1 | ||
|
|
cff6644b28 | ||
|
|
63837530ed | ||
|
|
62e09e73f7 | ||
|
|
daef0a2374 | ||
|
|
042045b998 | ||
|
|
bad7284465 | ||
|
|
6f0cb6365e | ||
|
|
653ec05c0e | ||
|
|
be2a751513 | ||
|
|
840adfbbcf | ||
|
|
acf32be842 | ||
|
|
3999613eca | ||
|
|
bff85725d2 | ||
|
|
93008b2369 | ||
|
|
be336e7514 | ||
|
|
255f7f2dee | ||
|
|
de2c07ac62 | ||
|
|
844d54d7e6 | ||
|
|
ff3e6c7248 | ||
|
|
408a2229d6 | ||
|
|
7cdd65075c | ||
|
|
436ce16e79 | ||
|
|
58320e2678 | ||
|
|
a6f7edf94b | ||
|
|
4a4f13be46 | ||
|
|
a13b0abb7d | ||
|
|
c081919320 | ||
|
|
21f7f78130 | ||
|
|
bb1b24c178 | ||
|
|
3f30000088 | ||
|
|
e6ce39f76e | ||
|
|
10116b7717 | ||
|
|
18edb8bd63 | ||
|
|
dae1aeb1f7 | ||
|
|
57085c892f | ||
|
|
d67efb2cab | ||
|
|
0e09ecbaa5 | ||
|
|
e3699070a4 | ||
|
|
bf40855825 | ||
|
|
3ee4f2810d | ||
|
|
79468cf676 | ||
|
|
4037942a26 | ||
|
|
cae6c9ab36 | ||
|
|
15b393193a | ||
|
|
53ab34928c | ||
|
|
eb4a169cfb | ||
|
|
6f6cadf31d | ||
|
|
17513a6dce | ||
|
|
a44560ddb6 | ||
|
|
2b8afb38b7 | ||
|
|
685ad74d53 | ||
|
|
288ea11534 | ||
|
|
b848ff8db9 | ||
|
|
5881fcb0d6 | ||
|
|
491a2e8732 | ||
|
|
4a620a2c5e | ||
|
|
05105155f8 | ||
|
|
9f96545fa7 | ||
|
|
0c60107e62 | ||
|
|
49eb9cbdd8 | ||
|
|
594d226056 | ||
|
|
aac7dccf45 | ||
|
|
c19e325b83 | ||
|
|
bd92c23add | ||
|
|
88335bd92e | ||
|
|
a4602021d8 | ||
|
|
dbe5c17a96 | ||
|
|
c40555c0ac | ||
|
|
bfc76278a9 | ||
|
|
a1f283946e | ||
|
|
066087b383 | ||
|
|
e9d42e059f | ||
|
|
d1dadc9814 | ||
|
|
2cc620ef33 | ||
|
|
cee705ccd3 | ||
|
|
a8f72424db | ||
|
|
31ed133932 | ||
|
|
d3c6974e99 | ||
|
|
1271081865 | ||
|
|
8a638a95a0 | ||
|
|
d9f726f2a5 | ||
|
|
5f3521b3d4 | ||
|
|
9a68bd8cc8 | ||
|
|
9b7812a0f2 | ||
|
|
4858d7e454 | ||
|
|
fbb3f41dff | ||
|
|
1472048b97 | ||
|
|
4aad51a352 | ||
|
|
9a0a0c2d8c | ||
|
|
fcc809f4f1 | ||
|
|
f3369677ef | ||
|
|
a03f9eb156 | ||
|
|
aa65dd8905 | ||
|
|
856b4f4654 | ||
|
|
9369fe8c27 | ||
|
|
1549ff12f1 | ||
|
|
70357ceff2 | ||
|
|
cfe7cac1c4 | ||
|
|
fb70eca0a3 | ||
|
|
cf2bf488a2 | ||
|
|
5c02fc47b9 | ||
|
|
4021e5eea9 | ||
|
|
5cd0b6272d | ||
|
|
bf49bebe7a | ||
|
|
1e8299e893 | ||
|
|
5381061d97 | ||
|
|
274558c430 | ||
|
|
188afe20f9 | ||
|
|
1add9c9a02 | ||
|
|
e7d4b99350 | ||
|
|
8627721533 | ||
|
|
6696416107 | ||
|
|
453be2e08a | ||
|
|
83497e4dc9 | ||
|
|
3806a9c320 | ||
|
|
4da95066a0 | ||
|
|
ab1105524f | ||
|
|
d70b743e03 | ||
|
|
920dd078f3 | ||
|
|
f8e780b9dd | ||
|
|
588910129c | ||
|
|
e42867f0a8 | ||
|
|
fe20afac17 | ||
|
|
10578ff08c | ||
|
|
1f0513cf4e | ||
|
|
647470f3ae | ||
|
|
efd0dbe5c2 | ||
|
|
bd2fe64bf1 | ||
|
|
7153db954f | ||
|
|
3b425affd3 | ||
|
|
d5a79ad5d7 | ||
|
|
7951338d27 | ||
|
|
90801267ee | ||
|
|
8d57823e51 | ||
|
|
277ccc5e18 | ||
|
|
cff9db5044 | ||
|
|
216f905670 | ||
|
|
53b2308011 | ||
|
|
c368500efd | ||
|
|
2fed68a73b | ||
|
|
e7ab49c973 | ||
|
|
5496491aa4 | ||
|
|
53ca5b2870 | ||
|
|
6aced26c35 | ||
|
|
2331750b58 | ||
|
|
b3fb4c1265 | ||
|
|
3ad7b9b117 | ||
|
|
5721debdf1 | ||
|
|
c1c23d1e7b | ||
|
|
9605641982 | ||
|
|
e52672c263 | ||
|
|
50f070980e | ||
|
|
7733849478 | ||
|
|
4bbc8a89a0 | ||
|
|
c87882e82f | ||
|
|
bd4301b2c1 | ||
|
|
e771f4e75e | ||
|
|
35835469d7 | ||
|
|
0d6992fcdd | ||
|
|
29b3f471cf | ||
|
|
4985875a15 | ||
|
|
4fffd3a111 | ||
|
|
590749e8be | ||
|
|
27cc76766c | ||
|
|
d52cf87d71 | ||
|
|
2ddd6895e1 | ||
|
|
545e7d2de8 | ||
|
|
a9ed6b352b | ||
|
|
523eebe47d | ||
|
|
b303d8bc40 | ||
|
|
68118f4233 | ||
|
|
fcc6b97f88 | ||
|
|
adc4398cc5 | ||
|
|
c53d26cfca | ||
|
|
c188bee229 | ||
|
|
7f1a89e3f6 | ||
|
|
5d46f3fcab | ||
|
|
b55d95d365 | ||
|
|
494cc8bace | ||
|
|
03e8c0f45c | ||
|
|
b6388a15ff | ||
|
|
45a18a61c6 | ||
|
|
1857a44c7c | ||
|
|
bd9e1475e2 | ||
|
|
6883267996 | ||
|
|
b88c784634 | ||
|
|
31020f9eea | ||
|
|
e89d59995a | ||
|
|
bf324a11cd | ||
|
|
e149433a80 | ||
|
|
65d02e495e | ||
|
|
f196a9fd27 | ||
|
|
7f0398ca25 | ||
|
|
d7f05722d4 | ||
|
|
26377a2195 | ||
|
|
aa4eaa16bf | ||
|
|
abc7bfe5c9 | ||
|
|
f0f4499540 | ||
|
|
dae4f9fef6 | ||
|
|
4c45c6fbd8 | ||
|
|
172cf26d77 | ||
|
|
feefb7e7e2 | ||
|
|
ced44a15ea | ||
|
|
5c2855e1c1 | ||
|
|
433785dc64 | ||
|
|
28845b96bd | ||
|
|
98ec35cee1 | ||
|
|
f795297e15 | ||
|
|
3fd3c47e6d | ||
|
|
153c25dbb3 | ||
|
|
a1a6b7e64f | ||
|
|
3ea7fb18d6 | ||
|
|
6ff52332a8 | ||
|
|
5e75b104d6 | ||
|
|
dc893701f9 | ||
|
|
e6b0aaf94a | ||
|
|
e754cbf763 | ||
|
|
5988895d69 | ||
|
|
2af5eea2c6 | ||
|
|
554acb7429 | ||
|
|
9c5869ce5a | ||
|
|
e641ff64fd | ||
|
|
aa731e3297 | ||
|
|
ac6407bb8e | ||
|
|
baf08eee09 | ||
|
|
04a43cd6a1 | ||
|
|
ed8d099607 | ||
|
|
b693d0cd91 | ||
|
|
fafedd2d59 | ||
|
|
f3a7ef1199 | ||
|
|
cb890c96b9 | ||
|
|
37bfa092a5 | ||
|
|
c517cb64ae | ||
|
|
51e09fa504 | ||
|
|
691172e28b | ||
|
|
6cf6d2159b | ||
|
|
17f0b417d5 | ||
|
|
d89baf4c5b | ||
|
|
2eb52cd047 | ||
|
|
f5492aed12 | ||
|
|
c2efd6ee58 | ||
|
|
be507bf1cc | ||
|
|
f11f3ce8b7 | ||
|
|
b2a3e930c1 | ||
|
|
147bf04d08 | ||
|
|
f4d3616c4b | ||
|
|
c97c025adb | ||
|
|
c55336e78d | ||
|
|
13e9135935 | ||
|
|
5c1e44a93d | ||
|
|
75adf9e75e | ||
|
|
0fa09f6af4 | ||
|
|
011ed270e8 | ||
|
|
d7e58ce10e | ||
|
|
813536d4c6 | ||
|
|
b89023efa1 | ||
|
|
b155347560 | ||
|
|
15faf742f1 | ||
|
|
2ba7d1639e | ||
|
|
a2de7cf070 | ||
|
|
c6d558b6f2 | ||
|
|
d1b97c0ba9 | ||
|
|
755ce0a016 | ||
|
|
79334ca5ab | ||
|
|
11e9752536 | ||
|
|
72b0f9e8f7 | ||
|
|
408a162044 | ||
|
|
7d6444491c | ||
|
|
7bfb6d6b76 | ||
|
|
e1be7f3d6f | ||
|
|
04a8485b17 | ||
|
|
f330dd210e | ||
|
|
97dc27b5fa | ||
|
|
1fd43fe673 | ||
|
|
29e21cc7f3 | ||
|
|
292fc153ef | ||
|
|
25d3c83d3b | ||
|
|
6b7f3db28e | ||
|
|
eec6e28b19 | ||
|
|
f3e379cf78 | ||
|
|
0258c47774 | ||
|
|
f63df65245 | ||
|
|
099137fe9a | ||
|
|
36f253893e | ||
|
|
8280c0d64c | ||
|
|
4f98b000eb | ||
|
|
b5d61b963a | ||
|
|
a7f7984c4a | ||
|
|
dd33c16aae | ||
|
|
e0bf0c0301 | ||
|
|
8d8aacf5e9 | ||
|
|
e085ba7fcc | ||
|
|
33f881ac8b | ||
|
|
b24ef39b9d | ||
|
|
a6d8b52686 | ||
|
|
65407539bb | ||
|
|
543060683b | ||
|
|
2848e51755 | ||
|
|
0db4978899 | ||
|
|
0284a23d0a | ||
|
|
7e728869cc | ||
|
|
a19d93e1a2 | ||
|
|
5aefa1af3d | ||
|
|
f1718fb5b3 | ||
|
|
6b527a50dd | ||
|
|
74df115fc1 | ||
|
|
3adfeeec3e | ||
|
|
c4df94a1d9 | ||
|
|
da1d98d603 | ||
|
|
6683418983 | ||
|
|
2c1d97f1ad | ||
|
|
2f854428bc | ||
|
|
c1a524a969 | ||
|
|
23807e12e8 | ||
|
|
87ec1ab97b | ||
|
|
b057b979fa | ||
|
|
7dc378e296 | ||
|
|
6d8cc30f12 | ||
|
|
0335e3fcc0 | ||
|
|
76aa1059cd | ||
|
|
b0a25f0183 | ||
|
|
db1babab5e | ||
|
|
7ea951613d | ||
|
|
6506b73523 | ||
|
|
639029007d | ||
|
|
01eb59ca9b | ||
|
|
a8b5e3da29 | ||
|
|
8cc0997f79 | ||
|
|
ffb7c317b5 | ||
|
|
bb7420fc22 | ||
|
|
0df9164e7c | ||
|
|
dcd590b9de | ||
|
|
8dc3a66688 | ||
|
|
88b4adebdc | ||
|
|
01f2438c1f | ||
|
|
eb51f37c67 | ||
|
|
4ef4d0659d | ||
|
|
2ce9a3f70f | ||
|
|
59cbdaaf49 | ||
|
|
e0cf16b7e9 | ||
|
|
1cdf09e9dd | ||
|
|
9966a6a4b7 | ||
|
|
20a1d1c519 | ||
|
|
313ec87dc1 | ||
|
|
a7ba6e447d | ||
|
|
baa978ab0b | ||
|
|
9f1b4fc9e7 | ||
|
|
38e5dbd866 | ||
|
|
50ed27946d | ||
|
|
856ac7d773 | ||
|
|
81f12df8b5 | ||
|
|
9eca3234e8 | ||
|
|
5a540bdd42 | ||
|
|
6d394b132d | ||
|
|
96a317ce68 | ||
|
|
bca8945c26 | ||
|
|
a4b108334f | ||
|
|
4f72cf9744 | ||
|
|
3c30f77d31 | ||
|
|
bcb6484062 | ||
|
|
11472eddbc | ||
|
|
12470f6221 | ||
|
|
a82d0e2f57 | ||
|
|
dca1d1e0d1 | ||
|
|
0cef8f3d26 | ||
|
|
fbde18fc02 | ||
|
|
b640c59087 | ||
|
|
1f3dea60d3 | ||
|
|
a7c06eadd0 | ||
|
|
39910f5137 | ||
|
|
6fc4eb92db | ||
|
|
81e82fb2d3 | ||
|
|
c817254495 | ||
|
|
4578b0ad11 | ||
|
|
9fbf82b603 | ||
|
|
4b0267910c | ||
|
|
54456aee9e | ||
|
|
2a31cdcded | ||
|
|
d3f31c6038 | ||
|
|
59dd9f6203 | ||
|
|
05cac05c06 | ||
|
|
724713ac80 | ||
|
|
72f3d5291c | ||
|
|
c138685364 | ||
|
|
4180d00a6c | ||
|
|
2512ac1e3c | ||
|
|
121fc0a273 | ||
|
|
4d9281018f | ||
|
|
3a94a60537 | ||
|
|
161e6fb8fb | ||
|
|
29fa474e4a | ||
|
|
ddb19f4a4f | ||
|
|
789fb1e7c9 | ||
|
|
521c5317a2 | ||
|
|
e0d85e60a3 | ||
|
|
ac7821f9bf | ||
|
|
84809db955 | ||
|
|
e6cecd97ac | ||
|
|
60e7deaaf5 | ||
|
|
23b07d8cb6 | ||
|
|
5f27697198 | ||
|
|
261d2c5ae4 | ||
|
|
847f7de003 | ||
|
|
dffc8df3e0 | ||
|
|
330d491eba | ||
|
|
db103ff340 | ||
|
|
1ac46bacfe | ||
|
|
c27a4ee61f | ||
|
|
2d8c4b1c88 | ||
|
|
d969f8621d | ||
|
|
a4ec91fd06 | ||
|
|
fd53472238 | ||
|
|
b3ddef2fc2 | ||
|
|
07d753176f | ||
|
|
8d758add63 | ||
|
|
506ab1c735 | ||
|
|
945020e505 | ||
|
|
5a7bcd0a4f | ||
|
|
ae92279f5c | ||
|
|
be33f5eb89 | ||
|
|
717a582085 | ||
|
|
ee87aee4dd | ||
|
|
2d6afeebe1 | ||
|
|
49bc58da04 | ||
|
|
f5831d5132 | ||
|
|
517ccc4088 | ||
|
|
90dd56b839 | ||
|
|
d1794f4c1b | ||
|
|
75bb4346b2 | ||
|
|
13477e5478 | ||
|
|
1093897838 | ||
|
|
4d27419d7c | ||
|
|
89e6d66872 | ||
|
|
b97c16a636 | ||
|
|
751ff59e2a | ||
|
|
64a549d051 | ||
|
|
7a686d4d21 | ||
|
|
7b218737cc | ||
|
|
b1520a87c3 | ||
|
|
2a2a34601c | ||
|
|
3c64b3da97 | ||
|
|
e7889e9ce2 | ||
|
|
7c8f45747c | ||
|
|
d37def7a72 | ||
|
|
452770e374 | ||
|
|
54e44ab477 | ||
|
|
6012d52fdb | ||
|
|
7ffa0766b4 | ||
|
|
d8e17111b9 | ||
|
|
9e602a491b | ||
|
|
f529afa625 | ||
|
|
5a4deb6e88 | ||
|
|
3bcd3cef2f | ||
|
|
fbe6f945f3 | ||
|
|
bb0f3839c1 | ||
|
|
af4026104c | ||
|
|
822aee2b4f | ||
|
|
f09334dc6f | ||
|
|
d1d2609f49 | ||
|
|
9aa6cdc494 | ||
|
|
8b403081c1 | ||
|
|
dc054c3f8a | ||
|
|
94c2810b0a | ||
|
|
6e83abdbf2 | ||
|
|
f03eaaaf33 | ||
|
|
71162ebdbb | ||
|
|
c75549f6db | ||
|
|
2ebc96d8eb | ||
|
|
29f2eeea31 | ||
|
|
a13981ffe4 | ||
|
|
cf152e6030 | ||
|
|
b279196af2 | ||
|
|
98e151fda7 | ||
|
|
7f3b5fb84d | ||
|
|
3d069f7b46 | ||
|
|
65c4f955a6 | ||
|
|
246b4b01c5 | ||
|
|
a680b71dc7 | ||
|
|
d0b5b09318 | ||
|
|
67f3a83c31 | ||
|
|
5dd260c336 | ||
|
|
ee6f165a1f | ||
|
|
0cc2ff83ed | ||
|
|
a9e92d6c5c | ||
|
|
ea5f07110b | ||
|
|
59746c2e36 | ||
|
|
6399e05209 | ||
|
|
08de642536 | ||
|
|
ab9e1b3aa7 | ||
|
|
af6744b112 | ||
|
|
1d86803e38 | ||
|
|
b12c19162b | ||
|
|
220608e52a | ||
|
|
06fb5c7c69 | ||
|
|
8970fd5d2f | ||
|
|
67d5f65507 | ||
|
|
7d678be07a | ||
|
|
74e2aa9c66 | ||
|
|
b9cc158e52 | ||
|
|
e68cf1c9ed | ||
|
|
f0fcc73f92 | ||
|
|
a340b3812c | ||
|
|
78c833a09f | ||
|
|
38888ba5b3 | ||
|
|
99e519cf0f | ||
|
|
09cb45001b | ||
|
|
9d3aa5a253 | ||
|
|
314308f975 | ||
|
|
b658ff2124 | ||
|
|
c844ea4423 | ||
|
|
db5af8ead1 | ||
|
|
c09dee7717 | ||
|
|
352281313f | ||
|
|
8afe18f148 | ||
|
|
90f348d26a | ||
|
|
8d3d06b7a0 | ||
|
|
c56ee8ec03 | ||
|
|
76f6c10434 | ||
|
|
cf64f2baca | ||
|
|
68a0193d95 | ||
|
|
80740f0e46 | ||
|
|
c60f790793 | ||
|
|
e0b4ec54bd | ||
|
|
d1bed6bf45 | ||
|
|
b82966e775 | ||
|
|
19a9d87486 | ||
|
|
3448e5867e | ||
|
|
e013d6b98c | ||
|
|
d392739049 | ||
|
|
12266ad004 | ||
|
|
e03c160e27 | ||
|
|
03f0e2196e | ||
|
|
34ea38c12e | ||
|
|
a33de607df | ||
|
|
e39959a132 | ||
|
|
33a42202c7 | ||
|
|
efc358da9f | ||
|
|
c1b39eb2ce | ||
|
|
12e30f0eb4 | ||
|
|
94bf971f72 | ||
|
|
bcfa9241b8 | ||
|
|
eea9d6136f | ||
|
|
c35f33e61a | ||
|
|
78eeba940a | ||
|
|
b3ed5f77f2 | ||
|
|
38f6b5ea71 | ||
|
|
c000a6164c | ||
|
|
cb6208a6fa | ||
|
|
b540558db6 | ||
|
|
e70b2dfbb2 | ||
|
|
f64cad89c4 | ||
|
|
935b3de2ad | ||
|
|
abc0359522 | ||
|
|
fcd48d9b2d | ||
|
|
97a79a4511 | ||
|
|
31172b0ecc | ||
|
|
74bd1613bd | ||
|
|
1fb3f95fdb | ||
|
|
ca571e7a7a | ||
|
|
52b6be0dfe | ||
|
|
abd6a6784e | ||
|
|
978df46611 | ||
|
|
31c428cece | ||
|
|
67c892991a | ||
|
|
5743adc467 | ||
|
|
76fc166e11 | ||
|
|
459cd21070 | ||
|
|
fc53e3339f | ||
|
|
9b788a882d | ||
|
|
5a3e0d5e85 | ||
|
|
ce4da69cc0 | ||
|
|
1a779077db | ||
|
|
e79531b292 | ||
|
|
7fea60183f | ||
|
|
41df6c4df2 | ||
|
|
b6a28b497b | ||
|
|
c75fbabc0f | ||
|
|
4cc0876efa | ||
|
|
abe1e37253 | ||
|
|
4dec965569 | ||
|
|
f478eaa98e | ||
|
|
1e105f88ca | ||
|
|
6586f3ed29 | ||
|
|
ba7019de8a | ||
|
|
9562ce3b87 | ||
|
|
a48fe674ee | ||
|
|
d439f75491 | ||
|
|
c559067f77 | ||
|
|
30bd80bd85 | ||
|
|
5709cb10d1 | ||
|
|
9329f8d3cd | ||
|
|
884c23a9c9 | ||
|
|
7a3a560c44 | ||
|
|
2963da1392 | ||
|
|
54f1941691 | ||
|
|
ca14ae19db | ||
|
|
6636ae6e63 | ||
|
|
2e75f42c69 | ||
|
|
c9547f383a | ||
|
|
65576707bf | ||
|
|
6ec8a06a09 | ||
|
|
9205c9d031 | ||
|
|
1ef80d6330 | ||
|
|
322665a22f | ||
|
|
cfa6d12691 | ||
|
|
c264c3e2dd | ||
|
|
d21bcd2f87 | ||
|
|
84f25b9f18 | ||
|
|
576fec4c36 | ||
|
|
48acafd10d | ||
|
|
a532a072ce | ||
|
|
2cd53c6ff1 | ||
|
|
18ccd55725 | ||
|
|
87eb569929 | ||
|
|
92387b1527 | ||
|
|
dd2f293f33 | ||
|
|
24e4f0aa87 | ||
|
|
6fe899af10 | ||
|
|
107fe0a142 | ||
|
|
b021be29e5 | ||
|
|
55e7844ca0 | ||
|
|
8dd85285e7 | ||
|
|
dbcbeb7a57 | ||
|
|
a9aee1c5b3 | ||
|
|
b3fe4b54c8 | ||
|
|
872ea6bf09 | ||
|
|
32fb9d51b9 | ||
|
|
ce637440bb | ||
|
|
61e4597488 | ||
|
|
26a064ed2d | ||
|
|
d5c9bac3c7 | ||
|
|
1665006401 | ||
|
|
5220ac4a9e | ||
|
|
ee0fdf016a | ||
|
|
8b4eedb594 | ||
|
|
01f5efa1d9 | ||
|
|
130bc26b9a | ||
|
|
09e83937de | ||
|
|
42e30468a9 | ||
|
|
3834acad5b | ||
|
|
654f7eceee | ||
|
|
ca9c8ae5fb | ||
|
|
1752086cfd | ||
|
|
369b2f7cd2 | ||
|
|
8b244ca988 | ||
|
|
fb9e51d943 | ||
|
|
bb3dc87953 | ||
|
|
6bcb422c80 | ||
|
|
540f865355 | ||
|
|
46ef71e3ec | ||
|
|
005450ff13 | ||
|
|
f809427575 | ||
|
|
9564eb2edb | ||
|
|
49708f209b | ||
|
|
14381fe8d0 | ||
|
|
17bec5c3ce | ||
|
|
2b90ab496a | ||
|
|
74dbf4cf70 | ||
|
|
e504aceeb5 | ||
|
|
3ce9ac74a6 | ||
|
|
3b0e7b4d0d | ||
|
|
5e856c6b4d | ||
|
|
6651a48c4d | ||
|
|
c031ae2aab | ||
|
|
1ac6c9f9c2 | ||
|
|
5d0eb6dda5 | ||
|
|
29c949ab03 | ||
|
|
576e389788 | ||
|
|
7b15a3d345 | ||
|
|
eedb43d756 | ||
|
|
338125b93a | ||
|
|
3ecc3ab798 | ||
|
|
de1cdb2dbe | ||
|
|
c9887874bc | ||
|
|
69fcaf14e5 | ||
|
|
f414198fee | ||
|
|
2de924a187 | ||
|
|
c1c2ff2d07 | ||
|
|
ff89f1476d | ||
|
|
e8d99cee70 | ||
|
|
ccfa3f03b0 | ||
|
|
baefe0b3f6 | ||
|
|
3669351427 | ||
|
|
79938b98da | ||
|
|
411d588fea | ||
|
|
7e63d773ef | ||
|
|
3e378f009d | ||
|
|
13db9d9452 | ||
|
|
c1c6e6265c | ||
|
|
a984b1b073 | ||
|
|
215b6aea95 | ||
|
|
96b7214ae2 | ||
|
|
1b0752b0a9 | ||
|
|
02329f61e3 | ||
|
|
7e29c48379 | ||
|
|
ad63efdaf7 | ||
|
|
6bec53dcd2 | ||
|
|
fef405ac98 | ||
|
|
97f9cc4bc0 | ||
|
|
7ab6fd9db6 | ||
|
|
b7ecec0c23 | ||
|
|
d12a858897 | ||
|
|
9716ff69c4 | ||
|
|
4dd1a24d0b | ||
|
|
c69c49047b | ||
|
|
bfbb4e4050 | ||
|
|
2aceb13f3e | ||
|
|
e9f34fbd26 | ||
|
|
17f9cdd401 | ||
|
|
156b856a80 | ||
|
|
e2e3df9013 | ||
|
|
ef8773a89b | ||
|
|
536f5d8203 | ||
|
|
631416d54a | ||
|
|
d366a06461 | ||
|
|
7bf8f14879 | ||
|
|
cd65d6de69 | ||
|
|
b57d514b1e | ||
|
|
f36be4d5e4 | ||
|
|
c2b0e223fa | ||
|
|
e32c856a04 | ||
|
|
bc7cd2ccc2 | ||
|
|
1842669104 | ||
|
|
c7535a91a6 | ||
|
|
99a5484dfb | ||
|
|
b78ae5ab10 | ||
|
|
f74d3e7e94 | ||
|
|
eba37e8fbe | ||
|
|
84fb11599e | ||
|
|
099812d219 | ||
|
|
c4291510e8 | ||
|
|
775a411215 | ||
|
|
59b4dd4c46 | ||
|
|
2f907e3a92 | ||
|
|
9971fd2864 | ||
|
|
23a394d1fc | ||
|
|
91d450df4e | ||
|
|
ea3943a87a | ||
|
|
019eda5b0c | ||
|
|
5056437ca1 | ||
|
|
90c912a5e2 | ||
|
|
9219613957 | ||
|
|
9858f2e499 | ||
|
|
6b0bf33f8e | ||
|
|
9ea6079072 | ||
|
|
478f16234d | ||
|
|
57a312cb1a | ||
|
|
bb88a74f92 | ||
|
|
4a07ce5fae | ||
|
|
043c4acc7e | ||
|
|
eb478e38b2 | ||
|
|
bf307e24c5 | ||
|
|
4a00590a1b | ||
|
|
4ccca079a5 | ||
|
|
9e5d1b3ba5 | ||
|
|
240f13a0a6 | ||
|
|
221ce33eb5 | ||
|
|
722943000e | ||
|
|
509a503761 | ||
|
|
bac1e4a850 | ||
|
|
934cc892eb | ||
|
|
b1c90f08cc | ||
|
|
680f19a424 | ||
|
|
621e0a8330 | ||
|
|
4449bf6f83 | ||
|
|
569c62e528 | ||
|
|
4c240edf94 | ||
|
|
0e977d66c1 | ||
|
|
3dee10772d | ||
|
|
1d72edcc4f | ||
|
|
c29b7d22d9 | ||
|
|
ee502aed49 | ||
|
|
414ff25564 | ||
|
|
b084b8b1d8 | ||
|
|
3ca19a8580 | ||
|
|
9c12a44d6e | ||
|
|
4706b0ada4 | ||
|
|
cc98e9850d | ||
|
|
af80db8c22 | ||
|
|
053d5ad24d | ||
|
|
e2805ac68a | ||
|
|
1caf05cc52 | ||
|
|
63cfb7db25 | ||
|
|
bdfc7d2a5a | ||
|
|
0ccbdcdd1f | ||
|
|
c598b2fa2d | ||
|
|
4f86448bd4 | ||
|
|
d235e7d46f | ||
|
|
e25b323d1b | ||
|
|
42093c48b2 | ||
|
|
9fca0b20f0 | ||
|
|
a6229d9e87 | ||
|
|
c443896644 | ||
|
|
79f11bd655 | ||
|
|
c5552dac1f | ||
|
|
734af31c13 | ||
|
|
2d96896fae | ||
|
|
20a0f82701 | ||
|
|
e4b7dbce7f | ||
|
|
0f128fd561 | ||
|
|
ac8a7bc12d | ||
|
|
90a299f424 | ||
|
|
00a7f5d75d | ||
|
|
2463fe92bd | ||
|
|
4f65fcd7b1 | ||
|
|
e41b92c55a | ||
|
|
3925f8fa16 | ||
|
|
cce1e36e26 | ||
|
|
3466c9c8cb | ||
|
|
6e2dadc63a | ||
|
|
00e89a23f6 | ||
|
|
a29e518cfe | ||
|
|
a7148b718e | ||
|
|
23fdc0eae4 | ||
|
|
8cb1bc89f1 | ||
|
|
1798a1fa12 | ||
|
|
f4c737ef42 | ||
|
|
611df4964d | ||
|
|
0a4ccf22da | ||
|
|
4fe98bf6e6 | ||
|
|
57c3023881 | ||
|
|
4408e079ff | ||
|
|
2991057aef | ||
|
|
6b4fea39ab | ||
|
|
a08ffcff50 | ||
|
|
6bd9f4a13a | ||
|
|
32420b77c8 | ||
|
|
0b8a84f536 | ||
|
|
f18a55831c | ||
|
|
58fb0decbf | ||
|
|
2124b7bf64 | ||
|
|
5b273a33b4 | ||
|
|
fb702f989f | ||
|
|
0203a0fdaf | ||
|
|
112a7ada74 | ||
|
|
452ba76507 | ||
|
|
2ac42c0d14 | ||
|
|
0955ea5b85 | ||
|
|
084bc72d90 | ||
|
|
57e2193432 | ||
|
|
ce8cf1e152 | ||
|
|
3da189f7c0 | ||
|
|
058d2d1bd4 | ||
|
|
f70f2f8c62 | ||
|
|
8d6086da48 | ||
|
|
bd6d88b884 | ||
|
|
4003218ceb | ||
|
|
ec3f2b76b0 | ||
|
|
fcb661d0e9 | ||
|
|
d8eb0558e9 | ||
|
|
5191948b64 | ||
|
|
7442d720f4 | ||
|
|
bbc859ca19 | ||
|
|
7275fb6f52 | ||
|
|
2d50202b2d | ||
|
|
f5dc16603e | ||
|
|
85b4d7c8d6 | ||
|
|
f0c962d274 | ||
|
|
486b6937d3 | ||
|
|
a6152ebadd | ||
|
|
63a475d88c | ||
|
|
3eba3224c8 | ||
|
|
247c4e55e7 | ||
|
|
26d7c27bee | ||
|
|
b492642282 | ||
|
|
cff78f5833 | ||
|
|
4ba19821ce | ||
|
|
1e385851d7 | ||
|
|
4643f74a03 | ||
|
|
6453d396bf | ||
|
|
92921f767e | ||
|
|
c251c4ccbb | ||
|
|
0ce670e45a | ||
|
|
2671b48a6c | ||
|
|
382478259f | ||
|
|
e3c333be47 | ||
|
|
a1a463787f | ||
|
|
a16ff07a06 | ||
|
|
3218caf34a | ||
|
|
01583ef540 | ||
|
|
dc13700094 | ||
|
|
1293af093c | ||
|
|
2998815166 | ||
|
|
9484c4dc05 | ||
|
|
521b0733d4 | ||
|
|
a463989278 | ||
|
|
a31719b546 | ||
|
|
f97cb00737 | ||
|
|
f2305fe5bf | ||
|
|
216cd6935f | ||
|
|
3a8f9484d2 | ||
|
|
3fa76b2d8f | ||
|
|
50648553cf | ||
|
|
70d03fd9c3 | ||
|
|
0a8cce6984 | ||
|
|
fb1a3a3a12 | ||
|
|
52e2722412 | ||
|
|
b64e4464a7 | ||
|
|
f1ab6feba2 | ||
|
|
e751461ff1 | ||
|
|
c7f42d1a4a | ||
|
|
6232ec78f7 | ||
|
|
f09d0f2301 | ||
|
|
14a071c478 | ||
|
|
e601ebe19b | ||
|
|
7068c45115 | ||
|
|
3bfcb0468e | ||
|
|
b2735eb30c | ||
|
|
552416bda4 | ||
|
|
b522413085 | ||
|
|
8a0fc92f20 | ||
|
|
4a34cd0662 | ||
|
|
11d83515dd | ||
|
|
7ce8ae72e8 | ||
|
|
cc7e122915 | ||
|
|
da84893921 | ||
|
|
1d5b6d7ae6 | ||
|
|
314991ac60 | ||
|
|
9b5b4cd505 | ||
|
|
c5069135d7 | ||
|
|
971c1f46b0 | ||
|
|
34c60e5486 | ||
|
|
526f21ae7f | ||
|
|
48597a94e8 | ||
|
|
0e77c3391b | ||
|
|
f1e79bde2e | ||
|
|
7b6849578b | ||
|
|
617fcc92cf | ||
|
|
18f0e4ba1a | ||
|
|
6fedffe6d6 | ||
|
|
d54e302a28 | ||
|
|
d99179f822 | ||
|
|
a6fbb3ef4c | ||
|
|
65cff673b8 | ||
|
|
dc166cad92 | ||
|
|
7d7ccac416 | ||
|
|
e933c5f481 | ||
|
|
2ba4b23b85 | ||
|
|
ba4ed0eb7f | ||
|
|
3cdf2b7f04 | ||
|
|
99b68c8352 | ||
|
|
a446f187c1 | ||
|
|
3ff541cf77 | ||
|
|
10895796b2 | ||
|
|
fbc58ebef8 | ||
|
|
5c54414be7 | ||
|
|
4df28728e2 | ||
|
|
f14a4c0b18 | ||
|
|
f5a27250b1 | ||
|
|
f95b189fe3 | ||
|
|
1aace95c8d | ||
|
|
7844471971 | ||
|
|
794a636dd3 | ||
|
|
e35414a0f1 | ||
|
|
0d0706a204 | ||
|
|
80f19324bc | ||
|
|
1b04c222cf | ||
|
|
5d04848886 | ||
|
|
fc14e831eb | ||
|
|
04d577262a | ||
|
|
7be3d2afe9 | ||
|
|
d1237d8984 | ||
|
|
1b391ccd06 | ||
|
|
7377bfcf07 | ||
|
|
665b708e6e | ||
|
|
f87049370f | ||
|
|
47948a34dd | ||
|
|
121a7dcedf | ||
|
|
240a58fd6e | ||
|
|
99e23b41eb | ||
|
|
cadb3d7da2 | ||
|
|
392d126372 | ||
|
|
871cca2401 | ||
|
|
1bdd556d3b | ||
|
|
9daad800a8 | ||
|
|
8d2c956563 | ||
|
|
0584d6d89b | ||
|
|
5763733490 | ||
|
|
894438d5fb | ||
|
|
2ad191aeba | ||
|
|
dd9d7e62d5 | ||
|
|
4e3e80109a | ||
|
|
70bef682b0 | ||
|
|
c2a9bf9974 | ||
|
|
23da9f13b0 | ||
|
|
a5a39c52b0 | ||
|
|
6355e9895d | ||
|
|
abf4af2645 | ||
|
|
cb71fea0f6 | ||
|
|
3e2d593dde | ||
|
|
4b66e94ecf | ||
|
|
40143cae1e | ||
|
|
b1277caeeb | ||
|
|
13cc6478fb | ||
|
|
c465250c21 | ||
|
|
815b52b8fb | ||
|
|
275167d1b0 | ||
|
|
45717147f7 | ||
|
|
f2f9f324ec | ||
|
|
8131d3e127 | ||
|
|
226d5a1d36 | ||
|
|
312fe4775d | ||
|
|
b368d18b0f | ||
|
|
8e4996baf4 | ||
|
|
b7cd502054 | ||
|
|
53ac379bc5 | ||
|
|
22f85deb2c | ||
|
|
52a01b2cf2 |
113
.clang-format
113
.clang-format
@@ -1,108 +1,19 @@
|
||||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: LLVM
|
||||
BasedOnStyle: Google
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: DontAlign
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: true
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: true
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterClass: true
|
||||
AfterControlStatement: true
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: true
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
BeforeCatch: true
|
||||
BeforeElse: true
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: true
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 140
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IndentCaseLabels: false
|
||||
Standard: c++17
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Cpp11
|
||||
TabWidth: 8
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
ColumnLimit: 130
|
||||
AlignAfterOpenBracket: Align
|
||||
BinPackParameters: false
|
||||
AlignEscapedNewlines: Left
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
PackConstructorInitializers: Never
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
IndentPPDirectives: BeforeHash
|
||||
SortIncludes: CaseInsensitive
|
||||
...
|
||||
|
||||
|
||||
36
.clang-tidy
36
.clang-tidy
@@ -1,10 +1,37 @@
|
||||
Checks: 'modernize-*,modernize-use-override,google-*,-google-runtime-references,misc-*,clang-analyzer-*'
|
||||
Checks: 'cppcoreguidelines-*,
|
||||
performance-*,
|
||||
modernize-*,
|
||||
google-*,
|
||||
misc-*
|
||||
cert-*,
|
||||
readability-*,
|
||||
clang-analyzer-*,
|
||||
-performance-unnecessary-value-param,
|
||||
-modernize-use-trailing-return-type,
|
||||
-google-runtime-references,
|
||||
-misc-non-private-member-variables-in-classes,
|
||||
-readability-braces-around-statements,
|
||||
-readability-identifier-length,
|
||||
-google-readability-braces-around-statements,
|
||||
-cppcoreguidelines-avoid-magic-numbers,
|
||||
-readability-magic-numbers,
|
||||
-readability-magic-numbers,
|
||||
-cppcoreguidelines-pro-type-vararg,
|
||||
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
|
||||
-cppcoreguidelines-avoid-c-arrays,
|
||||
-modernize-avoid-c-arrays,
|
||||
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
|
||||
-readability-named-parameter,
|
||||
-cert-env33-c,
|
||||
-modernize-concat-nested-namespaces,
|
||||
-cppcoreguidelines-owning-memory
|
||||
'
|
||||
|
||||
|
||||
WarningsAsErrors: ''
|
||||
HeaderFilterRegex: 'async.h|async_logger.h|common.h|details|formatter.h|logger.h|sinks|spdlog.h|tweakme.h|version.h'
|
||||
AnalyzeTemporaryDtors: false
|
||||
FormatStyle: none
|
||||
|
||||
CheckOptions:
|
||||
CheckOptions:
|
||||
- key: google-readability-braces-around-statements.ShortStatementLines
|
||||
value: '1'
|
||||
- key: google-readability-function-size.StatementThreshold
|
||||
@@ -25,4 +52,3 @@ CheckOptions:
|
||||
value: llvm
|
||||
- key: modernize-use-nullptr.NullMacros
|
||||
value: 'NULL'
|
||||
|
||||
|
||||
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
* text=false
|
||||
61
.github/workflows/linux.yml
vendored
Normal file
61
.github/workflows/linux.yml
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
name: linux
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
# -----------------------------------------------------------------------
|
||||
# Linux build matrix
|
||||
# -----------------------------------------------------------------------
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config:
|
||||
- { compiler: gcc, version: 9, build_type: Release, cppstd: 17 }
|
||||
- { compiler: gcc, version: 11, build_type: Debug, cppstd: 20 }
|
||||
- { compiler: gcc, version: 12, build_type: Release, cppstd: 20 }
|
||||
- { compiler: gcc, version: 12, build_type: Debug, cppstd: 20, asan: ON }
|
||||
- { compiler: clang, version: 12, build_type: Debug, cppstd: 17 }
|
||||
- { compiler: clang, version: 15, build_type: Debug, cppstd: 20, tsan: ON }
|
||||
container:
|
||||
image: ${{ matrix.config.compiler == 'clang' && 'teeks99/clang-ubuntu' || matrix.config.compiler }}:${{ matrix.config.version }}
|
||||
name: "${{ matrix.config.compiler}} ${{ matrix.config.version }} (C++${{ matrix.config.cppstd }} ${{ matrix.config.build_type }} ${{ matrix.config.asan == 'ON' && 'ASAN' || '' }}${{ matrix.config.tsan == 'ON' && 'TSAN' || '' }})"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Setup
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install -y curl git pkg-config libsystemd-dev
|
||||
CMAKE_VERSION="3.24.2"
|
||||
curl -sSL https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-x86_64.sh -o install-cmake.sh
|
||||
chmod +x install-cmake.sh
|
||||
./install-cmake.sh --prefix=/usr/local --skip-license
|
||||
- name: Setup Compiler
|
||||
if: matrix.config.compiler == 'clang'
|
||||
run: |
|
||||
scripts/ci_setup_clang.sh "${{ matrix.config.version }}"
|
||||
echo "CXXFLAGS=-stdlib=libc++" >> $GITHUB_ENV
|
||||
echo "CC=clang-${{ matrix.config.version }}" >> $GITHUB_ENV
|
||||
echo "CXX=clang++-${{ matrix.config.version }}" >> $GITHUB_ENV
|
||||
- name: Build
|
||||
run: |
|
||||
mkdir -p build && cd build
|
||||
cmake .. \
|
||||
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
|
||||
-DCMAKE_CXX_STANDARD=${{ matrix.config.cppstd }} \
|
||||
-DSPDLOG_BUILD_EXAMPLE=${{ matrix.config.examples || 'ON' }} \
|
||||
-DSPDLOG_BUILD_WARNINGS=ON \
|
||||
-DSPDLOG_BUILD_BENCH=OFF \
|
||||
-DSPDLOG_BUILD_TESTS=ON \
|
||||
-DSPDLOG_SANITIZE_ADDRESS=${{ matrix.config.asan || 'OFF' }} \
|
||||
-DSPDLOG_SANITIZE_ADDRESS=${{ matrix.config.asan || 'OFF' }} \
|
||||
-DSPDLOG_SANITIZE_THREAD=${{ matrix.config.tsan || 'OFF' }}
|
||||
make -j 4
|
||||
ctest -j 4 --output-on-failure
|
||||
26
.github/workflows/macos.yml
vendored
Normal file
26
.github/workflows/macos.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
name: macos
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: macOS-latest
|
||||
name: "macOS Clang (C++17, Release)"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build
|
||||
run: |
|
||||
mkdir -p build && cd build
|
||||
cmake .. \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_CXX_STANDARD=17 \
|
||||
-DSPDLOG_BUILD_EXAMPLE=ON \
|
||||
-DSPDLOG_BUILD_WARNINGS=ON \
|
||||
-DSPDLOG_BUILD_BENCH=OFF \
|
||||
-DSPDLOG_BUILD_TESTS=ON \
|
||||
-DSPDLOG_SANITIZE_ADDRESS=OFF
|
||||
make -j 4
|
||||
ctest -j 4 --output-on-failure
|
||||
113
.github/workflows/windows.yml
vendored
Normal file
113
.github/workflows/windows.yml
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
name: windows
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config:
|
||||
- GENERATOR: "Visual Studio 17 2022"
|
||||
BUILD_TYPE: Release
|
||||
BUILD_SHARED: 'ON'
|
||||
FATAL_ERRORS: 'ON'
|
||||
BUILD_EXAMPLE: 'OFF'
|
||||
CXX_STANDARD: 20
|
||||
- GENERATOR: "Visual Studio 17 2022"
|
||||
BUILD_TYPE: Release
|
||||
BUILD_SHARED: 'ON'
|
||||
FATAL_ERRORS: 'ON'
|
||||
BUILD_EXAMPLE: 'OFF'
|
||||
CXX_STANDARD: 17
|
||||
- GENERATOR: "Visual Studio 17 2022"
|
||||
BUILD_TYPE: Release
|
||||
BUILD_SHARED: 'OFF'
|
||||
FATAL_ERRORS: 'ON'
|
||||
BUILD_EXAMPLE: 'ON'
|
||||
CXX_STANDARD: 17
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: CMake ${{ matrix.config.GENERATOR }} CXX=${{matrix.config.CXX_STANDARD}}
|
||||
shell: pwsh
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -G "${{ matrix.config.GENERATOR }}" -A x64 `
|
||||
-D CMAKE_BUILD_TYPE=${{ matrix.config.BUILD_TYPE }} `
|
||||
-D BUILD_SHARED_LIBS=${{ matrix.config.BUILD_SHARED }} `
|
||||
-D SPDLOG_BUILD_EXAMPLE=${{ matrix.config.BUILD_EXAMPLE }} `
|
||||
-D SPDLOG_BUILD_TESTS=ON `
|
||||
-D SPDLOG_BUILD_WARNINGS=${{ matrix.config.FATAL_ERRORS }} `
|
||||
-D CMAKE_CXX_STANDARD=${{ matrix.config.CXX_STANDARD }} ..
|
||||
|
||||
- name: Build
|
||||
shell: pwsh
|
||||
run: |
|
||||
cd build
|
||||
cmake --build . --parallel --config ${{ matrix.config.BUILD_TYPE }}
|
||||
|
||||
- name: Run Tests
|
||||
shell: pwsh
|
||||
env:
|
||||
PATH: ${{ env.PATH }};${{ github.workspace }}\build\_deps\catch2-build\src\${{ matrix.config.BUILD_TYPE }};${{ github.workspace }}\build\bin\${{ matrix.config.BUILD_TYPE }}
|
||||
run: ${{ github.workspace }}\build\bin\${{ matrix.config.BUILD_TYPE }}\spdlog-utests.exe
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------
|
||||
# MSVC 2019 build matrix
|
||||
# -----------------------------------------------------------------------
|
||||
build_2019:
|
||||
runs-on: windows-2019
|
||||
strategy:
|
||||
fail-fast: true
|
||||
matrix:
|
||||
config:
|
||||
- GENERATOR: "Visual Studio 16 2019"
|
||||
BUILD_TYPE: Release
|
||||
BUILD_SHARED: 'ON'
|
||||
FATAL_ERRORS: 'ON'
|
||||
BUILD_EXAMPLE: 'ON'
|
||||
CXX_STANDARD: 17
|
||||
- GENERATOR: "Visual Studio 16 2019"
|
||||
BUILD_TYPE: Release
|
||||
BUILD_SHARED: 'ON'
|
||||
FATAL_ERRORS: 'ON'
|
||||
BUILD_EXAMPLE: 'ON'
|
||||
CXX_STANDARD: 20
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: CMake ${{ matrix.config.GENERATOR }} CXX=${{matrix.config.CXX_STANDARD}}
|
||||
shell: pwsh
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -G "${{ matrix.config.GENERATOR }}" -A x64 `
|
||||
-D CMAKE_BUILD_TYPE=${{ matrix.config.BUILD_TYPE }} `
|
||||
-D BUILD_SHARED_LIBS=${{ matrix.config.BUILD_SHARED }} `
|
||||
-D SPDLOG_BUILD_EXAMPLE=${{ matrix.config.BUILD_EXAMPLE }} `
|
||||
-D SPDLOG_BUILD_TESTS=ON `
|
||||
-D SPDLOG_BUILD_WARNINGS=${{ matrix.config.FATAL_ERRORS }} `
|
||||
-D CMAKE_CXX_STANDARD=${{ matrix.config.CXX_STANDARD }} ..
|
||||
|
||||
- name: Build
|
||||
shell: pwsh
|
||||
run: |
|
||||
cd build
|
||||
cmake --build . --parallel --config ${{ matrix.config.BUILD_TYPE }}
|
||||
|
||||
- name: Run Tests
|
||||
shell: pwsh
|
||||
env:
|
||||
PATH: ${{ env.PATH }};${{ github.workspace }}\build\_deps\catch2-build\src\${{ matrix.config.BUILD_TYPE }};${{ github.workspace }}\build\bin\${{ matrix.config.BUILD_TYPE }}
|
||||
run: ${{ github.workspace }}\build\bin\${{ matrix.config.BUILD_TYPE }}\spdlog-utests.exe
|
||||
45
.gitignore
vendored
45
.gitignore
vendored
@@ -1,5 +1,8 @@
|
||||
# Auto generated files
|
||||
build/*
|
||||
include/spdlog/spdlog_config.h
|
||||
[Dd]ebug/
|
||||
[Rr]elease/
|
||||
build/*
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
@@ -34,23 +37,16 @@ build/*
|
||||
# Codelite
|
||||
.codelite
|
||||
|
||||
# KDevelop
|
||||
*.kdev4
|
||||
|
||||
# .orig files
|
||||
*.orig
|
||||
|
||||
# example files
|
||||
example/*
|
||||
!example/example.cpp
|
||||
!example/bench.cpp
|
||||
!example/utils.h
|
||||
!example/Makefile*
|
||||
!example/example.sln
|
||||
!example/example.vcxproj
|
||||
!example/CMakeLists.txt
|
||||
!example/multisink.cpp
|
||||
!example/jni
|
||||
|
||||
# generated files
|
||||
generated
|
||||
version.rc
|
||||
|
||||
# Cmake
|
||||
CMakeCache.txt
|
||||
@@ -63,6 +59,29 @@ install_manifest.txt
|
||||
/tests/tests.VC.db
|
||||
/tests/tests
|
||||
/tests/logs/*
|
||||
spdlogConfig.cmake
|
||||
spdlogConfigVersion.cmake
|
||||
compile_commands.json
|
||||
|
||||
# idea
|
||||
.idea/
|
||||
.idea/
|
||||
.cache/
|
||||
.vscode/
|
||||
cmake-build-*/
|
||||
*.db
|
||||
*.ipch
|
||||
*.filters
|
||||
*.db-wal
|
||||
*.opendb
|
||||
*.db-shm
|
||||
*.vcxproj
|
||||
*.tcl
|
||||
*.user
|
||||
*.sln
|
||||
|
||||
# macos
|
||||
*.DS_store
|
||||
*.xcodeproj/
|
||||
/.vs
|
||||
/out/build
|
||||
/CMakeSettings.json
|
||||
|
||||
23
.readthedocs.yaml
Normal file
23
.readthedocs.yaml
Normal file
@@ -0,0 +1,23 @@
|
||||
# Read the Docs configuration file
|
||||
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
|
||||
|
||||
# Required
|
||||
version: 2
|
||||
|
||||
# Set the OS, Python version, and other tools you might need
|
||||
build:
|
||||
os: ubuntu-24.04
|
||||
tools:
|
||||
python: "3.13"
|
||||
|
||||
# Build documentation with Mkdocs
|
||||
mkdocs:
|
||||
configuration: docs/mkdocs.yml
|
||||
|
||||
# Optionally, but recommended,
|
||||
# declare the Python requirements required to build your documentation
|
||||
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
|
||||
# python:
|
||||
# install:
|
||||
# - requirements: docs/requirements.txt
|
||||
|
||||
115
.travis.yml
115
.travis.yml
@@ -1,115 +0,0 @@
|
||||
# Adapted from various sources, including:
|
||||
# - Louis Dionne's Hana: https://github.com/ldionne/hana
|
||||
# - Paul Fultz II's FIT: https://github.com/pfultz2/Fit
|
||||
# - Eric Niebler's range-v3: https://github.com/ericniebler/range-v3
|
||||
sudo: required
|
||||
language: cpp
|
||||
|
||||
addons: &gcc48
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
addons: &gcc7
|
||||
apt:
|
||||
packages:
|
||||
- g++-7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
addons: &clang35
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.5
|
||||
|
||||
addons: &clang6
|
||||
apt:
|
||||
packages:
|
||||
- clang-6.0
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-trusty-6.0
|
||||
|
||||
|
||||
matrix:
|
||||
include:
|
||||
# Test gcc-4.8: C++11, Build=Debug/Release
|
||||
- env: GCC_VERSION=4.8 BUILD_TYPE=Debug CPP=11
|
||||
os: linux
|
||||
addons: *gcc48
|
||||
|
||||
- env: GCC_VERSION=4.8 BUILD_TYPE=Release CPP=11
|
||||
os: linux
|
||||
addons: *gcc48
|
||||
|
||||
- env: GCC_VERSION=7 BUILD_TYPE=Release CPP=11
|
||||
os: linux
|
||||
addons: *gcc7
|
||||
|
||||
# Test clang-3.5: C++11, Build=Debug/Release
|
||||
- env: CLANG_VERSION=3.5 BUILD_TYPE=Debug CPP=11
|
||||
os: linux
|
||||
addons: *clang35
|
||||
|
||||
- env: CLANG_VERSION=3.5 BUILD_TYPE=Release CPP=11
|
||||
os: linux
|
||||
addons: *clang35
|
||||
|
||||
# Test clang-6.0: C++11, Build=Debug, ASAN=On
|
||||
- env: CLANG_VERSION=6.0 BUILD_TYPE=Debug CPP=11 ASAN=On TSAN=Off
|
||||
os: linux
|
||||
addons: *clang6
|
||||
|
||||
- env: CLANG_VERSION=6.0 BUILD_TYPE=Release CPP=11 ASAN=On TSAN=Off
|
||||
os: linux
|
||||
addons: *clang6
|
||||
|
||||
# Test clang-6.0: C++11, Build=Debug, TSAN=On
|
||||
- env: CLANG_VERSION=6.0 BUILD_TYPE=Debug CPP=11 ASAN=Off TSAN=On
|
||||
os: linux
|
||||
addons: *clang6
|
||||
|
||||
- env: CLANG_VERSION=6.0 BUILD_TYPE=Release CPP=11 ASAN=Off TSAN=On
|
||||
os: linux
|
||||
addons: *clang6
|
||||
|
||||
# osx
|
||||
- env: BUILD_TYPE=Release CPP=11 ASAN=Off TSAN=Off
|
||||
os: osx
|
||||
|
||||
|
||||
|
||||
|
||||
before_script:
|
||||
- if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi
|
||||
- if [ -n "$CLANG_VERSION" ]; then export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"; fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export CXX="clang++" CC="clang"; fi
|
||||
- which $CXX
|
||||
- which $CC
|
||||
- $CXX --version
|
||||
- cmake --version
|
||||
|
||||
script:
|
||||
- cd ${TRAVIS_BUILD_DIR}
|
||||
- mkdir -p build && cd build
|
||||
- |
|
||||
cmake .. \
|
||||
--warn-uninitialized \
|
||||
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
|
||||
-DCMAKE_CXX_STANDARD=$CPP \
|
||||
-DSPDLOG_BUILD_EXAMPLES=ON \
|
||||
-DSPDLOG_BUILD_BENCH=OFF \
|
||||
-DSPDLOG_SANITIZE_ADDRESS=$ASAN \
|
||||
-DSPDLOG_SANITIZE_THREAD=$TSAN
|
||||
- make VERBOSE=1 -j2
|
||||
- ctest -j2 --output-on-failure
|
||||
|
||||
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
462
CMakeLists.txt
462
CMakeLists.txt
@@ -1,148 +1,370 @@
|
||||
#
|
||||
# Copyright(c) 2015 Ruslan Baratov.
|
||||
# Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
#
|
||||
# Copyright(c) 2019 spdlog authors Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Start spdlog project
|
||||
# ---------------------------------------------------------------------------------------
|
||||
include(cmake/utils.cmake)
|
||||
include(cmake/ide.cmake)
|
||||
|
||||
spdlog_extract_version()
|
||||
|
||||
project(spdlog VERSION ${SPDLOG_VERSION} LANGUAGES CXX)
|
||||
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(spdlog VERSION 1.2.0 LANGUAGES CXX)
|
||||
include(CTest)
|
||||
include(CMakeDependentOption)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# set default build to release
|
||||
#---------------------------------------------------------------------------------------
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Set default build to release
|
||||
# ---------------------------------------------------------------------------------------
|
||||
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# compiler config
|
||||
#---------------------------------------------------------------------------------------
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Compiler config
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# c++ standard >=17 is required
|
||||
if (NOT DEFINED CMAKE_CXX_STANDARD)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
elseif (CMAKE_CXX_STANDARD LESS 17)
|
||||
message(FATAL_ERROR "Minimum supported CMAKE_CXX_STANDARD is 17, but it is set to ${CMAKE_CXX_STANDARD}")
|
||||
endif ()
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
||||
add_compile_options("-Wall")
|
||||
add_compile_options("-Wextra")
|
||||
add_compile_options("-Wconversion")
|
||||
add_compile_options("-pedantic")
|
||||
add_compile_options("-Wfatal-errors")
|
||||
|
||||
endif()
|
||||
if (CMAKE_SYSTEM_NAME MATCHES "CYGWIN" OR CMAKE_SYSTEM_NAME MATCHES "MSYS" OR CMAKE_SYSTEM_NAME MATCHES "MINGW")
|
||||
set(CMAKE_CXX_EXTENSIONS ON)
|
||||
endif ()
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# address sanitizers check
|
||||
#---------------------------------------------------------------------------------------
|
||||
include(cmake/sanitizers.cmake)
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Set SPDLOG_MASTER_PROJECT to ON if we are building spdlog
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Check if spdlog is being used directly or via add_subdirectory, but allow overriding
|
||||
if (NOT DEFINED SPDLOG_MASTER_PROJECT)
|
||||
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
||||
set(SPDLOG_MASTER_PROJECT ON)
|
||||
else ()
|
||||
set(SPDLOG_MASTER_PROJECT OFF)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# spdlog target
|
||||
#---------------------------------------------------------------------------------------
|
||||
add_library(spdlog INTERFACE)
|
||||
option(SPDLOG_BUILD_ALL "Build all artifacts" OFF)
|
||||
|
||||
# build shared option
|
||||
option(SPDLOG_BUILD_SHARED "Build shared library" OFF)
|
||||
|
||||
# example options
|
||||
option(SPDLOG_BUILD_EXAMPLE "Build example" ${SPDLOG_MASTER_PROJECT})
|
||||
|
||||
# testing options
|
||||
option(SPDLOG_BUILD_TESTS "Build tests" OFF)
|
||||
|
||||
# bench options
|
||||
option(SPDLOG_BUILD_BENCH "Build benchmarks (Requires https://github.com/google/benchmark.git to be installed)" OFF)
|
||||
|
||||
# sanitizer options
|
||||
option(SPDLOG_SANITIZE_ADDRESS "Enable address sanitizer in tests" OFF)
|
||||
|
||||
# warning options
|
||||
option(SPDLOG_BUILD_WARNINGS "Enable compiler warnings" OFF)
|
||||
|
||||
# install options
|
||||
option(SPDLOG_SYSTEM_INCLUDES "Include as system headers (skip for clang-tidy)." OFF)
|
||||
option(SPDLOG_INSTALL "Generate the install target" ${SPDLOG_MASTER_PROJECT})
|
||||
option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of of fetching from gitub." OFF)
|
||||
|
||||
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||
option(SPDLOG_CLOCK_COARSE "Use CLOCK_REALTIME_COARSE instead of the regular clock," OFF)
|
||||
else ()
|
||||
set(SPDLOG_CLOCK_COARSE OFF CACHE BOOL "non supported option" FORCE)
|
||||
endif ()
|
||||
|
||||
option(SPDLOG_PREVENT_CHILD_FD "Prevent from child processes to inherit log file descriptors" OFF)
|
||||
option(SPDLOG_NO_THREAD_ID "prevent spdlog from querying the thread id on each log call if thread id is not needed" OFF)
|
||||
option(SPDLOG_DISABLE_GLOBAL_LOGGER "Disable global logger creation" OFF)
|
||||
option(SPDLOG_NO_TLS "Disable thread local storage" OFF)
|
||||
|
||||
# clang-tidy
|
||||
option(SPDLOG_TIDY "run clang-tidy" OFF)
|
||||
|
||||
if (SPDLOG_TIDY)
|
||||
set(CMAKE_CXX_CLANG_TIDY "clang-tidy")
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
message(STATUS "Enabled clang-tidy")
|
||||
endif ()
|
||||
|
||||
if (SPDLOG_BUILD_SHARED)
|
||||
set(BUILD_SHARED_LIBS ON)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
# place dlls and libs and executables in the same directory
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
||||
set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/$<CONFIG>)
|
||||
|
||||
# make sure __cplusplus is defined
|
||||
add_compile_options(/Zc:__cplusplus)
|
||||
# enable parallel build for the solution
|
||||
add_compile_options(/MP)
|
||||
endif ()
|
||||
|
||||
message(STATUS "spdlog version: ${SPDLOG_VERSION}")
|
||||
message(STATUS "spdlog build type: " ${CMAKE_BUILD_TYPE})
|
||||
message(STATUS "spdlog build shared: " ${BUILD_SHARED_LIBS})
|
||||
message(STATUS "spdlog fmt external: " ${SPDLOG_FMT_EXTERNAL})
|
||||
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Find {fmt} library
|
||||
# ---------------------------------------------------------------------------------------
|
||||
if (SPDLOG_FMT_EXTERNAL)
|
||||
find_package(fmt REQUIRED)
|
||||
message(STATUS "Using external fmt lib version: ${fmt_VERSION}")
|
||||
else ()
|
||||
include(cmake/fmtlib.cmake)
|
||||
endif ()
|
||||
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Threads library is required
|
||||
# ---------------------------------------------------------------------------------------
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Library sources
|
||||
# ---------------------------------------------------------------------------------------
|
||||
set(SPDLOG_HEADERS
|
||||
"include/spdlog/common.h"
|
||||
"include/spdlog/formatter.h"
|
||||
"include/spdlog/fwd.h"
|
||||
"include/spdlog/logger.h"
|
||||
"include/spdlog/pattern_formatter.h"
|
||||
"include/spdlog/source_loc.h"
|
||||
"include/spdlog/spdlog.h"
|
||||
"include/spdlog/stopwatch.h"
|
||||
"include/spdlog/version.h"
|
||||
"include/spdlog/details/circular_q.h"
|
||||
"include/spdlog/details/file_helper.h"
|
||||
"include/spdlog/details/fmt_helper.h"
|
||||
"include/spdlog/details/log_msg.h"
|
||||
"include/spdlog/details/async_log_msg.h"
|
||||
"include/spdlog/details/mpmc_blocking_q.h"
|
||||
"include/spdlog/details/null_mutex.h"
|
||||
"include/spdlog/details/os.h"
|
||||
"include/spdlog/details/err_helper.h"
|
||||
"include/spdlog/bin_to_hex.h"
|
||||
"include/spdlog/sinks/android_sink.h"
|
||||
"include/spdlog/sinks/base_sink.h"
|
||||
"include/spdlog/sinks/basic_file_sink.h"
|
||||
"include/spdlog/sinks/callback_sink.h"
|
||||
"include/spdlog/sinks/daily_file_sink.h"
|
||||
"include/spdlog/sinks/dist_sink.h"
|
||||
"include/spdlog/sinks/dup_filter_sink.h"
|
||||
"include/spdlog/sinks/hourly_file_sink.h"
|
||||
"include/spdlog/sinks/kafka_sink.h"
|
||||
"include/spdlog/sinks/mongo_sink.h"
|
||||
"include/spdlog/sinks/msvc_sink.h"
|
||||
"include/spdlog/sinks/null_sink.h"
|
||||
"include/spdlog/sinks/ostream_sink.h"
|
||||
"include/spdlog/sinks/qt_sinks.h"
|
||||
"include/spdlog/sinks/ringbuffer_sink.h"
|
||||
"include/spdlog/sinks/rotating_file_sink.h"
|
||||
"include/spdlog/sinks/sink.h"
|
||||
"include/spdlog/sinks/stdout_color_sinks.h"
|
||||
"include/spdlog/sinks/stdout_sinks.h"
|
||||
"include/spdlog/sinks/syslog_sink.h"
|
||||
"include/spdlog/sinks/systemd_sink.h"
|
||||
"include/spdlog/sinks/tcp_sink.h"
|
||||
"include/spdlog/sinks/udp_sink.h"
|
||||
"include/spdlog/sinks/async_sink.h")
|
||||
|
||||
set(SPDLOG_SRCS
|
||||
"src/common.cpp"
|
||||
"src/logger.cpp"
|
||||
"src/pattern_formatter.cpp"
|
||||
"src/spdlog.cpp"
|
||||
"src/details/file_helper.cpp"
|
||||
"src/details/os_filesystem.cpp"
|
||||
"src/details/log_msg.cpp"
|
||||
"src/details/async_log_msg.cpp"
|
||||
"src/details/err_helper.cpp"
|
||||
"src/sinks/base_sink.cpp"
|
||||
"src/sinks/basic_file_sink.cpp"
|
||||
"src/sinks/rotating_file_sink.cpp"
|
||||
"src/sinks/stdout_sinks.cpp"
|
||||
"src/sinks/async_sink.cpp")
|
||||
|
||||
if (WIN32)
|
||||
list(APPEND SPDLOG_SRCS
|
||||
"src/details/os_windows.cpp"
|
||||
"src/sinks/wincolor_sink.cpp")
|
||||
list(APPEND SPDLOG_HEADERS
|
||||
"include/spdlog/sinks/wincolor_sink.h"
|
||||
"include/spdlog/details/tcp_client_windows.h"
|
||||
"include/spdlog/details/udp_client_windows.h"
|
||||
"include/spdlog/details/windows_include.h"
|
||||
"include/spdlog/sinks/win_eventlog_sink.h")
|
||||
else ()
|
||||
list(APPEND SPDLOG_SRCS
|
||||
"src/details/os_unix.cpp"
|
||||
"src/sinks/ansicolor_sink.cpp")
|
||||
list(APPEND SPDLOG_HEADERS
|
||||
"include/spdlog/details/tcp_client_unix.h"
|
||||
"include/spdlog/details/udp_client_unix.h"
|
||||
"include/spdlog/sinks/ansicolor_sink.h")
|
||||
endif ()
|
||||
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Check if fwrite_unlocked/_fwrite_nolock is available
|
||||
# ---------------------------------------------------------------------------------------
|
||||
include(CheckSymbolExists)
|
||||
if (WIN32)
|
||||
check_symbol_exists(_fwrite_nolock "stdio.h" HAVE_FWRITE_UNLOCKED)
|
||||
else ()
|
||||
check_symbol_exists(fwrite_unlocked "stdio.h" HAVE_FWRITE_UNLOCKED)
|
||||
endif ()
|
||||
if (HAVE_FWRITE_UNLOCKED)
|
||||
set(SPDLOG_FWRITE_UNLOCKED 1)
|
||||
endif ()
|
||||
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# spdlog library
|
||||
# ---------------------------------------------------------------------------------------
|
||||
if (BUILD_SHARED_LIBS)
|
||||
if (WIN32)
|
||||
set(VERSION_RC ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY)
|
||||
endif ()
|
||||
add_library(spdlog SHARED ${VERSION_RC})
|
||||
target_compile_definitions(spdlog PUBLIC SPDLOG_SHARED_LIB)
|
||||
if (MSVC)
|
||||
# disable dlls related warnings on msvc
|
||||
target_compile_options(spdlog PUBLIC $<$<AND:$<CXX_COMPILER_ID:MSVC>,$<NOT:$<COMPILE_LANGUAGE:CUDA>>>:/wd4251
|
||||
/wd4275>)
|
||||
endif ()
|
||||
else ()
|
||||
add_library(spdlog STATIC)
|
||||
endif ()
|
||||
add_library(spdlog::spdlog ALIAS spdlog)
|
||||
target_sources(spdlog PRIVATE ${SPDLOG_SRCS})
|
||||
target_sources(
|
||||
spdlog
|
||||
PUBLIC FILE_SET pub_headers
|
||||
TYPE HEADERS
|
||||
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
FILES ${SPDLOG_HEADERS})
|
||||
|
||||
# Check if spdlog is being used directly or via add_subdirectory
|
||||
set(SPDLOG_MASTER_PROJECT OFF)
|
||||
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
||||
set(SPDLOG_MASTER_PROJECT ON)
|
||||
endif()
|
||||
set(SPDLOG_INCLUDES_LEVEL "")
|
||||
if (SPDLOG_SYSTEM_INCLUDES)
|
||||
set(SPDLOG_INCLUDES_LEVEL "SYSTEM")
|
||||
endif ()
|
||||
|
||||
option(SPDLOG_BUILD_EXAMPLES "Build examples" ${SPDLOG_MASTER_PROJECT})
|
||||
option(SPDLOG_BUILD_BENCH "Build benchmarks" ${SPDLOG_MASTER_PROJECT})
|
||||
target_include_directories(spdlog ${SPDLOG_INCLUDES_LEVEL} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
|
||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||
|
||||
cmake_dependent_option(SPDLOG_BUILD_TESTING
|
||||
"Build spdlog tests" ${SPDLOG_MASTER_PROJECT}
|
||||
"BUILD_TESTING" OFF
|
||||
)
|
||||
target_link_libraries(spdlog PUBLIC Threads::Threads)
|
||||
target_link_libraries(spdlog PUBLIC fmt::fmt)
|
||||
spdlog_enable_warnings(spdlog)
|
||||
set_target_properties(spdlog PROPERTIES VERSION ${SPDLOG_VERSION} SOVERSION
|
||||
${SPDLOG_VERSION_MAJOR}.${SPDLOG_VERSION_MINOR})
|
||||
|
||||
target_include_directories(
|
||||
spdlog
|
||||
INTERFACE
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
|
||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
|
||||
)
|
||||
set(SPDLOG_NAME spdlog-${SPDLOG_VERSION_MAJOR})
|
||||
set_target_properties(spdlog PROPERTIES DEBUG_POSTFIX "-${SPDLOG_VERSION_MAJOR}.${SPDLOG_VERSION_MINOR}d")
|
||||
|
||||
set(HEADER_BASE "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# set source groups for visual studio
|
||||
# ---------------------------------------------------------------------------------------
|
||||
if (CMAKE_GENERATOR MATCHES "Visual Studio")
|
||||
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/include PREFIX include FILES ${SPDLOG_HEADERS})
|
||||
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src PREFIX sources FILES ${SPDLOG_SRCS})
|
||||
source_group(sources FILES ${VERSION_RC})
|
||||
endif ()
|
||||
|
||||
if(SPDLOG_BUILD_EXAMPLES)
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Add required libraries for Android CMake build
|
||||
# ---------------------------------------------------------------------------------------
|
||||
if (ANDROID)
|
||||
target_link_libraries(spdlog PUBLIC log)
|
||||
endif ()
|
||||
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# spdlog private defines according to the options
|
||||
# ---------------------------------------------------------------------------------------
|
||||
foreach (SPDLOG_OPTION
|
||||
SPDLOG_CLOCK_COARSE
|
||||
SPDLOG_PREVENT_CHILD_FD
|
||||
SPDLOG_NO_THREAD_ID
|
||||
SPDLOG_DISABLE_GLOBAL_LOGGER
|
||||
SPDLOG_NO_TLS
|
||||
SPDLOG_FWRITE_UNLOCKED)
|
||||
if (${SPDLOG_OPTION})
|
||||
target_compile_definitions(spdlog PRIVATE ${SPDLOG_OPTION})
|
||||
endif ()
|
||||
endforeach ()
|
||||
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Build binaries
|
||||
# ---------------------------------------------------------------------------------------
|
||||
if (SPDLOG_BUILD_EXAMPLE OR SPDLOG_BUILD_ALL)
|
||||
message(STATUS "Generating example(s)")
|
||||
add_subdirectory(example)
|
||||
endif()
|
||||
spdlog_enable_warnings(example)
|
||||
endif ()
|
||||
|
||||
if(SPDLOG_BUILD_TESTING)
|
||||
if (SPDLOG_BUILD_TESTS OR SPDLOG_BUILD_ALL)
|
||||
message(STATUS "Generating tests")
|
||||
enable_testing()
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
if(SPDLOG_BUILD_BENCH)
|
||||
if (SPDLOG_BUILD_BENCH OR SPDLOG_BUILD_ALL)
|
||||
message(STATUS "Generating benchmarks")
|
||||
add_subdirectory(bench)
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
# Install/export targets and files
|
||||
#---------------------------------------------------------------------------------------
|
||||
# set files and directories
|
||||
set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
|
||||
set(include_install_dir "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
set(pkgconfig_install_dir "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
||||
set(version_config "${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
|
||||
set(project_config "${PROJECT_NAME}Config.cmake")
|
||||
set(pkg_config "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc")
|
||||
set(targets_export_name "${PROJECT_NAME}Targets")
|
||||
set(namespace "${PROJECT_NAME}::")
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Install
|
||||
# ---------------------------------------------------------------------------------------
|
||||
if (SPDLOG_INSTALL)
|
||||
message(STATUS "Generating install")
|
||||
set(project_config_in "${CMAKE_CURRENT_LIST_DIR}/cmake/spdlogConfig.cmake.in")
|
||||
set(project_config_out "${CMAKE_CURRENT_BINARY_DIR}/spdlogConfig.cmake")
|
||||
set(config_targets_file "spdlogConfigTargets.cmake")
|
||||
set(version_config_file "${CMAKE_CURRENT_BINARY_DIR}/spdlogConfigVersion.cmake")
|
||||
set(export_dest_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${SPDLOG_NAME}")
|
||||
|
||||
# generate package version file
|
||||
include(CMakePackageConfigHelpers)
|
||||
write_basic_package_version_file(
|
||||
"${version_config}" COMPATIBILITY SameMajorVersion
|
||||
)
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Include files
|
||||
# ---------------------------------------------------------------------------------------
|
||||
set(installed_include_dir "${CMAKE_INSTALL_INCLUDEDIR}/${SPDLOG_NAME}")
|
||||
install(
|
||||
TARGETS spdlog
|
||||
EXPORT spdlogTargets
|
||||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/${SPDLOG_NAME}"
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/${SPDLOG_NAME}"
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/${SPDLOG_NAME}"
|
||||
FILE_SET pub_headers
|
||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${SPDLOG_NAME}")
|
||||
message(STATUS "Installing spdlog in ${CMAKE_INSTALL_LIBDIR}/${SPDLOG_NAME}")
|
||||
|
||||
# configure pkg config file
|
||||
configure_file("cmake/spdlog.pc.in" "${pkg_config}" @ONLY)
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Install CMake config files
|
||||
# ---------------------------------------------------------------------------------------
|
||||
install(EXPORT spdlogTargets DESTINATION ${export_dest_dir} NAMESPACE spdlog:: FILE ${config_targets_file})
|
||||
|
||||
# install targets
|
||||
install(
|
||||
TARGETS spdlog
|
||||
EXPORT "${targets_export_name}"
|
||||
)
|
||||
include(CMakePackageConfigHelpers)
|
||||
configure_package_config_file("${project_config_in}" "${project_config_out}" INSTALL_DESTINATION ${export_dest_dir})
|
||||
|
||||
# install headers
|
||||
install(
|
||||
DIRECTORY "${HEADER_BASE}/${PROJECT_NAME}"
|
||||
DESTINATION "${include_install_dir}"
|
||||
)
|
||||
write_basic_package_version_file("${version_config_file}" COMPATIBILITY SameMajorVersion)
|
||||
install(FILES "${project_config_out}" "${version_config_file}" DESTINATION "${export_dest_dir}")
|
||||
|
||||
# install project version file
|
||||
install(
|
||||
FILES "${version_config}"
|
||||
DESTINATION "${config_install_dir}"
|
||||
)
|
||||
|
||||
# install pkg config file
|
||||
install(
|
||||
FILES "${pkg_config}"
|
||||
DESTINATION "${pkgconfig_install_dir}"
|
||||
)
|
||||
|
||||
# install project config file
|
||||
install(
|
||||
EXPORT "${targets_export_name}"
|
||||
NAMESPACE "${namespace}"
|
||||
DESTINATION "${config_install_dir}"
|
||||
FILE ${project_config}
|
||||
)
|
||||
|
||||
# export build directory config file
|
||||
export(
|
||||
EXPORT ${targets_export_name}
|
||||
NAMESPACE "${namespace}"
|
||||
FILE ${project_config}
|
||||
)
|
||||
|
||||
# register project in CMake user registry
|
||||
export(PACKAGE ${PROJECT_NAME})
|
||||
|
||||
file(GLOB_RECURSE spdlog_include_SRCS "${HEADER_BASE}/*.h")
|
||||
add_custom_target(spdlog_headers_for_ide SOURCES ${spdlog_include_SRCS})
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Support creation of installable packages
|
||||
# ---------------------------------------------------------------------------------------
|
||||
include(cmake/spdlogCPack.cmake)
|
||||
endif ()
|
||||
|
||||
9
INSTALL
9
INSTALL
@@ -1,13 +1,12 @@
|
||||
spdlog is header only library.
|
||||
Just copy the files to your build tree and use a C++11 compiler
|
||||
CMake:
|
||||
add_executable(example example.cpp)
|
||||
target_link_libraries(example spdlog::spdlog)
|
||||
|
||||
Tested on:
|
||||
gcc 4.8.1 and above
|
||||
clang 3.5
|
||||
Visual Studio 2013
|
||||
|
||||
gcc 4.8 flags: --std==c++11 -pthread -O3 -flto -Wl,--no-as-needed
|
||||
gcc 4.9 flags: --std=c++11 -pthread -O3 -flto
|
||||
|
||||
|
||||
see the makefile in the example folder
|
||||
|
||||
|
||||
4
LICENSE
4
LICENSE
@@ -20,3 +20,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
-- NOTE: Third party dependency used by this software --
|
||||
This software depends on the fmt lib (MIT License),
|
||||
and users must comply to its license: https://raw.githubusercontent.com/fmtlib/fmt/master/LICENSE
|
||||
|
||||
|
||||
442
README.md
442
README.md
@@ -1,120 +1,106 @@
|
||||
# spdlog
|
||||
|
||||
Very fast, header only, C++ logging library. [](https://travis-ci.org/gabime/spdlog) [](https://ci.appveyor.com/project/gabime/spdlog)
|
||||
|
||||
[](https://github.com/gabime/spdlog/actions/workflows/linux.yml)
|
||||
[](https://github.com/gabime/spdlog/actions/workflows/windows.yml)
|
||||
[](https://github.com/gabime/spdlog/actions/workflows/macos.yml)
|
||||
[](https://github.com/gabime/spdlog/releases/latest)
|
||||
|
||||
Fast C++ logging library
|
||||
|
||||
## Install
|
||||
#### Just copy the headers:
|
||||
```console
|
||||
$ git clone https://github.com/gabime/spdlog.git
|
||||
$ cd spdlog && mkdir build && cd build
|
||||
$ cmake .. && cmake --build .
|
||||
```
|
||||
|
||||
* Copy the source [folder](https://github.com/gabime/spdlog/tree/v1.x/include/spdlog) to your build tree and use a C++11 compiler.
|
||||
|
||||
#### Or use your favorite package manager:
|
||||
|
||||
* Ubuntu: `apt-get install libspdlog-dev`
|
||||
* Homebrew: `brew install spdlog`
|
||||
* FreeBSD: `cd /usr/ports/devel/spdlog/ && make install clean`
|
||||
* Fedora: `yum install spdlog`
|
||||
* Gentoo: `emerge dev-libs/spdlog`
|
||||
* Arch Linux: `yaourt -S spdlog-git`
|
||||
* vcpkg: `vcpkg install spdlog`
|
||||
|
||||
see example [CMakeLists.txt](https://github.com/gabime/spdlog/blob/v2.x/example/CMakeLists.txt) on how to use.
|
||||
|
||||
## Platforms
|
||||
* Linux, FreeBSD, OpenBSD, Solaris, AIX
|
||||
* Windows (msvc 2013+, cygwin)
|
||||
* macOS (clang 3.5+)
|
||||
* Android
|
||||
* Linux, FreeBSD, OpenBSD, Solaris, AIX
|
||||
* Windows (msvc, cygwin)
|
||||
* macOS
|
||||
* Android
|
||||
|
||||
## Package managers:
|
||||
* Debian: `sudo apt install libspdlog-dev`
|
||||
* Homebrew: `brew install spdlog`
|
||||
* MacPorts: `sudo port install spdlog`
|
||||
* FreeBSD: `pkg install spdlog`
|
||||
* Fedora: `dnf install spdlog`
|
||||
* Gentoo: `emerge dev-libs/spdlog`
|
||||
* Arch Linux: `pacman -S spdlog`
|
||||
* openSUSE: `sudo zypper in spdlog-devel`
|
||||
* vcpkg: `vcpkg install spdlog`
|
||||
* conan: `conan install --requires=spdlog/[*]`
|
||||
* conda: `conda install -c conda-forge spdlog`
|
||||
* build2: ```depends: spdlog ^1.8.2```
|
||||
|
||||
|
||||
## Features
|
||||
* Very fast (see [benchmarks](#benchmarks) below).
|
||||
* Headers only, just copy and use.
|
||||
* Feature rich formatting, using the excellent [fmt](https://github.com/fmtlib/fmt) library.
|
||||
* Fast asynchronous mode (optional)
|
||||
* Headers only or compiled
|
||||
* Feature-rich formatting, using the excellent [fmt](https://github.com/fmtlib/fmt) library.
|
||||
* Asynchronous mode (optional)
|
||||
* [Custom](https://github.com/gabime/spdlog/wiki/3.-Custom-formatting) formatting.
|
||||
* Multi/Single threaded loggers.
|
||||
* Various log targets:
|
||||
* Rotating log files.
|
||||
* Daily log files.
|
||||
* Console logging (colors supported).
|
||||
* syslog.
|
||||
* Windows debugger (```OutputDebugString(..)```)
|
||||
* Easily extendable with custom log targets (just implement a single function in the [sink](include/spdlog/sinks/sink.h) interface).
|
||||
* Severity based filtering - threshold levels can be modified in runtime as well as in compile time.
|
||||
* Binary data logging.
|
||||
|
||||
|
||||
## Benchmarks
|
||||
|
||||
Below are some [benchmarks](https://github.com/gabime/spdlog/blob/v1.x/bench/bench.cpp) done in Ubuntu 64 bit, Intel i7-4770 CPU @ 3.40GHz
|
||||
|
||||
#### Synchronous mode
|
||||
```
|
||||
*******************************************************************************
|
||||
Single thread, 1,000,000 iterations
|
||||
*******************************************************************************
|
||||
basic_st... Elapsed: 0.181652 5,505,042/sec
|
||||
rotating_st... Elapsed: 0.181781 5,501,117/sec
|
||||
daily_st... Elapsed: 0.187595 5,330,630/sec
|
||||
null_st... Elapsed: 0.0504704 19,813,602/sec
|
||||
*******************************************************************************
|
||||
10 threads sharing same logger, 1,000,000 iterations
|
||||
*******************************************************************************
|
||||
basic_mt... Elapsed: 0.616035 1,623,284/sec
|
||||
rotating_mt... Elapsed: 0.620344 1,612,008/sec
|
||||
daily_mt... Elapsed: 0.648353 1,542,369/sec
|
||||
null_mt... Elapsed: 0.151972 6,580,166/sec
|
||||
```
|
||||
#### Asynchronous mode
|
||||
```
|
||||
*******************************************************************************
|
||||
10 threads sharing same logger, 1,000,000 iterations
|
||||
*******************************************************************************
|
||||
async... Elapsed: 0.350066 2,856,606/sec
|
||||
async... Elapsed: 0.314865 3,175,960/sec
|
||||
async... Elapsed: 0.349851 2,858,358/sec
|
||||
```
|
||||
* Rotating log files.
|
||||
* Daily log files.
|
||||
* Console logging (colors supported).
|
||||
* syslog.
|
||||
* Windows event log.
|
||||
* Windows debugger (```OutputDebugString(..)```).
|
||||
* Log to Qt widgets ([example](#log-to-qt-with-nice-colors)).
|
||||
* Easily [extendable](https://github.com/gabime/spdlog/wiki/4.-Sinks#implementing-your-own-sink) with custom log targets.
|
||||
* Log filtering - log levels can be modified at runtime as well as compile time.
|
||||
* Support for loading log levels from argv or environment var.
|
||||
|
||||
## Usage samples
|
||||
|
||||
#### Basic usage
|
||||
```c++
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
spdlog::info("Welcome to spdlog!");
|
||||
spdlog::error("Some error message with arg: {}", 1);
|
||||
|
||||
spdlog::warn("Easy padding in numbers like {:08d}", 12);
|
||||
spdlog::critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
|
||||
spdlog::info("Support for floats {:03.2f}", 1.23456);
|
||||
spdlog::info("Positional args are {1} {0}..", "too", "supported");
|
||||
spdlog::info("{:<30}", "left aligned");
|
||||
|
||||
spdlog::set_level(spdlog::level::debug); // Set global log level to debug
|
||||
spdlog::debug("This message should be displayed..");
|
||||
|
||||
// change log pattern
|
||||
spdlog::set_pattern("[%H:%M:%S %z] [%n] [%^---%L---%$] [thread %t] %v");
|
||||
|
||||
// Compile time log levels
|
||||
// define SPDLOG_ACTIVE_LEVEL to desired level
|
||||
SPDLOG_TRACE("Some trace message with param {}", 42);
|
||||
SPDLOG_DEBUG("Some debug message");
|
||||
}
|
||||
|
||||
```
|
||||
---
|
||||
#### Create stdout/stderr logger object
|
||||
```c++
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||
void stdout_example()
|
||||
{
|
||||
// create color multi threaded logger
|
||||
auto console = spdlog::stdout_color_mt("console");
|
||||
console->info("Welcome to spdlog!");
|
||||
console->error("Some error message with arg: {}", 1);
|
||||
|
||||
auto err_logger = spdlog::stderr_color_mt("stderr");
|
||||
err_logger->error("Some error message");
|
||||
|
||||
// Formatting examples
|
||||
console->warn("Easy padding in numbers like {:08d}", 12);
|
||||
console->critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
|
||||
console->info("Support for floats {:03.2f}", 1.23456);
|
||||
console->info("Positional args are {1} {0}..", "too", "supported");
|
||||
console->info("{:<30}", "left aligned");
|
||||
|
||||
// create a color multi-threaded logger
|
||||
auto console = spdlog::stdout_color_mt("console");
|
||||
auto err_logger = spdlog::stderr_color_mt("stderr");
|
||||
spdlog::get("console")->info("loggers can be retrieved from a global registry using the spdlog::get(logger_name)");
|
||||
|
||||
// Runtime log levels
|
||||
spdlog::set_level(spdlog::level::info); // Set global log level to info
|
||||
console->debug("This message should not be displayed!");
|
||||
console->set_level(spdlog::level::trace); // Set specific logger's log level
|
||||
console->debug("This message should be displayed..");
|
||||
|
||||
// Customize msg format for all loggers
|
||||
spdlog::set_pattern("[%H:%M:%S %z] [%n] [%^---%L---%$] [thread %t] %v");
|
||||
console->info("This an info message with custom format");
|
||||
|
||||
// Compile time log levels
|
||||
// define SPDLOG_DEBUG_ON or SPDLOG_TRACE_ON
|
||||
SPDLOG_TRACE(console, "Enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}", 1, 3.23);
|
||||
SPDLOG_DEBUG(console, "Enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}", 1, 3.23);
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
#### Basic file logger
|
||||
```c++
|
||||
@@ -123,7 +109,7 @@ void basic_logfile_example()
|
||||
{
|
||||
try
|
||||
{
|
||||
auto my_logger = spdlog::basic_logger_mt("basic_logger", "logs/basic-log.txt");
|
||||
auto logger = spdlog::basic_logger_mt("basic_logger", "logs/basic-log.txt");
|
||||
}
|
||||
catch (const spdlog::spdlog_ex &ex)
|
||||
{
|
||||
@@ -137,8 +123,10 @@ void basic_logfile_example()
|
||||
#include "spdlog/sinks/rotating_file_sink.h"
|
||||
void rotating_example()
|
||||
{
|
||||
// Create a file rotating logger with 5mb size max and 3 rotated files
|
||||
auto rotating_logger = spdlog::rotating_logger_mt("some_logger_name", "logs/rotating.txt", 1048576 * 5, 3);
|
||||
// Create a file rotating logger with 5 MB size max and 3 rotated files
|
||||
auto max_size = 1048576 * 5;
|
||||
auto max_files = 3;
|
||||
auto logger = spdlog::rotating_logger_mt("some_logger_name", "logs/rotating.txt", max_size, max_files);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -149,44 +137,47 @@ void rotating_example()
|
||||
#include "spdlog/sinks/daily_file_sink.h"
|
||||
void daily_example()
|
||||
{
|
||||
// Create a daily logger - a new file is created every day on 2:30am
|
||||
auto daily_logger = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30);
|
||||
// Create a daily logger - a new file is created every day at 2:30 am
|
||||
auto logger = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
#### Cloning loggers
|
||||
```c++
|
||||
// clone a logger and give it new name.
|
||||
// Useful for creating subsystem loggers from some "root" logger
|
||||
void clone_example()
|
||||
{
|
||||
auto network_logger = spdlog::get("root")->clone("network");
|
||||
network_logger->info("Logging network stuff..");
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
#### Periodic flush
|
||||
```c++
|
||||
// periodically flush all *registered* loggers every 3 seconds:
|
||||
// warning: only use if all your loggers are thread safe!
|
||||
// warning: only use if all your loggers are thread-safe ("_mt" loggers)
|
||||
spdlog::flush_every(std::chrono::seconds(3));
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
#### Binary logging
|
||||
#### Stopwatch
|
||||
```c++
|
||||
// Stopwatch support for spdlog
|
||||
#include "spdlog/stopwatch.h"
|
||||
void stopwatch_example()
|
||||
{
|
||||
spdlog::stopwatch sw;
|
||||
spdlog::debug("Elapsed {}", sw);
|
||||
spdlog::debug("Elapsed {:.3}", sw);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
#### Log binary data in hex
|
||||
```c++
|
||||
// log binary data as hex.
|
||||
// many types of std::container<char> types can be used.
|
||||
// ranges are supported too.
|
||||
// format flags:
|
||||
// {:X} - print in uppercase.
|
||||
// {:s} - don't separate each byte with space.
|
||||
// {:p} - don't print the position on each line start.
|
||||
// {:n} - don't split the output to lines.
|
||||
// {:n} - don't split the output into lines.
|
||||
// {:a} - show ASCII if :n is not set.
|
||||
|
||||
#include "spdlog/fmt/bin_to_hex.h"
|
||||
|
||||
@@ -205,11 +196,11 @@ void binary_example()
|
||||
```
|
||||
|
||||
---
|
||||
#### Logger with multi sinks - each with different format and log level
|
||||
#### Logger with multi sinks - each with a different format and log level
|
||||
```c++
|
||||
|
||||
// create logger with 2 targets with different log levels and formats.
|
||||
// the console will show only warnings or errors, while the file will log all.
|
||||
// create a logger with 2 targets, with different log levels and formats.
|
||||
// The console will show only warnings or errors, while the file will log all.
|
||||
void multi_sink_example()
|
||||
{
|
||||
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
||||
@@ -226,6 +217,27 @@ void multi_sink_example()
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
#### User-defined callbacks about log events
|
||||
```c++
|
||||
|
||||
// create a logger with a lambda function callback, the callback will be called
|
||||
// each time something is logged to the logger
|
||||
void callback_example()
|
||||
{
|
||||
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg &msg) {
|
||||
// for example you can be notified by sending an email to yourself
|
||||
});
|
||||
callback_sink->set_level(spdlog::level::err);
|
||||
|
||||
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
||||
spdlog::logger logger("custom_callback_logger", {console_sink, callback_sink});
|
||||
|
||||
logger.info("some info log");
|
||||
logger.error("critical issue"); // will notify you
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
#### Asynchronous logging
|
||||
```c++
|
||||
@@ -233,53 +245,60 @@ void multi_sink_example()
|
||||
#include "spdlog/sinks/basic_file_sink.h"
|
||||
void async_example()
|
||||
{
|
||||
// default thread pool settings can be modified *before* creating the async logger:
|
||||
// spdlog::init_thread_pool(8192, 1); // queue with 8k items and 1 backing thread.
|
||||
auto async_file = spdlog::basic_logger_mt<spdlog::async_factory>("async_file_logger", "logs/async_log.txt");
|
||||
// alternatively:
|
||||
// auto async_file = spdlog::create_async<spdlog::sinks::basic_file_sink_mt>("async_file_logger", "logs/async_log.txt");
|
||||
// TODO
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
#### Asynchronous logger with multi sinks
|
||||
#### User-defined types
|
||||
```c++
|
||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||
#include "spdlog/sinks/rotating_file_sink.h"
|
||||
|
||||
void multi_sink_example2()
|
||||
template<>
|
||||
struct fmt::formatter<my_type> : fmt::formatter<std::string>
|
||||
{
|
||||
spdlog::init_thread_pool(8192, 1);
|
||||
auto stdout_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt >();
|
||||
auto rotating_sink = std::make_shared<spdlog::sinks::rotating_file_sink_mt>("mylog.txt", 1024*1024*10, 3);
|
||||
std::vector<spdlog::sink_ptr> sinks {stdout_sink, rotating_sink};
|
||||
auto logger = std::make_shared<spdlog::async_logger>("loggername", sinks.begin(), sinks.end(), spdlog::thread_pool(), spdlog::async_overflow_policy::block);
|
||||
spdlog::register_logger(logger);
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
#### User defined types
|
||||
```c++
|
||||
// user defined types logging by implementing operator<<
|
||||
#include "spdlog/fmt/ostr.h" // must be included
|
||||
struct my_type
|
||||
{
|
||||
int i;
|
||||
template<typename OStream>
|
||||
friend OStream &operator<<(OStream &os, const my_type &c)
|
||||
auto format(my_type my, format_context &ctx) const -> decltype(ctx.out())
|
||||
{
|
||||
return os << "[my_type i=" << c.i << "]";
|
||||
return format_to(ctx.out(), "[my_type i={}]", my.i);
|
||||
}
|
||||
};
|
||||
|
||||
void user_defined_example()
|
||||
{
|
||||
spdlog::get("console")->info("user defined type: {}", my_type{14});
|
||||
spdlog::info("user defined type: {}", my_type(14));
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
#### User-defined flags in the log pattern
|
||||
```c++
|
||||
// Log patterns can contain custom flags.
|
||||
// the following example will add new flag '%*' - which will be bound to a <my_formatter_flag> instance.
|
||||
#include "spdlog/pattern_formatter.h"
|
||||
class my_formatter_flag : public spdlog::custom_flag_formatter
|
||||
{
|
||||
public:
|
||||
void format(const spdlog::details::log_msg &, const std::tm &, spdlog::memory_buf_t &dest) override
|
||||
{
|
||||
std::string some_txt = "custom-flag";
|
||||
dest.append(some_txt.data(), some_txt.data() + some_txt.size());
|
||||
}
|
||||
|
||||
std::unique_ptr<custom_flag_formatter> clone() const override
|
||||
{
|
||||
return std::make_unique<my_formatter_flag>();
|
||||
}
|
||||
};
|
||||
|
||||
void custom_flags_example()
|
||||
{
|
||||
auto formatter = std::make_unique<spdlog::pattern_formatter>();
|
||||
formatter->add_flag<my_formatter_flag>('*').set_pattern("[%n] [%*] [%^%l%$] %v");
|
||||
spdlog::set_formatter(std::move(formatter));
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
#### Custom error handler
|
||||
```c++
|
||||
@@ -291,8 +310,9 @@ void err_handler_example()
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
#### syslog
|
||||
#### syslog
|
||||
```c++
|
||||
#include "spdlog/sinks/syslog_sink.h"
|
||||
void syslog_example()
|
||||
@@ -303,16 +323,140 @@ void syslog_example()
|
||||
}
|
||||
```
|
||||
---
|
||||
#### Android example
|
||||
#### Android example
|
||||
```c++
|
||||
#incude "spdlog/sinks/android_sink.h"
|
||||
#include "spdlog/sinks/android_sink.h"
|
||||
void android_example()
|
||||
{
|
||||
std::string tag = "spdlog-android";
|
||||
auto android_logger = spdlog::android_logger("android", tag);
|
||||
auto android_logger = spdlog::android_logger_mt("android", tag);
|
||||
android_logger->critical("Use \"adb shell logcat\" to view this message.");
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
#### Load log levels from the env variable or argv
|
||||
|
||||
```c++
|
||||
#include "spdlog/cfg/env.h"
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
spdlog::cfg::load_env_levels();
|
||||
// or from the command line:
|
||||
// ./example SPDLOG_LEVEL=info,mylogger=trace
|
||||
// #include "spdlog/cfg/argv.h" // for loading levels from argv
|
||||
// spdlog::cfg::load_argv_levels(argc, argv);
|
||||
}
|
||||
```
|
||||
So then you can:
|
||||
|
||||
```console
|
||||
$ export SPDLOG_LEVEL=info,mylogger=trace
|
||||
$ ./example
|
||||
```
|
||||
|
||||
|
||||
---
|
||||
#### Log file open/close event handlers
|
||||
```c++
|
||||
// You can get callbacks from spdlog before/after a log file has been opened or closed.
|
||||
// This is useful for cleanup procedures or for adding something to the start/end of the log file.
|
||||
void file_events_example()
|
||||
{
|
||||
// pass the spdlog::file_event_handlers to file sinks for open/close log file notifications
|
||||
spdlog::file_event_handlers handlers;
|
||||
handlers.before_open = [](spdlog::filename_t filename) { spdlog::info("Before opening {}", filename); };
|
||||
handlers.after_open = [](spdlog::filename_t filename, std::FILE *fstream) { fputs("After opening\n", fstream); };
|
||||
handlers.before_close = [](spdlog::filename_t filename, std::FILE *fstream) { fputs("Before closing\n", fstream); };
|
||||
handlers.after_close = [](spdlog::filename_t filename) { spdlog::info("After closing {}", filename); };
|
||||
auto my_logger = spdlog::basic_logger_st("some_logger", "logs/events-sample.txt", true, handlers);
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
#### Replace the Default Logger
|
||||
```c++
|
||||
void replace_global_logger_example()
|
||||
{
|
||||
auto new_logger = spdlog::basic_logger_mt("new_global_logger", "logs/new-default-log.txt", true);
|
||||
spdlog::set_global_logger(new_logger);
|
||||
spdlog::info("new logger log message");
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
#### Log to Qt with nice colors
|
||||
```c++
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "spdlog/sinks/qt_sinks.h"
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
||||
{
|
||||
setMinimumSize(640, 480);
|
||||
auto log_widget = new QTextEdit(this);
|
||||
setCentralWidget(log_widget);
|
||||
int max_lines = 500; // keep the text widget to max 500 lines. remove old lines if needed.
|
||||
auto logger = spdlog::qt_color_logger_mt("qt_logger", log_widget, max_lines);
|
||||
logger->info("Some info message");
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
## Benchmarks
|
||||
|
||||
Below are some [benchmarks](https://github.com/gabime/spdlog/blob/v2.x/bench/bench.cpp) done in Ubuntu 64 bit, Intel i7-4770 CPU @ 3.40GHz
|
||||
|
||||
#### Synchronous mode
|
||||
```
|
||||
[info] **************************************************************
|
||||
[info] Single thread, 1,000,000 iterations
|
||||
[info] **************************************************************
|
||||
[info] basic_st Elapsed: 0.17 secs 5,777,626/sec
|
||||
[info] rotating_st Elapsed: 0.18 secs 5,475,894/sec
|
||||
[info] daily_st Elapsed: 0.20 secs 5,062,659/sec
|
||||
[info] empty_logger Elapsed: 0.07 secs 14,127,300/sec
|
||||
[info] **************************************************************
|
||||
[info] C-string (400 bytes). Single thread, 1,000,000 iterations
|
||||
[info] **************************************************************
|
||||
[info] basic_st Elapsed: 0.41 secs 2,412,483/sec
|
||||
[info] rotating_st Elapsed: 0.72 secs 1,389,196/sec
|
||||
[info] daily_st Elapsed: 0.42 secs 2,393,298/sec
|
||||
[info] null_st Elapsed: 0.04 secs 27,446,957/sec
|
||||
[info] **************************************************************
|
||||
[info] 10 threads, competing over the same logger object, 1,000,000 iterations
|
||||
[info] **************************************************************
|
||||
[info] basic_mt Elapsed: 0.60 secs 1,659,613/sec
|
||||
[info] rotating_mt Elapsed: 0.62 secs 1,612,493/sec
|
||||
[info] daily_mt Elapsed: 0.61 secs 1,638,305/sec
|
||||
[info] null_mt Elapsed: 0.16 secs 6,272,758/sec
|
||||
```
|
||||
#### Asynchronous mode
|
||||
```
|
||||
[info] -------------------------------------------------
|
||||
[info] Messages : 1,000,000
|
||||
[info] Threads : 10
|
||||
[info] Queue : 8,192 slots
|
||||
[info] Queue memory : 8,192 x 272 = 2,176 KB
|
||||
[info] -------------------------------------------------
|
||||
[info]
|
||||
[info] *********************************
|
||||
[info] Queue Overflow Policy: block
|
||||
[info] *********************************
|
||||
[info] Elapsed: 1.70784 secs 585,535/sec
|
||||
[info] Elapsed: 1.69805 secs 588,910/sec
|
||||
[info] Elapsed: 1.7026 secs 587,337/sec
|
||||
[info]
|
||||
[info] *********************************
|
||||
[info] Queue Overflow Policy: overrun
|
||||
[info] *********************************
|
||||
[info] Elapsed: 0.372816 secs 2,682,285/sec
|
||||
[info] Elapsed: 0.379758 secs 2,633,255/sec
|
||||
[info] Elapsed: 0.373532 secs 2,677,147/sec
|
||||
|
||||
```
|
||||
|
||||
## Documentation
|
||||
Documentation can be found in the [wiki](https://github.com/gabime/spdlog/wiki/1.-QuickStart) pages.
|
||||
|
||||
---
|
||||
|
||||
Thanks to [JetBrains](https://www.jetbrains.com/?from=spdlog) for donating product licenses to help develop **spdlog** <a href="https://www.jetbrains.com/?from=spdlog"><img src="logos/jetbrains-variant-4.svg" width="94" align="center" /></a>
|
||||
|
||||
32
appveyor.yml
32
appveyor.yml
@@ -1,32 +0,0 @@
|
||||
version: 1.0.{build}
|
||||
image: Visual Studio 2015
|
||||
environment:
|
||||
matrix:
|
||||
- GENERATOR: '"MinGW Makefiles"'
|
||||
BUILD_TYPE: Debug
|
||||
- GENERATOR: '"MinGW Makefiles"'
|
||||
BUILD_TYPE: Release
|
||||
- GENERATOR: '"Visual Studio 14 2015"'
|
||||
BUILD_TYPE: Debug
|
||||
- GENERATOR: '"Visual Studio 14 2015"'
|
||||
BUILD_TYPE: Release
|
||||
- GENERATOR: '"Visual Studio 14 2015 Win64"'
|
||||
BUILD_TYPE: Debug
|
||||
- GENERATOR: '"Visual Studio 14 2015 Win64"'
|
||||
BUILD_TYPE: Release
|
||||
build_script:
|
||||
- cmd: >-
|
||||
set
|
||||
|
||||
mkdir build
|
||||
|
||||
cd build
|
||||
|
||||
set PATH=%PATH:C:\Program Files\Git\usr\bin;=%
|
||||
|
||||
set PATH=C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin;%PATH%
|
||||
|
||||
cmake .. -G %GENERATOR% -DCMAKE_BUILD_TYPE=%BUILD_TYPE%
|
||||
|
||||
cmake --build . --config %BUILD_TYPE%
|
||||
test: off
|
||||
@@ -1,43 +1,39 @@
|
||||
# *************************************************************************/
|
||||
# * Copyright (c) 2015 Ruslan Baratov. */
|
||||
# * */
|
||||
# * Permission is hereby granted, free of charge, to any person obtaining */
|
||||
# * a copy of this software and associated documentation files (the */
|
||||
# * "Software"), to deal in the Software without restriction, including */
|
||||
# * without limitation the rights to use, copy, modify, merge, publish, */
|
||||
# * distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
# * permit persons to whom the Software is furnished to do so, subject to */
|
||||
# * the following conditions: */
|
||||
# * */
|
||||
# * The above copyright notice and this permission notice shall be */
|
||||
# * included in all copies or substantial portions of the Software. */
|
||||
# * */
|
||||
# * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
# * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
# * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
# * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
# * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
# * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
# * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
# *************************************************************************/
|
||||
# Copyright(c) 2019 spdlog authors Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(SpdlogBench CXX)
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
project(spdlog_bench CXX)
|
||||
|
||||
if(NOT TARGET spdlog)
|
||||
# Stand-alone build
|
||||
find_package(spdlog CONFIG REQUIRED)
|
||||
# Stand-alone build
|
||||
find_package(spdlog CONFIG REQUIRED)
|
||||
endif()
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
find_package(benchmark CONFIG)
|
||||
|
||||
if(NOT benchmark_FOUND)
|
||||
message(STATUS "Using CMake Version ${CMAKE_VERSION}")
|
||||
# User can fetch googlebenchmark
|
||||
message(STATUS "Downloading GoogleBenchmark")
|
||||
include(FetchContent)
|
||||
|
||||
# disable tests
|
||||
set(BENCHMARK_ENABLE_TESTING OFF CACHE INTERNAL "")
|
||||
# Do not build and run googlebenchmark tests
|
||||
FetchContent_Declare(googlebenchmark GIT_REPOSITORY https://github.com/google/benchmark.git GIT_TAG v1.6.0)
|
||||
FetchContent_MakeAvailable(googlebenchmark)
|
||||
set_target_properties(benchmark PROPERTIES FOLDER "third-party")
|
||||
endif()
|
||||
|
||||
add_executable(bench bench.cpp)
|
||||
target_link_libraries(bench spdlog::spdlog Threads::Threads)
|
||||
spdlog_enable_warnings(bench)
|
||||
target_link_libraries(bench PRIVATE spdlog::spdlog)
|
||||
|
||||
add_executable(async_bench async_bench.cpp)
|
||||
target_link_libraries(async_bench spdlog::spdlog Threads::Threads)
|
||||
target_link_libraries(async_bench PRIVATE spdlog::spdlog)
|
||||
|
||||
add_executable(latency latency.cpp)
|
||||
target_link_libraries(latency spdlog::spdlog Threads::Threads)
|
||||
target_link_libraries(latency PRIVATE benchmark::benchmark spdlog::spdlog)
|
||||
|
||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs")
|
||||
add_executable(formatter-bench formatter-bench.cpp)
|
||||
target_link_libraries(formatter-bench PRIVATE benchmark::benchmark spdlog::spdlog)
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
CXX ?= g++
|
||||
CXXFLAGS = -march=native -Wall -Wextra -pedantic -std=c++11 -pthread -I../include -fmax-errors=1
|
||||
CXX_RELEASE_FLAGS = -Ofast -flto -Wl,--no-as-needed
|
||||
|
||||
|
||||
binaries=bench latency async_bench
|
||||
|
||||
all: $(binaries)
|
||||
|
||||
bench: bench.cpp
|
||||
$(CXX) bench.cpp -o bench $(CXXFLAGS) $(CXX_RELEASE_FLAGS)
|
||||
|
||||
|
||||
async_bench: async_bench.cpp
|
||||
$(CXX) async_bench.cpp -o async_bench $(CXXFLAGS) $(CXX_RELEASE_FLAGS)
|
||||
|
||||
|
||||
latency: latency.cpp
|
||||
$(CXX) latency.cpp -o latency $(CXXFLAGS) $(CXX_RELEASE_FLAGS)
|
||||
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
clean:
|
||||
rm -f *.o logs/* $(binaries)
|
||||
|
||||
rebuild: clean all
|
||||
@@ -6,97 +6,123 @@
|
||||
//
|
||||
// bench.cpp : spdlog benchmarks
|
||||
//
|
||||
#include "spdlog/async.h"
|
||||
#include "spdlog/sinks/basic_file_sink.h"
|
||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "utils.h"
|
||||
#include <atomic>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <locale>
|
||||
#include <algorithm>
|
||||
|
||||
#include "spdlog/sinks/async_sink.h"
|
||||
#include "spdlog/sinks/basic_file_sink.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace std::chrono;
|
||||
using namespace spdlog;
|
||||
using namespace spdlog::sinks;
|
||||
using namespace utils;
|
||||
|
||||
void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count);
|
||||
|
||||
int count_lines(const char *filename)
|
||||
{
|
||||
int counter = 0;
|
||||
auto *infile = fopen(filename, "r");
|
||||
int ch;
|
||||
while (EOF != (ch = getc(infile)))
|
||||
{
|
||||
if ('\n' == ch)
|
||||
counter++;
|
||||
}
|
||||
fclose(infile);
|
||||
|
||||
return counter;
|
||||
int count_lines(const char *filename) {
|
||||
std::ifstream ifs(filename);
|
||||
return std::count(std::istreambuf_iterator(ifs), std::istreambuf_iterator<char>(), '\n');
|
||||
}
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
void verify_file(const char *filename, int expected_count) {
|
||||
spdlog::info("Verifying {} to contain {} line..", filename, expected_count);
|
||||
auto count = count_lines(filename);
|
||||
if (count != expected_count) {
|
||||
spdlog::error("Test failed. {} has {} lines instead of {}", filename, count, expected_count);
|
||||
exit(1);
|
||||
}
|
||||
spdlog::info("Line count OK ({})\n", count);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
using namespace spdlog::sinks;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// setlocale to show thousands separators
|
||||
std::locale::global(std::locale("en_US.UTF-8"));
|
||||
int howmany = 1000000;
|
||||
int queue_size = howmany + 2;
|
||||
int queue_size = std::min(howmany + 2, 8192);
|
||||
int threads = 10;
|
||||
int iters = 3;
|
||||
|
||||
try
|
||||
{
|
||||
auto console = spdlog::stdout_color_mt("console");
|
||||
if (argc == 1)
|
||||
{
|
||||
console->set_pattern("%v");
|
||||
console->info("Usage: {} <message_count> <threads> <q_size> <iterations>", argv[0]);
|
||||
try {
|
||||
spdlog::set_pattern("[%^%l%$] %v");
|
||||
if (argc > 1 && (std::string(argv[1]) == "-h" || std::string(argv[1]) == "--help")) {
|
||||
spdlog::info("Usage: {} <message_count> <threads> <q_size> <iterations>", argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argc > 1)
|
||||
howmany = atoi(argv[1]);
|
||||
if (argc > 2)
|
||||
threads = atoi(argv[2]);
|
||||
if (argc > 3)
|
||||
if (argc > 1) howmany = atoi(argv[1]);
|
||||
if (argc > 2) threads = atoi(argv[2]);
|
||||
if (argc > 3) {
|
||||
queue_size = atoi(argv[3]);
|
||||
|
||||
if (argc > 4)
|
||||
iters = atoi(argv[4]);
|
||||
|
||||
console->info("-------------------------------------------------");
|
||||
console->info("Messages: {:14n}", howmany);
|
||||
console->info("Threads : {:14n}", threads);
|
||||
console->info("Queue : {:14n}", queue_size);
|
||||
console->info("Iters : {:>14n}", iters);
|
||||
console->info("-------------------------------------------------");
|
||||
|
||||
const char *filename = "logs/basic_async.log";
|
||||
|
||||
for (int i = 0; i < iters; i++)
|
||||
{
|
||||
auto tp = std::make_shared<details::thread_pool>(queue_size, 1);
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename, true);
|
||||
auto logger = std::make_shared<async_logger>("async_logger", std::move(file_sink), std::move(tp), async_overflow_policy::block);
|
||||
bench_mt(howmany, std::move(logger), threads);
|
||||
auto count = count_lines(filename);
|
||||
|
||||
if (count != howmany)
|
||||
{
|
||||
console->error("Test failed. {} has {:n} lines instead of {:n}", filename, count, howmany);
|
||||
if (queue_size > 500000) {
|
||||
spdlog::error("Max queue size allowed: 500,000");
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
console->info("Line count OK ({:n})\n", count);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::exception &ex)
|
||||
{
|
||||
|
||||
if (argc > 4) iters = atoi(argv[4]);
|
||||
// validate all argc values
|
||||
if (howmany < 1 || threads < 1 || queue_size < 1 || iters < 1) {
|
||||
spdlog::error("Invalid input values");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
auto slot_size = sizeof(details::async_log_msg);
|
||||
spdlog::info("-------------------------------------------------");
|
||||
spdlog::info("Messages : {:L}", howmany);
|
||||
spdlog::info("Threads : {:L}", threads);
|
||||
spdlog::info("Queue : {:L} slots", queue_size);
|
||||
spdlog::info("Queue memory : {:L} x {:L} = {:L} KB ", queue_size, slot_size, (queue_size * slot_size) / 1024);
|
||||
spdlog::info("Total iters : {:L}", iters);
|
||||
spdlog::info("-------------------------------------------------");
|
||||
|
||||
const char *filename = "logs/basic_async.log";
|
||||
spdlog::info("");
|
||||
spdlog::info("*********************************");
|
||||
spdlog::info("Queue Overflow Policy: block");
|
||||
spdlog::info("*********************************");
|
||||
for (int i = 0; i < iters; i++) {
|
||||
{
|
||||
auto file_sink = std::make_shared<basic_file_sink_mt>(filename, true);
|
||||
auto cfg = async_sink::config();
|
||||
cfg.queue_size = queue_size;
|
||||
cfg.sinks.push_back(std::move(file_sink));
|
||||
auto async_sink = std::make_shared<sinks::async_sink>(cfg);
|
||||
auto logger = std::make_shared<spdlog::logger>("async_logger", std::move(async_sink));
|
||||
bench_mt(howmany, std::move(logger), threads);
|
||||
}
|
||||
//verify_file(filename, howmany); // in separate scope to ensure logger is destroyed and all logs were written
|
||||
}
|
||||
spdlog::info("");
|
||||
spdlog::info("*********************************");
|
||||
spdlog::info("Queue Overflow Policy: overrun");
|
||||
spdlog::info("*********************************");
|
||||
// do same test but discard the oldest if queue is full instead of blocking
|
||||
filename = "logs/basic_async-overrun.log";
|
||||
for (int i = 0; i < iters; i++) {
|
||||
async_sink::config cfg;
|
||||
cfg.policy = async_sink::overflow_policy::overrun_oldest;
|
||||
cfg.queue_size = queue_size;
|
||||
auto file_sink = std::make_shared<basic_file_sink_mt>(filename, true);
|
||||
cfg.sinks.push_back(std::move(file_sink));
|
||||
auto async_sink = std::make_shared<sinks::async_sink>(cfg);
|
||||
auto logger = std::make_shared<spdlog::logger>("async_logger", std::move(async_sink));
|
||||
bench_mt(howmany, std::move(logger), threads);
|
||||
}
|
||||
spdlog::shutdown();
|
||||
} catch (std::exception &ex) {
|
||||
std::cerr << "Error: " << ex.what() << std::endl;
|
||||
perror("Last error");
|
||||
return 1;
|
||||
@@ -104,36 +130,31 @@ int main(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
void thread_fun(std::shared_ptr<spdlog::logger> logger, int howmany)
|
||||
{
|
||||
for (int i = 0; i < howmany; i++)
|
||||
{
|
||||
void thread_fun(std::shared_ptr<spdlog::logger> logger, int howmany) {
|
||||
for (int i = 0; i < howmany; i++) {
|
||||
logger->info("Hello logger: msg number {}", i);
|
||||
}
|
||||
}
|
||||
|
||||
void bench_mt(int howmany, std::shared_ptr<spdlog::logger> logger, int thread_count)
|
||||
{
|
||||
void bench_mt(int howmany, std::shared_ptr<spdlog::logger> logger, int thread_count) {
|
||||
using std::chrono::high_resolution_clock;
|
||||
vector<thread> threads;
|
||||
vector<std::thread> threads;
|
||||
auto start = high_resolution_clock::now();
|
||||
|
||||
int msgs_per_thread = howmany / thread_count;
|
||||
int msgs_per_thread_mod = howmany % thread_count;
|
||||
for (int t = 0; t < thread_count; ++t)
|
||||
{
|
||||
for (int t = 0; t < thread_count; ++t) {
|
||||
if (t == 0 && msgs_per_thread_mod)
|
||||
threads.push_back(std::thread(thread_fun, logger, msgs_per_thread + msgs_per_thread_mod));
|
||||
else
|
||||
threads.push_back(std::thread(thread_fun, logger, msgs_per_thread));
|
||||
}
|
||||
|
||||
for (auto &t : threads)
|
||||
{
|
||||
for (auto &t : threads) {
|
||||
t.join();
|
||||
};
|
||||
}
|
||||
|
||||
auto delta = high_resolution_clock::now() - start;
|
||||
auto delta_d = duration_cast<duration<double>>(delta).count();
|
||||
spdlog::get("console")->info("Elapsed: {} secs\t {:n}/sec", delta_d, int(howmany / delta_d));
|
||||
spdlog::info("Elapsed: {} secs\t {:L}/sec", delta_d, static_cast<int>(howmany / delta_d));
|
||||
}
|
||||
|
||||
237
bench/bench.cpp
237
bench/bench.cpp
@@ -6,143 +6,196 @@
|
||||
//
|
||||
// bench.cpp : spdlog benchmarks
|
||||
//
|
||||
#include "spdlog/async.h"
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdlib> // EXIT_FAILURE
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include "spdlog/sinks/basic_file_sink.h"
|
||||
#include "spdlog/sinks/daily_file_sink.h"
|
||||
#include "spdlog/sinks/null_sink.h"
|
||||
#include "spdlog/sinks/rotating_file_sink.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "utils.h"
|
||||
#include <atomic>
|
||||
#include <cstdlib> // EXIT_FAILURE
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
using namespace std;
|
||||
using namespace std::chrono;
|
||||
using namespace spdlog;
|
||||
using namespace spdlog::sinks;
|
||||
using namespace utils;
|
||||
|
||||
void bench(int howmany, std::shared_ptr<spdlog::logger> log);
|
||||
void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count);
|
||||
void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, size_t thread_count);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// void bench_default_api(int howmany, std::shared_ptr<spdlog::logger> log);
|
||||
// void bench_c_string(int howmany, std::shared_ptr<spdlog::logger> log);
|
||||
|
||||
int howmany = 1000000;
|
||||
int queue_size = howmany + 2;
|
||||
int threads = 10;
|
||||
size_t file_size = 30 * 1024 * 1024;
|
||||
size_t rotating_files = 5;
|
||||
static const size_t file_size = 30 * 1024 * 1024;
|
||||
static const size_t rotating_files = 5;
|
||||
static const int max_threads = 1000;
|
||||
|
||||
try
|
||||
{
|
||||
using namespace spdlog::sinks;
|
||||
void bench_threaded_logging(size_t threads, int iters) {
|
||||
spdlog::info("**************************************************************");
|
||||
spdlog::info(
|
||||
spdlog::fmt_lib::format(std::locale("en_US.UTF-8"), "Multi threaded: {:L} threads, {:L} messages", threads, iters));
|
||||
spdlog::info("**************************************************************");
|
||||
|
||||
if (argc > 1)
|
||||
howmany = atoi(argv[1]);
|
||||
if (argc > 2)
|
||||
threads = atoi(argv[2]);
|
||||
if (argc > 3)
|
||||
queue_size = atoi(argv[3]);
|
||||
auto basic_mt = spdlog::create<basic_file_sink_mt>("basic_mt", "logs/basic_mt.log", true);
|
||||
bench_mt(iters, std::move(basic_mt), threads);
|
||||
|
||||
cout << "******************************************************************"
|
||||
"*************\n";
|
||||
cout << "Single thread, " << format(howmany) << " iterations" << endl;
|
||||
cout << "******************************************************************"
|
||||
"*************\n";
|
||||
spdlog::info("");
|
||||
auto rotating_mt = spdlog::create<rotating_file_sink_mt>("rotating_mt", "logs/rotating_mt.log", file_size, rotating_files);
|
||||
bench_mt(iters, std::move(rotating_mt), threads);
|
||||
|
||||
auto basic_st = spdlog::basic_logger_st("basic_st", "logs/basic_st.log", true);
|
||||
bench(howmany, basic_st);
|
||||
spdlog::info("");
|
||||
auto daily_mt = spdlog::create<daily_file_sink_mt>("daily_mt", "logs/daily_mt.log", 0, 1);
|
||||
bench_mt(iters, std::move(daily_mt), threads);
|
||||
|
||||
auto rotating_st = spdlog::rotating_logger_st("rotating_st", "logs/rotating_st.log", file_size, rotating_files);
|
||||
bench(howmany, rotating_st);
|
||||
spdlog::info("");
|
||||
auto empty_logger = std::make_shared<spdlog::logger>("level-off");
|
||||
empty_logger->set_level(spdlog::level::off);
|
||||
bench(iters, empty_logger);
|
||||
}
|
||||
|
||||
auto daily_st = spdlog::daily_logger_st("daily_st", "logs/daily_st.log");
|
||||
bench(howmany, daily_st);
|
||||
void bench_single_threaded(int iters) {
|
||||
spdlog::info("**************************************************************");
|
||||
spdlog::info(spdlog::fmt_lib::format(std::locale("en_US.UTF-8"), "Single threaded: {} messages", iters));
|
||||
spdlog::info("**************************************************************");
|
||||
|
||||
bench(howmany, spdlog::create<null_sink_st>("null_st"));
|
||||
auto basic_st = spdlog::create<basic_file_sink_st>("basic_st", "logs/basic_st.log", true);
|
||||
bench(iters, std::move(basic_st));
|
||||
|
||||
cout << "\n****************************************************************"
|
||||
"***************\n";
|
||||
cout << threads << " threads sharing same logger, " << format(howmany) << " iterations" << endl;
|
||||
cout << "******************************************************************"
|
||||
"*************\n";
|
||||
spdlog::info("");
|
||||
auto rotating_st = spdlog::create<rotating_file_sink_st>("rotating_st", "logs/rotating_st.log", file_size, rotating_files);
|
||||
bench(iters, std::move(rotating_st));
|
||||
|
||||
auto basic_mt = spdlog::basic_logger_mt("basic_mt", "logs/basic_mt.log", true);
|
||||
bench_mt(howmany, basic_mt, threads);
|
||||
spdlog::info("");
|
||||
auto daily_st = spdlog::create<daily_file_sink_st>("daily_st", "logs/daily_st.log", 0, 1);
|
||||
bench(iters, std::move(daily_st));
|
||||
|
||||
auto rotating_mt = spdlog::rotating_logger_mt("rotating_mt", "logs/rotating_mt.log", file_size, rotating_files);
|
||||
bench_mt(howmany, rotating_mt, threads);
|
||||
spdlog::info("");
|
||||
auto empty_logger = std::make_shared<spdlog::logger>("level-off");
|
||||
empty_logger->set_level(spdlog::level::off);
|
||||
bench(iters, empty_logger);
|
||||
}
|
||||
|
||||
auto daily_mt = spdlog::daily_logger_mt("daily_mt", "logs/daily_mt.log");
|
||||
bench_mt(howmany, daily_mt, threads);
|
||||
bench_mt(howmany, spdlog::create<null_sink_mt>("null_mt"), threads);
|
||||
|
||||
cout << "\n****************************************************************"
|
||||
"***************\n";
|
||||
cout << "async logging.. " << threads << " threads sharing same logger, " << format(howmany) << " iterations " << endl;
|
||||
cout << "******************************************************************"
|
||||
"*************\n";
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
spdlog::init_thread_pool(static_cast<size_t>(queue_size), 1);
|
||||
auto as = spdlog::basic_logger_mt<spdlog::async_factory>("async", "logs/basic_async.log", true);
|
||||
bench_mt(howmany, as, threads);
|
||||
spdlog::drop("async");
|
||||
int main(int argc, char *argv[]) {
|
||||
spdlog::global_logger()->set_pattern("[%^%l%$] %v");
|
||||
int iters = 250000;
|
||||
size_t threads = 4;
|
||||
try {
|
||||
if (argc > 1) {
|
||||
iters = std::stoi(argv[1]);
|
||||
}
|
||||
}
|
||||
catch (std::exception &ex)
|
||||
{
|
||||
std::cerr << "Error: " << ex.what() << std::endl;
|
||||
perror("Last error");
|
||||
if (argc > 2) {
|
||||
threads = std::stoul(argv[2]);
|
||||
}
|
||||
|
||||
if (threads > max_threads) {
|
||||
throw std::runtime_error(spdlog::fmt_lib::format("Number of threads exceeds maximum({})", max_threads));
|
||||
}
|
||||
|
||||
bench_single_threaded(iters);
|
||||
bench_threaded_logging(1, iters);
|
||||
bench_threaded_logging(threads, iters);
|
||||
} catch (std::exception &ex) {
|
||||
spdlog::error(ex.what());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void bench(int howmany, std::shared_ptr<spdlog::logger> log)
|
||||
{
|
||||
void bench(int howmany, std::shared_ptr<spdlog::logger> log) {
|
||||
using std::chrono::duration;
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::high_resolution_clock;
|
||||
cout << log->name() << "...\t\t" << flush;
|
||||
|
||||
auto start = high_resolution_clock::now();
|
||||
for (auto i = 0; i < howmany; ++i)
|
||||
{
|
||||
for (auto i = 0; i < howmany; ++i) {
|
||||
log->info("Hello logger: msg number {}", i);
|
||||
}
|
||||
|
||||
auto delta = high_resolution_clock::now() - start;
|
||||
auto delta_d = duration_cast<duration<double>>(delta).count();
|
||||
|
||||
cout << "Elapsed: " << delta_d << "\t" << format(int(howmany / delta_d)) << "/sec" << endl;
|
||||
spdlog::drop(log->name());
|
||||
spdlog::info(spdlog::fmt_lib::format(std::locale("en_US.UTF-8"), "{:<30} Elapsed: {:0.2f} secs {:>16L}/sec", log->name(),
|
||||
delta_d, static_cast<size_t>(howmany / delta_d)));
|
||||
}
|
||||
|
||||
void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count)
|
||||
{
|
||||
void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, size_t thread_count) {
|
||||
using std::chrono::duration;
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::high_resolution_clock;
|
||||
cout << log->name() << "...\t\t" << flush;
|
||||
vector<thread> threads;
|
||||
|
||||
std::vector<std::thread> threads;
|
||||
threads.reserve(thread_count);
|
||||
auto start = high_resolution_clock::now();
|
||||
for (int t = 0; t < thread_count; ++t)
|
||||
{
|
||||
threads.push_back(std::thread([&]() {
|
||||
for (int j = 0; j < howmany / thread_count; j++)
|
||||
{
|
||||
for (size_t t = 0; t < thread_count; ++t) {
|
||||
threads.emplace_back([&]() {
|
||||
for (int j = 0; j < howmany / static_cast<int>(thread_count); j++) {
|
||||
log->info("Hello logger: msg number {}", j);
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
for (auto &t : threads)
|
||||
{
|
||||
for (auto &t : threads) {
|
||||
t.join();
|
||||
};
|
||||
}
|
||||
|
||||
auto delta = high_resolution_clock::now() - start;
|
||||
auto delta_d = duration_cast<duration<double>>(delta).count();
|
||||
cout << "Elapsed: " << delta_d << "\t" << format(int(howmany / delta_d)) << "/sec" << endl;
|
||||
spdlog::info(spdlog::fmt_lib::format(std::locale("en_US.UTF-8"), "{:<30} Elapsed: {:0.2f} secs {:>16L}/sec", log->name(),
|
||||
delta_d, static_cast<size_t>(howmany / delta_d)));
|
||||
}
|
||||
|
||||
/*
|
||||
void bench_default_api(int howmany, std::shared_ptr<spdlog::logger> log)
|
||||
{
|
||||
using std::chrono::high_resolution_clock;
|
||||
using std::chrono::duration;
|
||||
using std::chrono::duration_cast;
|
||||
|
||||
auto orig_default = spdlog::global_logger();
|
||||
spdlog::set_global_logger(log);
|
||||
auto start = high_resolution_clock::now();
|
||||
for (auto i = 0; i < howmany; ++i)
|
||||
{
|
||||
spdlog::info("Hello logger: msg number {}", i);
|
||||
}
|
||||
|
||||
auto delta = high_resolution_clock::now() - start;
|
||||
auto delta_d = duration_cast<duration<double>>(delta).count();
|
||||
spdlog::drop(log->name());
|
||||
spdlog::set_global_logger(std::move(orig_default));
|
||||
spdlog::info("{:<30} Elapsed: {:0.2f} secs {:>16}/sec", log->name(), delta_d, int(howmany /
|
||||
delta_d));
|
||||
}
|
||||
|
||||
void bench_c_string(int howmany, std::shared_ptr<spdlog::logger> log)
|
||||
{
|
||||
using std::chrono::high_resolution_clock;
|
||||
using std::chrono::duration;
|
||||
using std::chrono::duration_cast;
|
||||
|
||||
const char *msg = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum pharetra
|
||||
metus cursus " "lacus placerat congue. Nulla egestas, mauris a tincidunt tempus, enim lectus
|
||||
volutpat mi, eu consequat sem " "libero nec massa. In dapibus ipsum a diam rhoncus gravida. Etiam
|
||||
non dapibus eros. Donec fringilla dui sed " "augue pretium, nec scelerisque est maximus. Nullam
|
||||
convallis, sem nec blandit maximus, nisi turpis ornare " "nisl, sit amet volutpat neque massa eu
|
||||
odio. Maecenas malesuada quam ex, posuere congue nibh turpis duis.";
|
||||
|
||||
auto orig_default = spdlog::global_logger();
|
||||
spdlog::set_global_logger(log);
|
||||
auto start = high_resolution_clock::now();
|
||||
for (auto i = 0; i < howmany; ++i)
|
||||
{
|
||||
spdlog::log(spdlog::level::info, msg);
|
||||
}
|
||||
|
||||
auto delta = high_resolution_clock::now() - start;
|
||||
auto delta_d = duration_cast<duration<double>>(delta).count();
|
||||
spdlog::drop(log->name());
|
||||
spdlog::set_global_logger(std::move(orig_default));
|
||||
spdlog::info("{:<30} Elapsed: {:0.2f} secs {:>16}/sec", log->name(), delta_d, int(howmany /
|
||||
delta_d));
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
68
bench/formatter-bench.cpp
Normal file
68
bench/formatter-bench.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// Copyright(c) 2018 Gabi Melman.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#include "benchmark/benchmark.h"
|
||||
#include "spdlog/pattern_formatter.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
void bench_formatter(benchmark::State &state, std::string pattern) {
|
||||
auto formatter = std::make_unique<spdlog::pattern_formatter>(pattern);
|
||||
spdlog::memory_buf_t dest;
|
||||
std::string logger_name = "logger-name";
|
||||
const char *text = "Hello. This is some message with length of 80 ";
|
||||
|
||||
spdlog::source_loc source_loc{"a/b/c/d/myfile.cpp", 123, "some_func()"};
|
||||
spdlog::details::log_msg msg(source_loc, logger_name, spdlog::level::info, text);
|
||||
|
||||
for (auto _ : state) {
|
||||
dest.clear();
|
||||
formatter->format(msg, dest);
|
||||
benchmark::DoNotOptimize(dest);
|
||||
}
|
||||
}
|
||||
|
||||
void bench_formatters() {
|
||||
// basic patterns(single flag)
|
||||
std::string all_flags = "+vtPnlLaAbBcCYDmdHIMSefFprRTXzEisg@luioO%";
|
||||
std::vector<std::string> basic_patterns;
|
||||
for (auto &flag : all_flags) {
|
||||
auto pattern = std::string("%") + flag;
|
||||
benchmark::RegisterBenchmark(pattern.c_str(), &bench_formatter, pattern);
|
||||
|
||||
// pattern = std::string("%16") + flag;
|
||||
// benchmark::RegisterBenchmark(pattern.c_str(), &bench_formatter, pattern);
|
||||
//
|
||||
// // bench center padding
|
||||
// pattern = std::string("%=16") + flag;
|
||||
// benchmark::RegisterBenchmark(pattern.c_str(), &bench_formatter, pattern);
|
||||
}
|
||||
|
||||
// complex patterns
|
||||
std::vector<std::string> patterns = {
|
||||
"[%D %X] [%l] [%n] %v",
|
||||
"[%Y-%m-%d %H:%M:%S.%e] [%l] [%n] %v",
|
||||
"[%Y-%m-%d %H:%M:%S.%e] [%l] [%n] [%t] %v",
|
||||
};
|
||||
for (auto &pattern : patterns) {
|
||||
benchmark::RegisterBenchmark(pattern.c_str(), &bench_formatter, pattern)->Iterations(2500000);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
spdlog::set_pattern("[%^%l%$] %v");
|
||||
if (argc != 2) {
|
||||
spdlog::error("Usage: {} <pattern> (or \"all\" to bench all)", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
std::string pattern = argv[1];
|
||||
if (pattern == "all") {
|
||||
bench_formatters();
|
||||
} else {
|
||||
benchmark::RegisterBenchmark(pattern.c_str(), &bench_formatter, pattern);
|
||||
}
|
||||
benchmark::Initialize(&argc, argv);
|
||||
benchmark::RunSpecifiedBenchmarks();
|
||||
}
|
||||
@@ -6,146 +6,157 @@
|
||||
//
|
||||
// latency.cpp : spdlog latency benchmarks
|
||||
//
|
||||
#include "spdlog/async.h"
|
||||
|
||||
#include "benchmark/benchmark.h"
|
||||
#include "spdlog/sinks/async_sink.h"
|
||||
#include "spdlog/sinks/basic_file_sink.h"
|
||||
#include "spdlog/sinks/daily_file_sink.h"
|
||||
#include "spdlog/sinks/null_sink.h"
|
||||
#include "spdlog/sinks/rotating_file_sink.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "utils.h"
|
||||
#include <atomic>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
using namespace std;
|
||||
using namespace std::chrono;
|
||||
using namespace spdlog;
|
||||
using namespace spdlog::sinks;
|
||||
using namespace utils;
|
||||
void bench_c_string(benchmark::State &state, std::shared_ptr<spdlog::logger> logger) {
|
||||
const char *msg =
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum pharetra metus cursus "
|
||||
"lacus placerat congue. Nulla egestas, mauris a tincidunt tempus, enim lectus volutpat mi, "
|
||||
"eu consequat sem "
|
||||
"libero nec massa. In dapibus ipsum a diam rhoncus gravida. Etiam non dapibus eros. Donec "
|
||||
"fringilla dui sed "
|
||||
"augue pretium, nec scelerisque est maximus. Nullam convallis, sem nec blandit maximus, "
|
||||
"nisi turpis ornare "
|
||||
"nisl, sit amet volutpat neque massa eu odio. Maecenas malesuada quam ex, posuere congue "
|
||||
"nibh turpis duis.";
|
||||
|
||||
void bench(int howmany, std::shared_ptr<spdlog::logger> log);
|
||||
void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count);
|
||||
for (auto _ : state) {
|
||||
logger->info(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void bench_logger(benchmark::State &state, std::shared_ptr<spdlog::logger> logger) {
|
||||
int i = 0;
|
||||
for (auto _ : state) {
|
||||
logger->info("Hello logger: msg number {}...............", ++i);
|
||||
}
|
||||
}
|
||||
|
||||
void bench_global_logger(benchmark::State &state, std::shared_ptr<spdlog::logger> logger) {
|
||||
spdlog::set_global_logger(std::move(logger));
|
||||
int i = 0;
|
||||
for (auto _ : state) {
|
||||
spdlog::info("Hello logger: msg number {}...............", ++i);
|
||||
}
|
||||
}
|
||||
|
||||
void bench_disabled_macro(benchmark::State &state, std::shared_ptr<spdlog::logger> logger) {
|
||||
int i = 0;
|
||||
benchmark::DoNotOptimize(i); // prevent unused warnings
|
||||
benchmark::DoNotOptimize(logger); // prevent unused warnings
|
||||
for (auto _ : state) {
|
||||
SPDLOG_LOGGER_DEBUG(logger, "Hello logger: msg number {}...............", i++);
|
||||
}
|
||||
}
|
||||
|
||||
void bench_disabled_macro_global_logger(benchmark::State &state, std::shared_ptr<spdlog::logger> logger) {
|
||||
spdlog::set_global_logger(std::move(logger));
|
||||
int i = 0;
|
||||
benchmark::DoNotOptimize(i); // prevent unused warnings
|
||||
benchmark::DoNotOptimize(logger); // prevent unused warnings
|
||||
for (auto _ : state) {
|
||||
SPDLOG_DEBUG("Hello logger: msg number {}...............", i++);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
void bench_dev_null() {
|
||||
auto dev_null_st = spdlog::create<basic_file_sink_st>("/dev/null_st", "/dev/null");
|
||||
benchmark::RegisterBenchmark("/dev/null_st", bench_logger, std::move(dev_null_st))->UseRealTime();
|
||||
|
||||
auto dev_null_mt = spdlog::create<basic_file_sink_mt>("/dev/null_mt", "/dev/null");
|
||||
benchmark::RegisterBenchmark("/dev/null_mt", bench_logger, std::move(dev_null_mt))->UseRealTime();
|
||||
}
|
||||
|
||||
#endif // __linux__
|
||||
|
||||
// test spdlog::get() performance
|
||||
// for this test we create multiple null loggers and then call spdlog::get() on one of them multiple times
|
||||
// create multiple null loggers and return name of the one to test
|
||||
static std::string prepare_null_loggers() {
|
||||
const std::string some_logger_name = "Some logger name";
|
||||
const int null_logger_count = 9;
|
||||
for (int i = 0; i < null_logger_count; i++) {
|
||||
spdlog::create<null_sink_mt>(some_logger_name + std::to_string(i));
|
||||
}
|
||||
return some_logger_name + std::to_string(null_logger_count / 2);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
using spdlog::sinks::null_sink_mt;
|
||||
using spdlog::sinks::null_sink_st;
|
||||
|
||||
int main(int, char *[])
|
||||
{
|
||||
std::srand(static_cast<unsigned>(std::time(nullptr))); // use current time as seed for random generator
|
||||
int howmany = 1000000;
|
||||
int queue_size = howmany + 2;
|
||||
int threads = 10;
|
||||
size_t file_size = 30 * 1024 * 1024;
|
||||
size_t rotating_files = 5;
|
||||
int n_threads = benchmark::CPUInfo::Get().num_cpus;
|
||||
|
||||
try
|
||||
{
|
||||
auto full_bench = argc > 1 && std::string(argv[1]) == "full";
|
||||
|
||||
cout << "******************************************************************"
|
||||
"*************\n";
|
||||
cout << "Single thread\n";
|
||||
cout << "******************************************************************"
|
||||
"*************\n";
|
||||
// disabled loggers
|
||||
auto disabled_logger = std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_mt>());
|
||||
disabled_logger->set_level(spdlog::level::off);
|
||||
benchmark::RegisterBenchmark("disabled-at-compile-time", bench_disabled_macro, disabled_logger);
|
||||
benchmark::RegisterBenchmark("disabled-at-compile-time (global logger)", bench_disabled_macro_global_logger, disabled_logger);
|
||||
benchmark::RegisterBenchmark("disabled-at-runtime", bench_logger, disabled_logger);
|
||||
benchmark::RegisterBenchmark("disabled-at-runtime (global logger)", bench_global_logger, disabled_logger);
|
||||
|
||||
auto basic_st = spdlog::basic_logger_mt("basic_st", "logs/basic_st.log", true);
|
||||
bench(howmany, basic_st);
|
||||
auto null_logger_st = std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_st>());
|
||||
benchmark::RegisterBenchmark("null_sink_st (500_bytes c_str)", bench_c_string, std::move(null_logger_st));
|
||||
benchmark::RegisterBenchmark("null_sink_st", bench_logger, null_logger_st);
|
||||
benchmark::RegisterBenchmark("null_sink_st (global logger)", bench_global_logger, null_logger_st);
|
||||
|
||||
auto rotating_st = spdlog::rotating_logger_st("rotating_st", "logs/rotating_st.log", file_size, rotating_files);
|
||||
bench(howmany, rotating_st);
|
||||
#ifdef __linux__
|
||||
bench_dev_null();
|
||||
#endif // __linux__
|
||||
|
||||
auto daily_st = spdlog::daily_logger_st("daily_st", "logs/daily_st.log");
|
||||
bench(howmany, daily_st);
|
||||
if (full_bench) {
|
||||
// basic_st
|
||||
auto basic_st = spdlog::create<basic_file_sink_st>("basic_st", "latency_logs/basic_st.log", true);
|
||||
benchmark::RegisterBenchmark("basic_st", bench_logger, std::move(basic_st))->UseRealTime();
|
||||
|
||||
bench(howmany, spdlog::create<null_sink_st>("null_st"));
|
||||
// rotating st
|
||||
auto rotating_st = spdlog::create<rotating_file_sink_st>("rotating_st", "latency_logs/rotating_st.log", file_size, rotating_files);
|
||||
benchmark::RegisterBenchmark("rotating_st", bench_logger, std::move(rotating_st))->UseRealTime();
|
||||
|
||||
cout << "\n****************************************************************"
|
||||
"***************\n";
|
||||
cout << threads << " threads sharing same logger\n";
|
||||
cout << "******************************************************************"
|
||||
"*************\n";
|
||||
// daily st
|
||||
auto daily_st = spdlog::create<daily_file_sink_st>("daily_st", "latency_logs/daily_st.log", 0, 1);
|
||||
benchmark::RegisterBenchmark("daily_st", bench_logger, std::move(daily_st))->UseRealTime();
|
||||
|
||||
auto basic_mt = spdlog::basic_logger_mt("basic_mt", "logs/basic_mt.log", true);
|
||||
bench_mt(howmany, basic_mt, threads);
|
||||
//
|
||||
// Multi threaded bench, 10 loggers using same logger concurrently
|
||||
//
|
||||
auto null_logger_mt = std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_mt>());
|
||||
benchmark::RegisterBenchmark("null_sink_mt", bench_logger, null_logger_mt)->Threads(n_threads)->UseRealTime();
|
||||
|
||||
auto rotating_mt = spdlog::rotating_logger_mt("rotating_mt", "logs/rotating_mt.log", file_size, rotating_files);
|
||||
bench_mt(howmany, rotating_mt, threads);
|
||||
// basic_mt
|
||||
auto basic_mt = spdlog::create<basic_file_sink_mt>("basic_mt", "latency_logs/basic_mt.log", true);
|
||||
benchmark::RegisterBenchmark("basic_mt", bench_logger, std::move(basic_mt))->Threads(n_threads)->UseRealTime();
|
||||
|
||||
auto daily_mt = spdlog::daily_logger_mt("daily_mt", "logs/daily_mt.log");
|
||||
bench_mt(howmany, daily_mt, threads);
|
||||
bench(howmany, spdlog::create<null_sink_st>("null_mt"));
|
||||
// rotating mt
|
||||
auto rotating_mt = spdlog::create<rotating_file_sink_mt>("rotating_mt", "latency_logs/rotating_mt.log", file_size, rotating_files);
|
||||
benchmark::RegisterBenchmark("rotating_mt", bench_logger, std::move(rotating_mt))->Threads(n_threads)->UseRealTime();
|
||||
|
||||
cout << "\n****************************************************************"
|
||||
"***************\n";
|
||||
cout << "async logging.. " << threads << " threads sharing same logger\n";
|
||||
cout << "******************************************************************"
|
||||
"*************\n";
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
spdlog::init_thread_pool(static_cast<size_t>(queue_size), 1);
|
||||
auto as = spdlog::basic_logger_mt<spdlog::async_factory>("async", "logs/basic_async.log", true);
|
||||
bench_mt(howmany, as, threads);
|
||||
spdlog::drop("async");
|
||||
}
|
||||
// daily mt
|
||||
auto daily_mt = spdlog::create<daily_file_sink_mt>("daily_mt", "latency_logs/daily_mt.log", 0, 1);
|
||||
benchmark::RegisterBenchmark("daily_mt", bench_logger, std::move(daily_mt))->Threads(n_threads)->UseRealTime();
|
||||
}
|
||||
catch (std::exception &ex)
|
||||
{
|
||||
std::cerr << "Error: " << ex.what() << std::endl;
|
||||
perror("Last error");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void bench(int howmany, std::shared_ptr<spdlog::logger> log)
|
||||
{
|
||||
using namespace std::chrono;
|
||||
using chrono::high_resolution_clock;
|
||||
using chrono::milliseconds;
|
||||
using chrono::nanoseconds;
|
||||
|
||||
cout << log->name() << "...\t\t" << flush;
|
||||
nanoseconds total_nanos = nanoseconds::zero();
|
||||
for (auto i = 0; i < howmany; ++i)
|
||||
{
|
||||
auto start = high_resolution_clock::now();
|
||||
log->info("Hello logger: msg number {}", i);
|
||||
auto delta_nanos = chrono::duration_cast<nanoseconds>(high_resolution_clock::now() - start);
|
||||
total_nanos += delta_nanos;
|
||||
}
|
||||
|
||||
auto avg = total_nanos.count() / howmany;
|
||||
cout << format(avg) << " ns/call" << endl;
|
||||
}
|
||||
|
||||
void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count)
|
||||
{
|
||||
using namespace std::chrono;
|
||||
using chrono::high_resolution_clock;
|
||||
using chrono::milliseconds;
|
||||
using chrono::nanoseconds;
|
||||
|
||||
cout << log->name() << "...\t\t" << flush;
|
||||
vector<thread> threads;
|
||||
std::atomic<nanoseconds::rep> total_nanos{0};
|
||||
for (int t = 0; t < thread_count; ++t)
|
||||
{
|
||||
threads.push_back(std::thread([&]() {
|
||||
for (int j = 0; j < howmany / thread_count; j++)
|
||||
{
|
||||
auto start = high_resolution_clock::now();
|
||||
log->info("Hello logger: msg number {}", j);
|
||||
auto delta_nanos = chrono::duration_cast<nanoseconds>(high_resolution_clock::now() - start);
|
||||
total_nanos += delta_nanos.count();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
for (auto &t : threads)
|
||||
{
|
||||
t.join();
|
||||
};
|
||||
|
||||
auto avg = total_nanos / howmany;
|
||||
cout << format(avg) << " ns/call" << endl;
|
||||
using spdlog::sinks::async_sink;
|
||||
async_sink::config config;
|
||||
config.queue_size = 3 * 1024 * 1024;;
|
||||
config.sinks.push_back(std::make_shared<null_sink_st>());
|
||||
config.policy = async_sink::overflow_policy::overrun_oldest;
|
||||
auto async_logger = std::make_shared<spdlog::logger>("async_logger", std::make_shared<async_sink>(config));
|
||||
benchmark::RegisterBenchmark("async_logger", bench_logger, async_logger)->Threads(n_threads)->UseRealTime();
|
||||
|
||||
benchmark::Initialize(&argc, argv);
|
||||
benchmark::RunSpecifiedBenchmarks();
|
||||
}
|
||||
|
||||
4
bench/logs/.gitignore
vendored
4
bench/logs/.gitignore
vendored
@@ -1,4 +0,0 @@
|
||||
# Ignore everything in this directory
|
||||
*
|
||||
# Except this file
|
||||
!.gitignore
|
||||
19
bench/mem
19
bench/mem
@@ -1,19 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "usage: $0 <program>"
|
||||
fi
|
||||
|
||||
PROG=$1
|
||||
|
||||
if [ ! -x "$PROG" ]; then
|
||||
echo $PROG not found or not executable.
|
||||
exit 1
|
||||
fi
|
||||
|
||||
$* &
|
||||
PID=$!
|
||||
|
||||
while `kill -0 $PID 2>/dev/null`; do
|
||||
ps -eo size,pid,user,pcpu,command --sort -size | awk '{ line=1 ; hr=$1/1024 ; printf("%13.2f Mb ",hr); } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }' | grep -v grep | grep -v $0 | grep $PROG
|
||||
done
|
||||
@@ -1,77 +0,0 @@
|
||||
//
|
||||
// Copyright(c) 2015 Gabi Melman.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "spdlog/async.h"
|
||||
#include "spdlog/sinks/basic_file_sink.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
using namespace std::chrono;
|
||||
using clock = steady_clock;
|
||||
|
||||
int thread_count = 10;
|
||||
if (argc > 1)
|
||||
thread_count = std::atoi(argv[1]);
|
||||
|
||||
int howmany = 1000000;
|
||||
spdlog::init_thread_pool(howmany, 1);
|
||||
|
||||
auto logger = spdlog::create_async_logger<spdlog::sinks::basic_file_sink_mt>("file_logger", "logs/spdlog-bench-async.log", false);
|
||||
logger->set_pattern("[%Y-%m-%d %T.%F]: %L %t %v");
|
||||
|
||||
std::cout << "To stop, press <Enter>" << std::endl;
|
||||
std::atomic<bool> run{true};
|
||||
std::thread stoper(std::thread([&run]() {
|
||||
std::cin.get();
|
||||
run = false;
|
||||
}));
|
||||
|
||||
while (run)
|
||||
{
|
||||
std::atomic<int> msg_counter{0};
|
||||
std::vector<std::thread> threads;
|
||||
|
||||
auto start = clock::now();
|
||||
for (int t = 0; t < thread_count; ++t)
|
||||
{
|
||||
threads.push_back(std::thread([&]() {
|
||||
while (true)
|
||||
{
|
||||
int counter = ++msg_counter;
|
||||
if (counter > howmany)
|
||||
break;
|
||||
logger->info("spdlog message #{}: This is some text for your pleasure", counter);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
for (auto &t : threads)
|
||||
{
|
||||
t.join();
|
||||
}
|
||||
|
||||
duration<float> delta = clock::now() - start;
|
||||
float deltaf = delta.count();
|
||||
auto rate = howmany / deltaf;
|
||||
|
||||
std::cout << "Total: " << howmany << std::endl;
|
||||
std::cout << "Threads: " << thread_count << std::endl;
|
||||
std::cout << "Delta = " << std::fixed << deltaf << " seconds" << std::endl;
|
||||
std::cout << "Rate = " << std::fixed << rate << "/sec" << std::endl;
|
||||
} // while
|
||||
|
||||
stoper.join();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -11,9 +11,8 @@
|
||||
|
||||
namespace utils {
|
||||
|
||||
template<typename T>
|
||||
inline std::string format(const T &value)
|
||||
{
|
||||
template <typename T>
|
||||
inline std::string format(const T &value) {
|
||||
static std::locale loc("");
|
||||
std::stringstream ss;
|
||||
ss.imbue(loc);
|
||||
@@ -21,9 +20,8 @@ inline std::string format(const T &value)
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline std::string format(const double &value)
|
||||
{
|
||||
template <>
|
||||
inline std::string format(const double &value) {
|
||||
static std::locale loc("");
|
||||
std::stringstream ss;
|
||||
ss.imbue(loc);
|
||||
@@ -31,4 +29,4 @@ inline std::string format(const double &value)
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
} // namespace utils
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
#!/bin/bash
|
||||
clang-tidy example/example.cpp -- -I ./include
|
||||
@@ -1,24 +0,0 @@
|
||||
# *************************************************************************/
|
||||
# * Copyright (c) 2015 Ruslan Baratov. */
|
||||
# * */
|
||||
# * Permission is hereby granted, free of charge, to any person obtaining */
|
||||
# * a copy of this software and associated documentation files (the */
|
||||
# * "Software"), to deal in the Software without restriction, including */
|
||||
# * without limitation the rights to use, copy, modify, merge, publish, */
|
||||
# * distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
# * permit persons to whom the Software is furnished to do so, subject to */
|
||||
# * the following conditions: */
|
||||
# * */
|
||||
# * The above copyright notice and this permission notice shall be */
|
||||
# * included in all copies or substantial portions of the Software. */
|
||||
# * */
|
||||
# * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
# * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
# * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
# * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
# * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
# * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
# * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
# *************************************************************************/
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake")
|
||||
15
cmake/fmtlib.cmake
Normal file
15
cmake/fmtlib.cmake
Normal file
@@ -0,0 +1,15 @@
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
fmt
|
||||
DOWNLOAD_EXTRACT_TIMESTAMP FALSE
|
||||
URL https://github.com/fmtlib/fmt/archive/refs/tags/11.0.2.tar.gz
|
||||
URL_HASH SHA256=6cb1e6d37bdcb756dbbe59be438790db409cdb4868c66e888d5df9f13f7c027f)
|
||||
|
||||
FetchContent_GetProperties(fmt)
|
||||
if(NOT fmt_POPULATED)
|
||||
# We do not require os features of fmt
|
||||
set(FMT_OS OFF CACHE BOOL "Disable FMT_OS" FORCE)
|
||||
FetchContent_MakeAvailable(fmt)
|
||||
set_target_properties(fmt PROPERTIES FOLDER "third-party")
|
||||
endif()
|
||||
18
cmake/ide.cmake
Normal file
18
cmake/ide.cmake
Normal file
@@ -0,0 +1,18 @@
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# IDE support for headers
|
||||
# ---------------------------------------------------------------------------------------
|
||||
set(SPDLOG_HEADERS_DIR "${CMAKE_CURRENT_LIST_DIR}/../include")
|
||||
|
||||
file(GLOB SPDLOG_TOP_HEADERS "${SPDLOG_HEADERS_DIR}/spdlog/*.h")
|
||||
file(GLOB SPDLOG_DETAILS_HEADERS "${SPDLOG_HEADERS_DIR}/spdlog/details/*.h")
|
||||
file(GLOB SPDLOG_SINKS_HEADERS "${SPDLOG_HEADERS_DIR}/spdlog/sinks/*.h")
|
||||
file(GLOB SPDLOG_FMT_HEADERS "${SPDLOG_HEADERS_DIR}/spdlog/fmt/*.h")
|
||||
file(GLOB SPDLOG_FMT_BUNDELED_HEADERS "${SPDLOG_HEADERS_DIR}/spdlog/fmt/bundled/*.h")
|
||||
set(SPDLOG_ALL_HEADERS ${SPDLOG_TOP_HEADERS} ${SPDLOG_DETAILS_HEADERS} ${SPDLOG_SINKS_HEADERS} ${SPDLOG_FMT_HEADERS}
|
||||
${SPDLOG_FMT_BUNDELED_HEADERS})
|
||||
|
||||
source_group("Header Files\\spdlog" FILES ${SPDLOG_TOP_HEADERS})
|
||||
source_group("Header Files\\spdlog\\details" FILES ${SPDLOG_DETAILS_HEADERS})
|
||||
source_group("Header Files\\spdlog\\sinks" FILES ${SPDLOG_SINKS_HEADERS})
|
||||
source_group("Header Files\\spdlog\\fmt" FILES ${SPDLOG_FMT_HEADERS})
|
||||
source_group("Header Files\\spdlog\\fmt\\bundled\\" FILES ${SPDLOG_FMT_BUNDELED_HEADERS})
|
||||
@@ -1,21 +0,0 @@
|
||||
if(SPDLOG_SANITIZE_THREAD AND SPDLOG_SANITIZE_ADDRESS)
|
||||
message(FATAL_ERROR "AddressSanitizer is not compatible with ThreadSanitizer.")
|
||||
endif()
|
||||
|
||||
if(SPDLOG_SANITIZE_ADDRESS)
|
||||
message(STATUS "AddressSanitizer enabled")
|
||||
set(SANITIZER_FLAGS "-fsanitize=address,undefined")
|
||||
add_compile_options("-fno-sanitize=signed-integer-overflow")
|
||||
endif()
|
||||
|
||||
if(SPDLOG_SANITIZE_THREAD)
|
||||
message(STATUS "ThreadSanitizer enabled")
|
||||
set(SANITIZER_FLAGS "-fsanitize=thread")
|
||||
endif()
|
||||
|
||||
if(SPDLOG_SANITIZE_THREAD OR SPDLOG_SANITIZE_ADDRESS)
|
||||
add_compile_options(${SANITIZER_FLAGS})
|
||||
add_compile_options("-fno-sanitize-recover=all")
|
||||
add_compile_options("-fno-omit-frame-pointer")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAGS} -fuse-ld=gold")
|
||||
endif()
|
||||
@@ -1,6 +0,0 @@
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
includedir=${prefix}/include
|
||||
|
||||
Name: @PROJECT_NAME@
|
||||
Description: Super fast C++ logging library.
|
||||
Version: @PROJECT_VERSION@
|
||||
60
cmake/spdlogCPack.cmake
Normal file
60
cmake/spdlogCPack.cmake
Normal file
@@ -0,0 +1,60 @@
|
||||
set(CPACK_GENERATOR "TGZ;ZIP" CACHE STRING "Semicolon separated list of generators")
|
||||
|
||||
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
|
||||
set(CPACK_INSTALL_CMAKE_PROJECTS "${CMAKE_BINARY_DIR}" "${PROJECT_NAME}" ALL .)
|
||||
|
||||
set(CPACK_PROJECT_URL "https://github.com/gabime/spdlog")
|
||||
set(CPACK_PACKAGE_VENDOR "Gabi Melman")
|
||||
set(CPACK_PACKAGE_CONTACT "Gabi Melman <gmelman1@gmail.com>")
|
||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Fast C++ logging library")
|
||||
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
|
||||
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
|
||||
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
|
||||
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
|
||||
if(PROJECT_VERSION_TWEAK)
|
||||
set(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}.${PROJECT_VERSION_TWEAK})
|
||||
endif()
|
||||
set(CPACK_PACKAGE_RELOCATABLE ON CACHE BOOL "Build relocatable package")
|
||||
|
||||
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
|
||||
set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
|
||||
set(CPACK_DEBIAN_PACKAGE_SECTION "libs")
|
||||
set(CPACK_RPM_PACKAGE_URL ${CPACK_PROJECT_URL})
|
||||
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${CPACK_PROJECT_URL})
|
||||
set(CPACK_RPM_PACKAGE_DESCRIPTION "Fast C++ logging library.")
|
||||
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "FastC++ logging library.")
|
||||
|
||||
if(CPACK_PACKAGE_NAME)
|
||||
set(CPACK_RPM_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
|
||||
set(CPACK_DEBIAN_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
|
||||
else()
|
||||
set(CPACK_RPM_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}")
|
||||
set(CPACK_DEBIAN_FILE_NAME "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}")
|
||||
set(CPACK_RPM_PACKAGE_NAME "${PROJECT_NAME}")
|
||||
set(CPACK_DEBIAN_PACKAGE_NAME "${PROJECT_NAME}")
|
||||
endif()
|
||||
|
||||
if(CPACK_RPM_PACKAGE_RELEASE)
|
||||
set(CPACK_RPM_FILE_NAME "${CPACK_RPM_FILE_NAME}-${CPACK_RPM_PACKAGE_RELEASE}")
|
||||
endif()
|
||||
if(CPACK_DEBIAN_PACKAGE_RELEASE)
|
||||
set(CPACK_DEBIAN_FILE_NAME "${CPACK_DEBIAN_FILE_NAME}-${CPACK_DEBIAN_PACKAGE_RELEASE}")
|
||||
endif()
|
||||
|
||||
if(CPACK_RPM_PACKAGE_ARCHITECTURE)
|
||||
set(CPACK_RPM_FILE_NAME "${CPACK_RPM_FILE_NAME}.${CPACK_RPM_PACKAGE_ARCHITECTURE}")
|
||||
endif()
|
||||
if(CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
|
||||
set(CPACK_DEBIAN_FILE_NAME "${CPACK_DEBIAN_FILE_NAME}.${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
|
||||
endif()
|
||||
set(CPACK_RPM_FILE_NAME "${CPACK_RPM_FILE_NAME}.rpm")
|
||||
set(CPACK_DEBIAN_FILE_NAME "${CPACK_DEBIAN_FILE_NAME}.deb")
|
||||
|
||||
if(NOT CPACK_PACKAGE_RELOCATABLE)
|
||||
# Depend on pkgconfig rpm to create the system pkgconfig folder
|
||||
set(CPACK_RPM_PACKAGE_REQUIRES pkgconfig)
|
||||
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
|
||||
"${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
||||
endif()
|
||||
|
||||
include(CPack)
|
||||
15
cmake/spdlogConfig.cmake.in
Normal file
15
cmake/spdlogConfig.cmake.in
Normal file
@@ -0,0 +1,15 @@
|
||||
# Copyright(c) 2019 spdlog authors
|
||||
# Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include(CMakeFindDependencyMacro)
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
find_dependency(fmt 11 CONFIG)
|
||||
|
||||
set(config_targets_file @config_targets_file@)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/${config_targets_file}")
|
||||
|
||||
check_required_components(spdlog)
|
||||
73
cmake/utils.cmake
Normal file
73
cmake/utils.cmake
Normal file
@@ -0,0 +1,73 @@
|
||||
# Get spdlog version from include/spdlog/version.h and put it in SPDLOG_VERSION
|
||||
function(spdlog_extract_version)
|
||||
file(READ "${CMAKE_CURRENT_LIST_DIR}/include/spdlog/version.h" file_contents)
|
||||
string(REGEX MATCH "SPDLOG_VER_MAJOR ([0-9]+)" _ "${file_contents}")
|
||||
if(NOT CMAKE_MATCH_COUNT EQUAL 1)
|
||||
message(FATAL_ERROR "Could not extract major version number from spdlog/version.h")
|
||||
endif()
|
||||
set(ver_major ${CMAKE_MATCH_1})
|
||||
|
||||
string(REGEX MATCH "SPDLOG_VER_MINOR ([0-9]+)" _ "${file_contents}")
|
||||
if(NOT CMAKE_MATCH_COUNT EQUAL 1)
|
||||
message(FATAL_ERROR "Could not extract minor version number from spdlog/version.h")
|
||||
endif()
|
||||
|
||||
set(ver_minor ${CMAKE_MATCH_1})
|
||||
string(REGEX MATCH "SPDLOG_VER_PATCH ([0-9]+)" _ "${file_contents}")
|
||||
if(NOT CMAKE_MATCH_COUNT EQUAL 1)
|
||||
message(FATAL_ERROR "Could not extract patch version number from spdlog/version.h")
|
||||
endif()
|
||||
set(ver_patch ${CMAKE_MATCH_1})
|
||||
|
||||
set(SPDLOG_VERSION_MAJOR ${ver_major} PARENT_SCOPE)
|
||||
set(SPDLOG_VERSION_MINOR ${ver_minor} PARENT_SCOPE)
|
||||
set(SPDLOG_VERSION_PATCH ${ver_patch} PARENT_SCOPE)
|
||||
set(SPDLOG_VERSION "${ver_major}.${ver_minor}.${ver_patch}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Turn on warnings on the given target
|
||||
function(spdlog_enable_warnings target_name)
|
||||
if(SPDLOG_BUILD_WARNINGS)
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
list(APPEND MSVC_OPTIONS "/W3")
|
||||
if(MSVC_VERSION GREATER 1900) # Allow non fatal security warnings for msvc 2015
|
||||
list(APPEND MSVC_OPTIONS "/WX")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_compile_options(
|
||||
${target_name}
|
||||
PRIVATE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wconversion
|
||||
-pedantic
|
||||
-Werror
|
||||
-Wfatal-errors>
|
||||
$<$<CXX_COMPILER_ID:MSVC>:${MSVC_OPTIONS}>)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Enable address sanitizer (gcc/clang only)
|
||||
function(spdlog_enable_addr_sanitizer target_name)
|
||||
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
message(FATAL_ERROR "Sanitizer supported only for gcc/clang")
|
||||
endif()
|
||||
message(STATUS "Address sanitizer enabled")
|
||||
target_compile_options(${target_name} PRIVATE -fsanitize=address,undefined)
|
||||
target_compile_options(${target_name} PRIVATE -fno-sanitize=signed-integer-overflow)
|
||||
target_compile_options(${target_name} PRIVATE -fno-sanitize-recover=all)
|
||||
target_compile_options(${target_name} PRIVATE -fno-omit-frame-pointer)
|
||||
target_link_libraries(${target_name} PRIVATE -fsanitize=address,undefined -fuse-ld=gold)
|
||||
endfunction()
|
||||
|
||||
# Enable thread sanitizer (gcc/clang only)
|
||||
function(spdlog_enable_thread_sanitizer target_name)
|
||||
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
message(FATAL_ERROR "Sanitizer supported only for gcc/clang")
|
||||
endif()
|
||||
message(STATUS "Thread sanitizer enabled")
|
||||
target_compile_options(${target_name} PRIVATE -fsanitize=thread)
|
||||
target_compile_options(${target_name} PRIVATE -fno-omit-frame-pointer)
|
||||
target_link_libraries(${target_name} PRIVATE -fsanitize=thread -fuse-ld=gold)
|
||||
endfunction()
|
||||
42
cmake/version.rc.in
Normal file
42
cmake/version.rc.in
Normal file
@@ -0,0 +1,42 @@
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
#include <windows.h>
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION @SPDLOG_VERSION_MAJOR@,@SPDLOG_VERSION_MINOR@,@SPDLOG_VERSION_PATCH@,0
|
||||
PRODUCTVERSION @SPDLOG_VERSION_MAJOR@,@SPDLOG_VERSION_MINOR@,@SPDLOG_VERSION_PATCH@,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x40004L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "FileDescription", "spdlog dll\0"
|
||||
VALUE "FileVersion", "@SPDLOG_VERSION@.0\0"
|
||||
VALUE "InternalName", "spdlog.dll\0"
|
||||
VALUE "LegalCopyright", "Copyright (C) spdlog\0"
|
||||
VALUE "ProductName", "spdlog\0"
|
||||
VALUE "ProductVersion", "@SPDLOG_VERSION@.0\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
463
docs/index.md
Normal file
463
docs/index.md
Normal file
@@ -0,0 +1,463 @@
|
||||
|
||||
# spdlog
|
||||
|
||||
|
||||
[](https://github.com/gabime/spdlog/actions/workflows/linux.yml)
|
||||
[](https://github.com/gabime/spdlog/actions/workflows/windows.yml)
|
||||
[](https://github.com/gabime/spdlog/actions/workflows/macos.yml)
|
||||
[](https://github.com/gabime/spdlog/releases/latest)
|
||||
|
||||
Fast C++ logging library
|
||||
|
||||
## Install
|
||||
```console
|
||||
$ git clone https://github.com/gabime/spdlog.git
|
||||
$ cd spdlog && mkdir build && cd build
|
||||
$ cmake .. && cmake --build .
|
||||
```
|
||||
|
||||
see example [CMakeLists.txt](https://github.com/gabime/spdlog/blob/v2.x/example/CMakeLists.txt) on how to use.
|
||||
|
||||
## Platforms
|
||||
* Linux, FreeBSD, OpenBSD, Solaris, AIX
|
||||
* Windows (msvc, cygwin)
|
||||
* macOS
|
||||
* Android
|
||||
|
||||
## Package managers:
|
||||
* Debian: `sudo apt install libspdlog-dev`
|
||||
* Homebrew: `brew install spdlog`
|
||||
* MacPorts: `sudo port install spdlog`
|
||||
* FreeBSD: `pkg install spdlog`
|
||||
* Fedora: `dnf install spdlog`
|
||||
* Gentoo: `emerge dev-libs/spdlog`
|
||||
* Arch Linux: `pacman -S spdlog`
|
||||
* openSUSE: `sudo zypper in spdlog-devel`
|
||||
* vcpkg: `vcpkg install spdlog`
|
||||
* conan: `conan install --requires=spdlog/[*]`
|
||||
* conda: `conda install -c conda-forge spdlog`
|
||||
* build2: ```depends: spdlog ^1.8.2```
|
||||
|
||||
|
||||
## Features
|
||||
* Very fast (see [benchmarks](#benchmarks) below).
|
||||
* Headers only or compiled
|
||||
* Feature-rich formatting, using the excellent [fmt](https://github.com/fmtlib/fmt) library.
|
||||
* Asynchronous mode (optional)
|
||||
* [Custom](https://github.com/gabime/spdlog/wiki/3.-Custom-formatting) formatting.
|
||||
* Multi/Single threaded loggers.
|
||||
* Various log targets:
|
||||
* Rotating log files.
|
||||
* Daily log files.
|
||||
* Console logging (colors supported).
|
||||
* syslog.
|
||||
* Windows event log.
|
||||
* Windows debugger (```OutputDebugString(..)```).
|
||||
* Log to Qt widgets ([example](#log-to-qt-with-nice-colors)).
|
||||
* Easily [extendable](https://github.com/gabime/spdlog/wiki/4.-Sinks#implementing-your-own-sink) with custom log targets.
|
||||
* Log filtering - log levels can be modified at runtime as well as compile time.
|
||||
* Support for loading log levels from argv or environment var.
|
||||
|
||||
## Usage samples
|
||||
|
||||
#### Basic usage
|
||||
```c++
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
spdlog::info("Welcome to spdlog!");
|
||||
spdlog::error("Some error message with arg: {}", 1);
|
||||
|
||||
spdlog::warn("Easy padding in numbers like {:08d}", 12);
|
||||
spdlog::critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
|
||||
spdlog::info("Support for floats {:03.2f}", 1.23456);
|
||||
spdlog::info("Positional args are {1} {0}..", "too", "supported");
|
||||
spdlog::info("{:<30}", "left aligned");
|
||||
|
||||
spdlog::set_level(spdlog::level::debug); // Set global log level to debug
|
||||
spdlog::debug("This message should be displayed..");
|
||||
|
||||
// change log pattern
|
||||
spdlog::set_pattern("[%H:%M:%S %z] [%n] [%^---%L---%$] [thread %t] %v");
|
||||
|
||||
// Compile time log levels
|
||||
// define SPDLOG_ACTIVE_LEVEL to desired level
|
||||
SPDLOG_TRACE("Some trace message with param {}", 42);
|
||||
SPDLOG_DEBUG("Some debug message");
|
||||
}
|
||||
|
||||
```
|
||||
---
|
||||
#### Create stdout/stderr logger object
|
||||
```c++
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||
void stdout_example()
|
||||
{
|
||||
// create a color multi-threaded logger
|
||||
auto console = spdlog::stdout_color_mt("console");
|
||||
auto err_logger = spdlog::stderr_color_mt("stderr");
|
||||
spdlog::get("console")->info("loggers can be retrieved from a global registry using the spdlog::get(logger_name)");
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
#### Basic file logger
|
||||
```c++
|
||||
#include "spdlog/sinks/basic_file_sink.h"
|
||||
void basic_logfile_example()
|
||||
{
|
||||
try
|
||||
{
|
||||
auto logger = spdlog::basic_logger_mt("basic_logger", "logs/basic-log.txt");
|
||||
}
|
||||
catch (const spdlog::spdlog_ex &ex)
|
||||
{
|
||||
std::cout << "Log init failed: " << ex.what() << std::endl;
|
||||
}
|
||||
}
|
||||
```
|
||||
---
|
||||
#### Rotating files
|
||||
```c++
|
||||
#include "spdlog/sinks/rotating_file_sink.h"
|
||||
void rotating_example()
|
||||
{
|
||||
// Create a file rotating logger with 5 MB size max and 3 rotated files
|
||||
auto max_size = 1048576 * 5;
|
||||
auto max_files = 3;
|
||||
auto logger = spdlog::rotating_logger_mt("some_logger_name", "logs/rotating.txt", max_size, max_files);
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
#### Daily files
|
||||
```c++
|
||||
|
||||
#include "spdlog/sinks/daily_file_sink.h"
|
||||
void daily_example()
|
||||
{
|
||||
// Create a daily logger - a new file is created every day at 2:30 am
|
||||
auto logger = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
---
|
||||
#### Periodic flush
|
||||
```c++
|
||||
// periodically flush all *registered* loggers every 3 seconds:
|
||||
// warning: only use if all your loggers are thread-safe ("_mt" loggers)
|
||||
spdlog::flush_every(std::chrono::seconds(3));
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
#### Stopwatch
|
||||
```c++
|
||||
// Stopwatch support for spdlog
|
||||
#include "spdlog/stopwatch.h"
|
||||
void stopwatch_example()
|
||||
{
|
||||
spdlog::stopwatch sw;
|
||||
spdlog::debug("Elapsed {}", sw);
|
||||
spdlog::debug("Elapsed {:.3}", sw);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
#### Log binary data in hex
|
||||
```c++
|
||||
// many types of std::container<char> types can be used.
|
||||
// ranges are supported too.
|
||||
// format flags:
|
||||
// {:X} - print in uppercase.
|
||||
// {:s} - don't separate each byte with space.
|
||||
// {:p} - don't print the position on each line start.
|
||||
// {:n} - don't split the output into lines.
|
||||
// {:a} - show ASCII if :n is not set.
|
||||
|
||||
#include "spdlog/fmt/bin_to_hex.h"
|
||||
|
||||
void binary_example()
|
||||
{
|
||||
auto console = spdlog::get("console");
|
||||
std::array<char, 80> buf;
|
||||
console->info("Binary example: {}", spdlog::to_hex(buf));
|
||||
console->info("Another binary example:{:n}", spdlog::to_hex(std::begin(buf), std::begin(buf) + 10));
|
||||
// more examples:
|
||||
// logger->info("uppercase: {:X}", spdlog::to_hex(buf));
|
||||
// logger->info("uppercase, no delimiters: {:Xs}", spdlog::to_hex(buf));
|
||||
// logger->info("uppercase, no delimiters, no position info: {:Xsp}", spdlog::to_hex(buf));
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
#### Logger with multi sinks - each with a different format and log level
|
||||
```c++
|
||||
|
||||
// create a logger with 2 targets, with different log levels and formats.
|
||||
// The console will show only warnings or errors, while the file will log all.
|
||||
void multi_sink_example()
|
||||
{
|
||||
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
||||
console_sink->set_level(spdlog::level::warn);
|
||||
console_sink->set_pattern("[multi_sink_example] [%^%l%$] %v");
|
||||
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/multisink.txt", true);
|
||||
file_sink->set_level(spdlog::level::trace);
|
||||
|
||||
spdlog::logger logger("multi_sink", {console_sink, file_sink});
|
||||
logger.set_level(spdlog::level::debug);
|
||||
logger.warn("this should appear in both console and file");
|
||||
logger.info("this message should not appear in the console, only in the file");
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
#### User-defined callbacks about log events
|
||||
```c++
|
||||
|
||||
// create a logger with a lambda function callback, the callback will be called
|
||||
// each time something is logged to the logger
|
||||
void callback_example()
|
||||
{
|
||||
auto callback_sink = std::make_shared<spdlog::sinks::callback_sink_mt>([](const spdlog::details::log_msg &msg) {
|
||||
// for example you can be notified by sending an email to yourself
|
||||
});
|
||||
callback_sink->set_level(spdlog::level::err);
|
||||
|
||||
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
||||
spdlog::logger logger("custom_callback_logger", {console_sink, callback_sink});
|
||||
|
||||
logger.info("some info log");
|
||||
logger.error("critical issue"); // will notify you
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
#### Asynchronous logging
|
||||
```c++
|
||||
#include "spdlog/async.h"
|
||||
#include "spdlog/sinks/basic_file_sink.h"
|
||||
void async_example()
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
#### User-defined types
|
||||
```c++
|
||||
template<>
|
||||
struct fmt::formatter<my_type> : fmt::formatter<std::string>
|
||||
{
|
||||
auto format(my_type my, format_context &ctx) const -> decltype(ctx.out())
|
||||
{
|
||||
return format_to(ctx.out(), "[my_type i={}]", my.i);
|
||||
}
|
||||
};
|
||||
|
||||
void user_defined_example()
|
||||
{
|
||||
spdlog::info("user defined type: {}", my_type(14));
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
#### User-defined flags in the log pattern
|
||||
```c++
|
||||
// Log patterns can contain custom flags.
|
||||
// the following example will add new flag '%*' - which will be bound to a <my_formatter_flag> instance.
|
||||
#include "spdlog/pattern_formatter.h"
|
||||
class my_formatter_flag : public spdlog::custom_flag_formatter
|
||||
{
|
||||
public:
|
||||
void format(const spdlog::details::log_msg &, const std::tm &, spdlog::memory_buf_t &dest) override
|
||||
{
|
||||
std::string some_txt = "custom-flag";
|
||||
dest.append(some_txt.data(), some_txt.data() + some_txt.size());
|
||||
}
|
||||
|
||||
std::unique_ptr<custom_flag_formatter> clone() const override
|
||||
{
|
||||
return std::make_unique<my_formatter_flag>();
|
||||
}
|
||||
};
|
||||
|
||||
void custom_flags_example()
|
||||
{
|
||||
auto formatter = std::make_unique<spdlog::pattern_formatter>();
|
||||
formatter->add_flag<my_formatter_flag>('*').set_pattern("[%n] [%*] [%^%l%$] %v");
|
||||
spdlog::set_formatter(std::move(formatter));
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
#### Custom error handler
|
||||
```c++
|
||||
void err_handler_example()
|
||||
{
|
||||
// can be set globally or per logger(logger->set_error_handler(..))
|
||||
spdlog::set_error_handler([](const std::string &msg) { spdlog::get("console")->error("*** LOGGER ERROR ***: {}", msg); });
|
||||
spdlog::get("console")->info("some invalid message to trigger an error {}{}{}{}", 3);
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
#### syslog
|
||||
```c++
|
||||
#include "spdlog/sinks/syslog_sink.h"
|
||||
void syslog_example()
|
||||
{
|
||||
std::string ident = "spdlog-example";
|
||||
auto syslog_logger = spdlog::syslog_logger_mt("syslog", ident, LOG_PID);
|
||||
syslog_logger->warn("This is warning that will end up in syslog.");
|
||||
}
|
||||
```
|
||||
---
|
||||
#### Android example
|
||||
```c++
|
||||
#include "spdlog/sinks/android_sink.h"
|
||||
void android_example()
|
||||
{
|
||||
std::string tag = "spdlog-android";
|
||||
auto android_logger = spdlog::android_logger_mt("android", tag);
|
||||
android_logger->critical("Use \"adb shell logcat\" to view this message.");
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
#### Load log levels from the env variable or argv
|
||||
|
||||
```c++
|
||||
#include "spdlog/cfg/env.h"
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
spdlog::cfg::load_env_levels();
|
||||
// or from the command line:
|
||||
// ./example SPDLOG_LEVEL=info,mylogger=trace
|
||||
// #include "spdlog/cfg/argv.h" // for loading levels from argv
|
||||
// spdlog::cfg::load_argv_levels(argc, argv);
|
||||
}
|
||||
```
|
||||
So then you can:
|
||||
|
||||
```console
|
||||
$ export SPDLOG_LEVEL=info,mylogger=trace
|
||||
$ ./example
|
||||
```
|
||||
|
||||
|
||||
---
|
||||
#### Log file open/close event handlers
|
||||
```c++
|
||||
// You can get callbacks from spdlog before/after a log file has been opened or closed.
|
||||
// This is useful for cleanup procedures or for adding something to the start/end of the log file.
|
||||
void file_events_example()
|
||||
{
|
||||
// pass the spdlog::file_event_handlers to file sinks for open/close log file notifications
|
||||
spdlog::file_event_handlers handlers;
|
||||
handlers.before_open = [](spdlog::filename_t filename) { spdlog::info("Before opening {}", filename); };
|
||||
handlers.after_open = [](spdlog::filename_t filename, std::FILE *fstream) { fputs("After opening\n", fstream); };
|
||||
handlers.before_close = [](spdlog::filename_t filename, std::FILE *fstream) { fputs("Before closing\n", fstream); };
|
||||
handlers.after_close = [](spdlog::filename_t filename) { spdlog::info("After closing {}", filename); };
|
||||
auto my_logger = spdlog::basic_logger_st("some_logger", "logs/events-sample.txt", true, handlers);
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
#### Replace the Default Logger
|
||||
```c++
|
||||
void replace_global_logger_example()
|
||||
{
|
||||
auto new_logger = spdlog::basic_logger_mt("new_global_logger", "logs/new-default-log.txt", true);
|
||||
spdlog::set_global_logger(new_logger);
|
||||
spdlog::info("new logger log message");
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
#### Log to Qt with nice colors
|
||||
```c++
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "spdlog/sinks/qt_sinks.h"
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
||||
{
|
||||
setMinimumSize(640, 480);
|
||||
auto log_widget = new QTextEdit(this);
|
||||
setCentralWidget(log_widget);
|
||||
int max_lines = 500; // keep the text widget to max 500 lines. remove old lines if needed.
|
||||
auto logger = spdlog::qt_color_logger_mt("qt_logger", log_widget, max_lines);
|
||||
logger->info("Some info message");
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
## Benchmarks
|
||||
|
||||
Below are some [benchmarks](https://github.com/gabime/spdlog/blob/v2.x/bench/bench.cpp) done in Ubuntu 64 bit, Intel i7-4770 CPU @ 3.40GHz
|
||||
|
||||
#### Synchronous mode
|
||||
```
|
||||
[info] **************************************************************
|
||||
[info] Single thread, 1,000,000 iterations
|
||||
[info] **************************************************************
|
||||
[info] basic_st Elapsed: 0.17 secs 5,777,626/sec
|
||||
[info] rotating_st Elapsed: 0.18 secs 5,475,894/sec
|
||||
[info] daily_st Elapsed: 0.20 secs 5,062,659/sec
|
||||
[info] empty_logger Elapsed: 0.07 secs 14,127,300/sec
|
||||
[info] **************************************************************
|
||||
[info] C-string (400 bytes). Single thread, 1,000,000 iterations
|
||||
[info] **************************************************************
|
||||
[info] basic_st Elapsed: 0.41 secs 2,412,483/sec
|
||||
[info] rotating_st Elapsed: 0.72 secs 1,389,196/sec
|
||||
[info] daily_st Elapsed: 0.42 secs 2,393,298/sec
|
||||
[info] null_st Elapsed: 0.04 secs 27,446,957/sec
|
||||
[info] **************************************************************
|
||||
[info] 10 threads, competing over the same logger object, 1,000,000 iterations
|
||||
[info] **************************************************************
|
||||
[info] basic_mt Elapsed: 0.60 secs 1,659,613/sec
|
||||
[info] rotating_mt Elapsed: 0.62 secs 1,612,493/sec
|
||||
[info] daily_mt Elapsed: 0.61 secs 1,638,305/sec
|
||||
[info] null_mt Elapsed: 0.16 secs 6,272,758/sec
|
||||
```
|
||||
#### Asynchronous mode
|
||||
```
|
||||
[info] -------------------------------------------------
|
||||
[info] Messages : 1,000,000
|
||||
[info] Threads : 10
|
||||
[info] Queue : 8,192 slots
|
||||
[info] Queue memory : 8,192 x 272 = 2,176 KB
|
||||
[info] -------------------------------------------------
|
||||
[info]
|
||||
[info] *********************************
|
||||
[info] Queue Overflow Policy: block
|
||||
[info] *********************************
|
||||
[info] Elapsed: 1.70784 secs 585,535/sec
|
||||
[info] Elapsed: 1.69805 secs 588,910/sec
|
||||
[info] Elapsed: 1.7026 secs 587,337/sec
|
||||
[info]
|
||||
[info] *********************************
|
||||
[info] Queue Overflow Policy: overrun
|
||||
[info] *********************************
|
||||
[info] Elapsed: 0.372816 secs 2,682,285/sec
|
||||
[info] Elapsed: 0.379758 secs 2,633,255/sec
|
||||
[info] Elapsed: 0.373532 secs 2,677,147/sec
|
||||
|
||||
```
|
||||
|
||||
## Documentation
|
||||
Documentation can be found in the [wiki](https://github.com/gabime/spdlog/wiki/1.-QuickStart) pages.
|
||||
|
||||
---
|
||||
|
||||
Thanks to [JetBrains](https://www.jetbrains.com/?from=spdlog) for donating product licenses to help develop **spdlog** <a href="https://www.jetbrains.com/?from=spdlog"><img src="logos/jetbrains-variant-4.svg" width="94" align="center" /></a>
|
||||
8
docs/mkdocs.yml
Normal file
8
docs/mkdocs.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
docs_dir: .
|
||||
site_name: spdlog
|
||||
nav:
|
||||
- Home: index.md
|
||||
theme:
|
||||
name: mkdocs
|
||||
color_mode: dark
|
||||
|
||||
@@ -1,49 +1,12 @@
|
||||
# *************************************************************************/
|
||||
# * Copyright (c) 2015 Ruslan Baratov. */
|
||||
# * */
|
||||
# * Permission is hereby granted, free of charge, to any person obtaining */
|
||||
# * a copy of this software and associated documentation files (the */
|
||||
# * "Software"), to deal in the Software without restriction, including */
|
||||
# * without limitation the rights to use, copy, modify, merge, publish, */
|
||||
# * distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
# * permit persons to whom the Software is furnished to do so, subject to */
|
||||
# * the following conditions: */
|
||||
# * */
|
||||
# * The above copyright notice and this permission notice shall be */
|
||||
# * included in all copies or substantial portions of the Software. */
|
||||
# * */
|
||||
# * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
# * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
# * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
# * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
# * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
# * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
# * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
# *************************************************************************/
|
||||
# Copyright(c) 2019 spdlog authors Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(SpdlogExamples CXX)
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
project(spdlog_example CXX)
|
||||
|
||||
if(NOT TARGET spdlog)
|
||||
# Stand-alone build
|
||||
find_package(spdlog CONFIG REQUIRED)
|
||||
# Stand-alone build
|
||||
find_package(spdlog 2 REQUIRED)
|
||||
endif()
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
add_executable(example example.cpp)
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
|
||||
find_library(log-lib log)
|
||||
target_link_libraries(example spdlog::spdlog Threads::Threads log)
|
||||
else()
|
||||
target_link_libraries(example spdlog::spdlog Threads::Threads)
|
||||
endif()
|
||||
|
||||
|
||||
add_executable(multisink multisink.cpp)
|
||||
target_link_libraries(multisink spdlog::spdlog Threads::Threads)
|
||||
|
||||
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/logs")
|
||||
|
||||
enable_testing()
|
||||
add_test(NAME example COMMAND example)
|
||||
target_link_libraries(example PRIVATE spdlog::spdlog $<$<BOOL:${MINGW}>:ws2_32>)
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
CXX ?= g++
|
||||
CXX_FLAGS = -Wall -Wextra -pedantic -std=c++11 -pthread -I../include -fmax-errors=1 -Wconversion
|
||||
CXX_RELEASE_FLAGS = -O3 -march=native
|
||||
CXX_DEBUG_FLAGS= -g
|
||||
|
||||
all: example
|
||||
debug: example-debug
|
||||
|
||||
example: example.cpp
|
||||
$(CXX) example.cpp -o example $(CXX_FLAGS) $(CXX_RELEASE_FLAGS) $(CXXFLAGS)
|
||||
|
||||
|
||||
example-debug: example.cpp
|
||||
$(CXX) example.cpp -o example-debug $(CXX_FLAGS) $(CXX_DEBUG_FLAGS) $(CXXFLAGS)
|
||||
|
||||
clean:
|
||||
rm -f *.o logs/*.txt example example-debug
|
||||
|
||||
|
||||
rebuild: clean all
|
||||
rebuild-debug: clean debug
|
||||
@@ -1,22 +0,0 @@
|
||||
#-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded
|
||||
CXX ?= g++
|
||||
CXX_FLAGS = -Wall -Wextra -pedantic -std=c++11 -pthread -I../include -fmax-errors=1 -Wconversion -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-weak-vtables -Wno-global-constructors
|
||||
CXX_RELEASE_FLAGS = -O3 -march=native
|
||||
CXX_DEBUG_FLAGS= -g
|
||||
|
||||
all: example
|
||||
debug: example-debug
|
||||
|
||||
example: example.cpp
|
||||
$(CXX) example.cpp -o example $(CXX_FLAGS) $(CXX_RELEASE_FLAGS) $(CXXFLAGS)
|
||||
|
||||
|
||||
example-debug: example.cpp
|
||||
$(CXX) example.cpp -o example-debug $(CXX_FLAGS) $(CXX_DEBUG_FLAGS) $(CXXFLAGS)
|
||||
|
||||
clean:
|
||||
rm -f *.o logs/*.txt example example-debug
|
||||
|
||||
|
||||
rebuild: clean all
|
||||
rebuild-debug: clean debug
|
||||
@@ -1,26 +0,0 @@
|
||||
CXX = clang++
|
||||
CXXFLAGS = -march=native -Wall -Wextra -Wshadow -pedantic -std=c++11 -pthread -I../include
|
||||
CXX_RELEASE_FLAGS = -O2
|
||||
CXX_DEBUG_FLAGS= -g
|
||||
|
||||
|
||||
all: example
|
||||
debug: example-debug
|
||||
|
||||
example: example.cpp
|
||||
$(CXX) example.cpp -o example-clang $(CXXFLAGS) $(CXX_RELEASE_FLAGS)
|
||||
|
||||
|
||||
|
||||
example-debug: example.cpp
|
||||
$(CXX) example.cpp -o example-clang-debug $(CXXFLAGS) $(CXX_DEBUG_FLAGS)
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o logs/*.txt example-clang example-clang-debug
|
||||
|
||||
|
||||
rebuild: clean all
|
||||
rebuild-debug: clean debug
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
CXX ?= g++
|
||||
CXXFLAGS = -D_WIN32_WINNT=0x600 -march=native -Wall -Wextra -pedantic -std=gnu++0x -pthread -Wl,--no-as-needed -I../include
|
||||
CXX_RELEASE_FLAGS = -O3
|
||||
CXX_DEBUG_FLAGS= -g
|
||||
|
||||
|
||||
all: example
|
||||
debug: example-debug
|
||||
|
||||
example: example.cpp
|
||||
$(CXX) example.cpp -o example $(CXXFLAGS) $(CXX_RELEASE_FLAGS)
|
||||
|
||||
|
||||
example-debug: example.cpp
|
||||
$(CXX) example.cpp -o example-debug $(CXXFLAGS) $(CXX_DEBUG_FLAGS)
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.o logs/*.txt example example-debug
|
||||
|
||||
|
||||
rebuild: clean all
|
||||
rebuild-debug: clean debug
|
||||
|
||||
|
||||
@@ -1,190 +1,198 @@
|
||||
//
|
||||
// Copyright(c) 2015 Gabi Melman.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
//
|
||||
|
||||
// spdlog usage example
|
||||
//
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
|
||||
void stdout_example();
|
||||
void stdout_logger_example();
|
||||
void basic_example();
|
||||
void rotating_example();
|
||||
void daily_example();
|
||||
void callback_example();
|
||||
void async_example();
|
||||
void binary_example();
|
||||
void vector_example();
|
||||
void stopwatch_example();
|
||||
void trace_example();
|
||||
void multi_sink_example();
|
||||
void user_defined_example();
|
||||
void err_handler_example();
|
||||
void syslog_example();
|
||||
void clone_example();
|
||||
void udp_example();
|
||||
void custom_flags_example();
|
||||
void file_events_example();
|
||||
void replace_global_logger_example();
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "spdlog/version.h"
|
||||
|
||||
int main(int, char *[])
|
||||
{
|
||||
using namespace spdlog::sinks;
|
||||
|
||||
try
|
||||
{
|
||||
// console logging example
|
||||
stdout_example();
|
||||
int main(int, char *[]) {
|
||||
spdlog::info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH);
|
||||
spdlog::warn("Easy padding in numbers like {:08d}", 12);
|
||||
spdlog::critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
|
||||
spdlog::info("Support for floats {:03.2f}", 1.23456);
|
||||
spdlog::info("Positional args are {1} {0}..", "too", "supported");
|
||||
spdlog::info("{:>8} aligned, {:<8} aligned", "right", "left");
|
||||
|
||||
// various file loggers
|
||||
// Runtime log levels
|
||||
spdlog::set_level(spdlog::level::info); // Set global log level to info
|
||||
spdlog::debug("This message should not be displayed!");
|
||||
spdlog::set_level(spdlog::level::trace); // Set specific logger's log level
|
||||
spdlog::debug("This message should be displayed..");
|
||||
|
||||
// Customize msg format for all loggers
|
||||
spdlog::set_pattern("[%H:%M:%S %z] [%^%L%$] [thread %t] %v");
|
||||
spdlog::info("This an info message with custom format");
|
||||
spdlog::set_pattern("%+"); // back to default format
|
||||
spdlog::set_level(spdlog::level::info);
|
||||
|
||||
try {
|
||||
stdout_logger_example();
|
||||
basic_example();
|
||||
rotating_example();
|
||||
daily_example();
|
||||
|
||||
clone_example();
|
||||
|
||||
// async logging using a backing thread pool
|
||||
callback_example();
|
||||
async_example();
|
||||
|
||||
// log binary data
|
||||
binary_example();
|
||||
|
||||
// a logger can have multiple targets with different formats
|
||||
vector_example();
|
||||
multi_sink_example();
|
||||
|
||||
// user defined types logging by implementing operator<<
|
||||
user_defined_example();
|
||||
|
||||
// custom error handler
|
||||
err_handler_example();
|
||||
trace_example();
|
||||
stopwatch_example();
|
||||
udp_example();
|
||||
custom_flags_example();
|
||||
file_events_example();
|
||||
replace_global_logger_example();
|
||||
|
||||
// flush all *registered* loggers using a worker thread every 3 seconds.
|
||||
// note: registered loggers *must* be thread safe for this to work correctly!
|
||||
spdlog::flush_every(std::chrono::seconds(3));
|
||||
|
||||
// apply some function on all registered loggers
|
||||
spdlog::apply_all([&](std::shared_ptr<spdlog::logger> l) { l->info("End of example."); });
|
||||
|
||||
// release any threads created by spdlog, and drop all loggers in the registry.
|
||||
// Release all spdlog resources
|
||||
// This is optional (only mandatory if using windows + async log).
|
||||
spdlog::shutdown();
|
||||
}
|
||||
// Exceptions will only be thrown upon failed logger or sink construction (not during logging)
|
||||
catch (const spdlog::spdlog_ex &ex)
|
||||
{
|
||||
std::cout << "Log init failed: " << ex.what() << std::endl;
|
||||
|
||||
// Exceptions will only be thrown upon failed logger or sink construction (not during logging).
|
||||
catch (const spdlog::spdlog_ex &ex) {
|
||||
std::printf("Log initialization failed: %s\n", ex.what());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||
// or #include "spdlog/sinks/stdout_sinks.h" if no colors needed
|
||||
void stdout_example()
|
||||
{
|
||||
// create color multi threaded logger
|
||||
auto console = spdlog::stdout_color_mt("console");
|
||||
console->info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH);
|
||||
console->error("Some error message with arg: {}", 1);
|
||||
|
||||
auto err_logger = spdlog::stderr_color_mt("stderr");
|
||||
err_logger->error("Some error message");
|
||||
|
||||
// Formatting examples
|
||||
console->warn("Easy padding in numbers like {:08d}", 12);
|
||||
console->critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
|
||||
console->info("Support for floats {:03.2f}", 1.23456);
|
||||
console->info("Positional args are {1} {0}..", "too", "supported");
|
||||
console->info("{:<30}", "left aligned");
|
||||
|
||||
spdlog::get("console")->info("loggers can be retrieved from a global registry using the spdlog::get(logger_name)");
|
||||
|
||||
// Runtime log levels
|
||||
spdlog::set_level(spdlog::level::info); // Set global log level to info
|
||||
console->debug("This message should not be displayed!");
|
||||
console->set_level(spdlog::level::trace); // Set specific logger's log level
|
||||
console->debug("This message should be displayed..");
|
||||
|
||||
// Customize msg format for all loggers
|
||||
spdlog::set_pattern("[%H:%M:%S %z] [%n] [%^---%L---%$] [thread %t] %v");
|
||||
console->info("This an info message with custom format");
|
||||
spdlog::set_pattern("%+"); // back to default format
|
||||
|
||||
// Compile time log levels
|
||||
// define SPDLOG_DEBUG_ON or SPDLOG_TRACE_ON
|
||||
SPDLOG_TRACE(console, "Enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}", 1, 3.23);
|
||||
SPDLOG_DEBUG(console, "Enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}", 1, 3.23);
|
||||
// or #include "spdlog/sinks/stdout_sinks.h" if no colors needed.
|
||||
void stdout_logger_example() {
|
||||
// Create color multithreading logger.
|
||||
auto console = spdlog::create<stdout_color_sink_mt>("console");
|
||||
// or for stderr:
|
||||
//auto console = spdlog::create<stderr_color_sink_mt>("console");
|
||||
}
|
||||
|
||||
#include "spdlog/sinks/basic_file_sink.h"
|
||||
void basic_example()
|
||||
{
|
||||
// Create basic file logger (not rotated)
|
||||
auto my_logger = spdlog::basic_logger_mt("basic_logger", "logs/basic-log.txt");
|
||||
void basic_example() {
|
||||
// Create basic file logger (not rotated).
|
||||
auto my_logger = spdlog::create<basic_file_sink_mt>("file_logger", "logs/basic-log.txt", true);
|
||||
}
|
||||
|
||||
#include "spdlog/sinks/rotating_file_sink.h"
|
||||
void rotating_example()
|
||||
{
|
||||
// Create a file rotating logger with 5mb size max and 3 rotated files
|
||||
auto rotating_logger = spdlog::rotating_logger_mt("some_logger_name", "logs/rotating.txt", 1048576 * 5, 3);
|
||||
void rotating_example() {
|
||||
// Create a file rotating logger with 5mb size max and 3 rotated files.
|
||||
auto rotating_logger = spdlog::create<rotating_file_sink_mt>("some_logger_name", "logs/rotating.txt", 1048576 * 5, 3);
|
||||
}
|
||||
|
||||
#include "spdlog/sinks/daily_file_sink.h"
|
||||
void daily_example()
|
||||
{
|
||||
// Create a daily logger - a new file is created every day on 2:30am
|
||||
auto daily_logger = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30);
|
||||
void daily_example() {
|
||||
// Create a daily logger - a new file is created every day on 2:30am.
|
||||
auto daily_logger = spdlog::create<daily_file_format_sink_mt>("daily_logger", "logs/daily.txt", 2, 30);
|
||||
}
|
||||
|
||||
// clone a logger and give it new name.
|
||||
// Useful for creating component/subsystem loggers from some "root" logger
|
||||
void clone_example()
|
||||
{
|
||||
auto network_logger = spdlog::get("console")->clone("network");
|
||||
network_logger->info("Logging network stuff..");
|
||||
#include "spdlog/sinks/callback_sink.h"
|
||||
void callback_example() {
|
||||
// Create the logger
|
||||
auto logger = spdlog::create<callback_sink_mt>("custom_callback_logger", [](const spdlog::details::log_msg & /*msg*/) {
|
||||
// do what you need to do with msg
|
||||
});
|
||||
}
|
||||
|
||||
#include "spdlog/async.h"
|
||||
void async_example()
|
||||
{
|
||||
// default thread pool settings can be modified *before* creating the async logger:
|
||||
// spdlog::init_thread_pool(32768, 1); // queue with max 32k items 1 backing thread.
|
||||
auto async_file = spdlog::basic_logger_mt<spdlog::async_factory>("async_file_logger", "logs/async_log.txt");
|
||||
// alternatively:
|
||||
// auto async_file = spdlog::create_async<spdlog::sinks::basic_file_sink_mt>("async_file_logger", "logs/async_log.txt");
|
||||
|
||||
for (int i = 1; i < 101; ++i)
|
||||
{
|
||||
async_file->info("Async message #{}", i);
|
||||
#include "spdlog/sinks/async_sink.h"
|
||||
void async_example() {
|
||||
using spdlog::sinks::async_sink;
|
||||
auto sink = async_sink::with<basic_file_sink_mt>("logs/async_log.txt", true);
|
||||
auto logger = std::make_shared<spdlog::logger>("async_logger", sink);
|
||||
for (int i = 1; i < 101; ++i) {
|
||||
logger->info("Async message #{}", i);
|
||||
}
|
||||
}
|
||||
|
||||
// log binary data as hex.
|
||||
// many types of std::container<char> types can be used.
|
||||
// ranges are supported too.
|
||||
// format flags:
|
||||
// Log binary data as hex.
|
||||
// Many types of std::container<char> types can be used.
|
||||
// Iterator ranges are supported too.
|
||||
// Format flags:
|
||||
// {:X} - print in uppercase.
|
||||
// {:s} - don't separate each byte with space.
|
||||
// {:p} - don't print the position on each line start.
|
||||
// {:n} - don't split the output to lines.
|
||||
|
||||
#include "spdlog/fmt/bin_to_hex.h"
|
||||
void binary_example()
|
||||
{
|
||||
auto console = spdlog::get("console");
|
||||
std::array<char, 80> buf;
|
||||
console->info("Binary example: {}", spdlog::to_hex(buf));
|
||||
console->info("Another binary example:{:n}", spdlog::to_hex(std::begin(buf), std::begin(buf) + 10));
|
||||
#include "spdlog/bin_to_hex.h"
|
||||
void binary_example() {
|
||||
std::vector<char> buf;
|
||||
for (int i = 0; i < 80; i++) {
|
||||
buf.push_back(static_cast<char>(i & 0xff));
|
||||
}
|
||||
spdlog::info("Binary example: {}", spdlog::to_hex(buf));
|
||||
spdlog::info("Another binary example:{:n}", spdlog::to_hex(std::begin(buf), std::begin(buf) + 10));
|
||||
// more examples:
|
||||
// logger->info("uppercase: {:X}", spdlog::to_hex(buf));
|
||||
// logger->info("uppercase, no delimiters: {:Xs}", spdlog::to_hex(buf));
|
||||
// logger->info("uppercase, no delimiters, no position info: {:Xsp}", spdlog::to_hex(buf));
|
||||
// logger->info("hexdump style: {:a}", spdlog::to_hex(buf));
|
||||
// logger->info("hexdump style, 20 chars per line {:a}", spdlog::to_hex(buf, 20));
|
||||
}
|
||||
|
||||
// create logger with 2 targets with different log levels and formats
|
||||
// the console will show only warnings or errors, while the file will log all
|
||||
// Log a vector of numbers
|
||||
#include "fmt/ranges.h"
|
||||
void vector_example() {
|
||||
std::vector<int> vec = {1, 2, 3};
|
||||
spdlog::info("Vector example: {}", vec);
|
||||
}
|
||||
|
||||
void multi_sink_example()
|
||||
{
|
||||
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
||||
// Compile time log levels.
|
||||
// define SPDLOG_ACTIVE_LEVEL to required level (e.g. SPDLOG_LEVEL_TRACE)
|
||||
void trace_example() {
|
||||
// trace from global logger
|
||||
SPDLOG_TRACE("Some trace message.. {} ,{}", 1, 3.23);
|
||||
// debug from global logger
|
||||
SPDLOG_DEBUG("Some debug message.. {} ,{}", 1, 3.23);
|
||||
}
|
||||
|
||||
// stopwatch example
|
||||
#include <thread>
|
||||
|
||||
#include "spdlog/stopwatch.h"
|
||||
void stopwatch_example() {
|
||||
spdlog::stopwatch sw;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(123));
|
||||
spdlog::info("Stopwatch: {} seconds", sw);
|
||||
}
|
||||
|
||||
#include "spdlog/sinks/udp_sink.h"
|
||||
void udp_example() {
|
||||
udp_sink_config cfg("127.0.0.1", 11091);
|
||||
auto my_logger = spdlog::create<udp_sink_mt>("udplog", cfg);
|
||||
my_logger->set_level(spdlog::level::debug);
|
||||
my_logger->info("hello world");
|
||||
}
|
||||
|
||||
// A logger with multiple sinks (stdout and file) - each with a different format and log level.
|
||||
void multi_sink_example() {
|
||||
auto console_sink = std::make_shared<stdout_color_sink_mt>();
|
||||
console_sink->set_level(spdlog::level::warn);
|
||||
console_sink->set_pattern("[multi_sink_example] [%^%l%$] %v");
|
||||
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/multisink.txt", true);
|
||||
auto file_sink = std::make_shared<basic_file_sink_mt>("logs/multisink.txt", true);
|
||||
file_sink->set_level(spdlog::level::trace);
|
||||
|
||||
spdlog::logger logger("multi_sink", {console_sink, file_sink});
|
||||
@@ -192,52 +200,99 @@ void multi_sink_example()
|
||||
logger.warn("this should appear in both console and file");
|
||||
logger.info("this message should not appear in the console, only in the file");
|
||||
}
|
||||
// user defined types logging by implementing operator<<
|
||||
#include "spdlog/fmt/ostr.h" // must be included
|
||||
struct my_type
|
||||
{
|
||||
int i;
|
||||
template<typename OStream>
|
||||
friend OStream &operator<<(OStream &os, const my_type &c)
|
||||
{
|
||||
return os << "[my_type i=" << c.i << "]";
|
||||
|
||||
// User defined types logging
|
||||
struct my_type {
|
||||
int i = 0;
|
||||
explicit my_type(int i)
|
||||
: i(i) {}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<my_type> : fmt::formatter<std::string> {
|
||||
auto format(my_type my, format_context &ctx) const -> decltype(ctx.out()) {
|
||||
return fmt::format_to(ctx.out(), "[my_type i={}]", my.i);
|
||||
}
|
||||
};
|
||||
|
||||
void user_defined_example()
|
||||
{
|
||||
spdlog::get("console")->info("user defined type: {}", my_type{14});
|
||||
}
|
||||
void user_defined_example() { spdlog::info("user defined type: {}", my_type(14)); }
|
||||
|
||||
//
|
||||
// custom error handler
|
||||
//
|
||||
void err_handler_example()
|
||||
{
|
||||
// Custom error handler. Will be triggered on log failure.
|
||||
void err_handler_example() {
|
||||
// can be set globally or per logger(logger->set_error_handler(..))
|
||||
spdlog::set_error_handler([](const std::string &msg) { spdlog::get("console")->error("*** ERROR HANDLER EXAMPLE ***: {}", msg); });
|
||||
spdlog::get("console")->info("some invalid message to trigger an error {}{}{}{}", 3);
|
||||
spdlog::set_error_handler([](const std::string &msg) { printf("*** Custom log error handler: %s ***\n", msg.c_str()); });
|
||||
}
|
||||
|
||||
// syslog example (linux/osx/freebsd)
|
||||
#ifndef _WIN32
|
||||
#include "spdlog/sinks/syslog_sink.h"
|
||||
void syslog_example()
|
||||
{
|
||||
#include "spdlog/sinks/syslog_sink.h"
|
||||
void syslog_example() {
|
||||
std::string ident = "spdlog-example";
|
||||
auto syslog_logger = spdlog::syslog_logger_mt("syslog", ident, LOG_PID);
|
||||
auto syslog_logger = spdlog::create<syslog_sink_mt>("syslog", ident, LOG_PID);
|
||||
syslog_logger->warn("This is warning that will end up in syslog.");
|
||||
}
|
||||
#endif
|
||||
|
||||
// Android example
|
||||
// Android example.
|
||||
#if defined(__ANDROID__)
|
||||
#include "spdlog/sinks/android_sink.h"
|
||||
void android_example()
|
||||
{
|
||||
#include "spdlog/sinks/android_sink.h"
|
||||
void android_example() {
|
||||
std::string tag = "spdlog-android";
|
||||
auto android_logger = spdlog::android_logger_mt("android", tag);
|
||||
android_logger->critical("Use \"adb shell logcat\" to view this message.");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Log patterns can contain custom flags.
|
||||
// this will add custom flag '%*' which will be bound to a <my_formatter_flag> instance
|
||||
#include "spdlog/pattern_formatter.h"
|
||||
class my_formatter_flag : public spdlog::custom_flag_formatter {
|
||||
public:
|
||||
void format(const spdlog::details::log_msg &, const std::tm &, spdlog::memory_buf_t &dest) override {
|
||||
std::string some_txt = "custom-flag";
|
||||
dest.append(some_txt.data(), some_txt.data() + some_txt.size());
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
std::unique_ptr<custom_flag_formatter> clone() const override {
|
||||
return std::make_unique<my_formatter_flag>();
|
||||
}
|
||||
};
|
||||
|
||||
void custom_flags_example() {
|
||||
auto formatter = std::make_unique<spdlog::pattern_formatter>();
|
||||
formatter->add_flag<my_formatter_flag>('*').set_pattern("[%n] [%*] [%^%l%$] %v");
|
||||
// set the new formatter using spdlog::set_formatter(formatter) or
|
||||
// logger->set_formatter(formatter) spdlog::set_formatter(std::move(formatter));
|
||||
}
|
||||
|
||||
void file_events_example() {
|
||||
// pass the spdlog::file_event_handlers to file sinks for open/close log file notifications
|
||||
spdlog::file_event_handlers handlers;
|
||||
handlers.before_open = [](spdlog::filename_t) { spdlog::trace("Before opening logfile"); };
|
||||
handlers.after_open = [](spdlog::filename_t, std::FILE *fstream) {
|
||||
spdlog::trace("After opening logfile");
|
||||
fputs("After opening\n", fstream);
|
||||
};
|
||||
handlers.before_close = [](spdlog::filename_t, std::FILE *fstream) {
|
||||
spdlog::trace("Before closing logfile");
|
||||
fputs("Before closing\n", fstream);
|
||||
};
|
||||
handlers.after_close = [](spdlog::filename_t) { spdlog::trace("After closing logfile"); };
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/events-sample.txt", true, handlers);
|
||||
spdlog::logger my_logger("some_logger", file_sink);
|
||||
my_logger.trace("Some log line");
|
||||
}
|
||||
|
||||
void replace_global_logger_example() {
|
||||
// store the old logger so we don't break other examples.
|
||||
auto old_logger = spdlog::global_logger();
|
||||
|
||||
auto new_logger = spdlog::create<basic_file_sink_mt>("new_global_logger", "logs/new-default-log.txt", true);
|
||||
spdlog::set_global_logger(new_logger);
|
||||
spdlog::set_level(spdlog::level::info);
|
||||
spdlog::debug("This message should not be displayed!");
|
||||
spdlog::set_level(spdlog::level::trace);
|
||||
spdlog::debug("This message should be displayed..");
|
||||
spdlog::set_global_logger(old_logger);
|
||||
}
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27703.2018
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example", "example.vcxproj", "{9E5AB93A-0CCE-4BAC-9FCB-0FC9CB5EB8D2}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "spdlog", "spdlog", "{7FC6AB76-AD88-4135-888C-0568E81475AF}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
..\include\spdlog\async.h = ..\include\spdlog\async.h
|
||||
..\include\spdlog\async_logger.h = ..\include\spdlog\async_logger.h
|
||||
..\include\spdlog\common.h = ..\include\spdlog\common.h
|
||||
..\include\spdlog\formatter.h = ..\include\spdlog\formatter.h
|
||||
..\include\spdlog\logger.h = ..\include\spdlog\logger.h
|
||||
..\include\spdlog\spdlog.h = ..\include\spdlog\spdlog.h
|
||||
..\include\spdlog\tweakme.h = ..\include\spdlog\tweakme.h
|
||||
..\include\spdlog\version.h = ..\include\spdlog\version.h
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "details", "details", "{08E93803-E650-42D9-BBB4-3C16979F850E}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
..\include\spdlog\details\async_logger_impl.h = ..\include\spdlog\details\async_logger_impl.h
|
||||
..\include\spdlog\details\circular_q.h = ..\include\spdlog\details\circular_q.h
|
||||
..\include\spdlog\details\console_globals.h = ..\include\spdlog\details\console_globals.h
|
||||
..\include\spdlog\details\file_helper.h = ..\include\spdlog\details\file_helper.h
|
||||
..\include\spdlog\details\fmt_helper.h = ..\include\spdlog\details\fmt_helper.h
|
||||
..\include\spdlog\details\log_msg.h = ..\include\spdlog\details\log_msg.h
|
||||
..\include\spdlog\details\logger_impl.h = ..\include\spdlog\details\logger_impl.h
|
||||
..\include\spdlog\details\mpmc_blocking_q.h = ..\include\spdlog\details\mpmc_blocking_q.h
|
||||
..\include\spdlog\details\null_mutex.h = ..\include\spdlog\details\null_mutex.h
|
||||
..\include\spdlog\details\os.h = ..\include\spdlog\details\os.h
|
||||
..\include\spdlog\details\pattern_formatter.h = ..\include\spdlog\details\pattern_formatter.h
|
||||
..\include\spdlog\details\periodic_worker.h = ..\include\spdlog\details\periodic_worker.h
|
||||
..\include\spdlog\details\registry.h = ..\include\spdlog\details\registry.h
|
||||
..\include\spdlog\details\spdlog_impl.h = ..\include\spdlog\details\spdlog_impl.h
|
||||
..\include\spdlog\details\thread_pool.h = ..\include\spdlog\details\thread_pool.h
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "fmt", "fmt", "{82378DE1-8463-4F91-91A0-C2C40E2AEA2A}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
..\include\spdlog\fmt\fmt.h = ..\include\spdlog\fmt\fmt.h
|
||||
..\include\spdlog\fmt\ostr.h = ..\include\spdlog\fmt\ostr.h
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "bundled", "bundled", "{D9CA4494-80D1-48D1-A897-D3564F7B27FF}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
..\include\spdlog\fmt\bundled\format.cc = ..\include\spdlog\fmt\bundled\format.cc
|
||||
..\include\spdlog\fmt\bundled\format.h = ..\include\spdlog\fmt\bundled\format.h
|
||||
..\include\spdlog\fmt\bundled\LICENSE.rst = ..\include\spdlog\fmt\bundled\LICENSE.rst
|
||||
..\include\spdlog\fmt\bundled\ostream.cc = ..\include\spdlog\fmt\bundled\ostream.cc
|
||||
..\include\spdlog\fmt\bundled\ostream.h = ..\include\spdlog\fmt\bundled\ostream.h
|
||||
..\include\spdlog\fmt\bundled\posix.cc = ..\include\spdlog\fmt\bundled\posix.cc
|
||||
..\include\spdlog\fmt\bundled\posix.h = ..\include\spdlog\fmt\bundled\posix.h
|
||||
..\include\spdlog\fmt\bundled\printf.cc = ..\include\spdlog\fmt\bundled\printf.cc
|
||||
..\include\spdlog\fmt\bundled\printf.h = ..\include\spdlog\fmt\bundled\printf.h
|
||||
..\include\spdlog\fmt\bundled\time.h = ..\include\spdlog\fmt\bundled\time.h
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sinks", "sinks", "{27D16BB9-2B81-4F61-80EC-0C7A777248E4}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
..\include\spdlog\sinks\android_sink.h = ..\include\spdlog\sinks\android_sink.h
|
||||
..\include\spdlog\sinks\ansicolor_sink.h = ..\include\spdlog\sinks\ansicolor_sink.h
|
||||
..\include\spdlog\sinks\base_sink.h = ..\include\spdlog\sinks\base_sink.h
|
||||
..\include\spdlog\sinks\dist_sink.h = ..\include\spdlog\sinks\dist_sink.h
|
||||
..\include\spdlog\sinks\file_sinks.h = ..\include\spdlog\sinks\file_sinks.h
|
||||
..\include\spdlog\sinks\msvc_sink.h = ..\include\spdlog\sinks\msvc_sink.h
|
||||
..\include\spdlog\sinks\null_sink.h = ..\include\spdlog\sinks\null_sink.h
|
||||
..\include\spdlog\sinks\ostream_sink.h = ..\include\spdlog\sinks\ostream_sink.h
|
||||
..\include\spdlog\sinks\sink.h = ..\include\spdlog\sinks\sink.h
|
||||
..\include\spdlog\sinks\stdout_color_sinks.h = ..\include\spdlog\sinks\stdout_color_sinks.h
|
||||
..\include\spdlog\sinks\stdout_sinks.h = ..\include\spdlog\sinks\stdout_sinks.h
|
||||
..\include\spdlog\sinks\syslog_sink.h = ..\include\spdlog\sinks\syslog_sink.h
|
||||
..\include\spdlog\sinks\wincolor_sink.h = ..\include\spdlog\sinks\wincolor_sink.h
|
||||
..\include\spdlog\sinks\windebug_sink.h = ..\include\spdlog\sinks\windebug_sink.h
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Debug|x64 = Debug|x64
|
||||
Release|Win32 = Release|Win32
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9E5AB93A-0CCE-4BAC-9FCB-0FC9CB5EB8D2}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{9E5AB93A-0CCE-4BAC-9FCB-0FC9CB5EB8D2}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{9E5AB93A-0CCE-4BAC-9FCB-0FC9CB5EB8D2}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{9E5AB93A-0CCE-4BAC-9FCB-0FC9CB5EB8D2}.Debug|x64.Build.0 = Debug|x64
|
||||
{9E5AB93A-0CCE-4BAC-9FCB-0FC9CB5EB8D2}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{9E5AB93A-0CCE-4BAC-9FCB-0FC9CB5EB8D2}.Release|Win32.Build.0 = Release|Win32
|
||||
{9E5AB93A-0CCE-4BAC-9FCB-0FC9CB5EB8D2}.Release|x64.ActiveCfg = Release|x64
|
||||
{9E5AB93A-0CCE-4BAC-9FCB-0FC9CB5EB8D2}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{08E93803-E650-42D9-BBB4-3C16979F850E} = {7FC6AB76-AD88-4135-888C-0568E81475AF}
|
||||
{82378DE1-8463-4F91-91A0-C2C40E2AEA2A} = {7FC6AB76-AD88-4135-888C-0568E81475AF}
|
||||
{D9CA4494-80D1-48D1-A897-D3564F7B27FF} = {82378DE1-8463-4F91-91A0-C2C40E2AEA2A}
|
||||
{27D16BB9-2B81-4F61-80EC-0C7A777248E4} = {7FC6AB76-AD88-4135-888C-0568E81475AF}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {1BF53532-C5DC-4236-B195-9E17CBE40A48}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -1,168 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="example.cpp" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{9E5AB93A-0CCE-4BAC-9FCB-0FC9CB5EB8D2}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>.</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PrecompiledHeaderFile />
|
||||
<PrecompiledHeaderOutputFile />
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PrecompiledHeaderFile>
|
||||
</PrecompiledHeaderFile>
|
||||
<PrecompiledHeaderOutputFile>
|
||||
</PrecompiledHeaderOutputFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PrecompiledHeaderFile />
|
||||
<PrecompiledHeaderOutputFile />
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PrecompiledHeaderFile>
|
||||
</PrecompiledHeaderFile>
|
||||
<PrecompiledHeaderOutputFile>
|
||||
</PrecompiledHeaderOutputFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -1,15 +0,0 @@
|
||||
# Setup a project
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := example
|
||||
LOCAL_SRC_FILES := example.cpp
|
||||
LOCAL_CPPFLAGS += -Wall -Wshadow -Wextra -pedantic -std=c++11 -fPIE -pie
|
||||
LOCAL_LDFLAGS += -fPIE -pie
|
||||
|
||||
# Add exception support and set path for spdlog's headers
|
||||
LOCAL_CPPFLAGS += -fexceptions -I../include
|
||||
# Use android's log library
|
||||
LOCAL_LDFLAGS += -llog
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
@@ -1,2 +0,0 @@
|
||||
# Exceptions are used in spdlog. Link to an exception-ready C++ runtime.
|
||||
APP_STL = gnustl_static
|
||||
@@ -1,157 +0,0 @@
|
||||
//
|
||||
// Copyright(c) 2015 Gabi Melman.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
//
|
||||
// spdlog usage example
|
||||
//
|
||||
//
|
||||
|
||||
#define SPDLOG_TRACE_ON
|
||||
#define SPDLOG_DEBUG_ON
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
void async_example();
|
||||
void syslog_example();
|
||||
void android_example();
|
||||
void user_defined_example();
|
||||
void err_handler_example();
|
||||
|
||||
namespace spd = spdlog;
|
||||
int main(int, char *[])
|
||||
{
|
||||
try
|
||||
{
|
||||
// Console logger with color
|
||||
auto console = spd::stdout_color_mt("console");
|
||||
console->info("Welcome to spdlog!");
|
||||
console->error("Some error message with arg{}..", 1);
|
||||
|
||||
// Formatting examples
|
||||
console->warn("Easy padding in numbers like {:08d}", 12);
|
||||
console->critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
|
||||
console->info("Support for floats {:03.2f}", 1.23456);
|
||||
console->info("Positional args are {1} {0}..", "too", "supported");
|
||||
console->info("{:<30}", "left aligned");
|
||||
|
||||
spd::get("console")->info("loggers can be retrieved from a global registry using the spdlog::get(logger_name) function");
|
||||
|
||||
// Create basic file logger (not rotated)
|
||||
auto my_logger = spd::basic_logger_mt("basic_logger", "logs/basic-log.txt");
|
||||
my_logger->info("Some log message");
|
||||
|
||||
// Create a file rotating logger with 5mb size max and 3 rotated files
|
||||
auto rotating_logger = spd::rotating_logger_mt("some_logger_name", "logs/rotating.txt", 1048576 * 5, 3);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
rotating_logger->info("{} * {} equals {:>10}", i, i, i * i);
|
||||
|
||||
// Create a daily logger - a new file is created every day on 2:30am
|
||||
auto daily_logger = spd::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30);
|
||||
// trigger flush if the log severity is error or higher
|
||||
daily_logger->flush_on(spd::level::err);
|
||||
daily_logger->info(123.44);
|
||||
|
||||
// Customize msg format for all messages
|
||||
spd::set_pattern("*** [%H:%M:%S %z] [thread %t] %v ***");
|
||||
rotating_logger->info("This is another message with custom format");
|
||||
|
||||
// Runtime log levels
|
||||
spd::set_level(spd::level::info); // Set global log level to info
|
||||
console->debug("This message should not be displayed!");
|
||||
console->set_level(spd::level::debug); // Set specific logger's log level
|
||||
console->debug("This message should be displayed..");
|
||||
|
||||
// Compile time log levels
|
||||
// define SPDLOG_DEBUG_ON or SPDLOG_TRACE_ON
|
||||
SPDLOG_TRACE(console, "Enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}", 1, 3.23);
|
||||
SPDLOG_DEBUG(console, "Enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}", 1, 3.23);
|
||||
|
||||
// Asynchronous logging is very fast..
|
||||
// Just call spdlog::set_async_mode(q_size) and all created loggers from now on will be asynchronous..
|
||||
async_example();
|
||||
|
||||
// syslog example. linux/osx only
|
||||
syslog_example();
|
||||
|
||||
// android example. compile with NDK
|
||||
android_example();
|
||||
|
||||
// Log user-defined types example
|
||||
user_defined_example();
|
||||
|
||||
// Change default log error handler
|
||||
err_handler_example();
|
||||
|
||||
// Apply a function on all registered loggers
|
||||
spd::apply_all([&](std::shared_ptr<spdlog::logger> l) { l->info("End of example."); });
|
||||
|
||||
// Release and close all loggers
|
||||
spdlog::drop_all();
|
||||
}
|
||||
// Exceptions will only be thrown upon failed logger or sink construction (not during logging)
|
||||
catch (const spd::spdlog_ex &ex)
|
||||
{
|
||||
std::cout << "Log init failed: " << ex.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void async_example()
|
||||
{
|
||||
size_t q_size = 4096; // queue size must be power of 2
|
||||
spdlog::set_async_mode(q_size);
|
||||
auto async_file = spd::daily_logger_st("async_file_logger", "logs/async_log.txt");
|
||||
for (int i = 0; i < 100; ++i)
|
||||
async_file->info("Async message #{}", i);
|
||||
}
|
||||
|
||||
// syslog example (linux/osx/freebsd)
|
||||
void syslog_example()
|
||||
{
|
||||
#ifdef SPDLOG_ENABLE_SYSLOG
|
||||
std::string ident = "spdlog-example";
|
||||
auto syslog_logger = spd::syslog_logger("syslog", ident, LOG_PID);
|
||||
syslog_logger->warn("This is warning that will end up in syslog.");
|
||||
#endif
|
||||
}
|
||||
|
||||
// Android example
|
||||
void android_example()
|
||||
{
|
||||
#if defined(__ANDROID__)
|
||||
std::string tag = "spdlog-android";
|
||||
auto android_logger = spd::android_logger("android", tag);
|
||||
android_logger->critical("Use \"adb shell logcat\" to view this message.");
|
||||
#endif
|
||||
}
|
||||
|
||||
// user defined types logging by implementing operator<<
|
||||
struct my_type
|
||||
{
|
||||
int i;
|
||||
template<typename OStream>
|
||||
friend OStream &operator<<(OStream &os, const my_type &c)
|
||||
{
|
||||
return os << "[my_type i=" << c.i << "]";
|
||||
}
|
||||
};
|
||||
|
||||
#include "spdlog/fmt/ostr.h" // must be included
|
||||
void user_defined_example()
|
||||
{
|
||||
spd::get("console")->info("user defined type: {}", my_type{14});
|
||||
}
|
||||
|
||||
//
|
||||
// custom error handler
|
||||
//
|
||||
void err_handler_example()
|
||||
{
|
||||
// can be set globaly or per logger(logger->set_error_handler(..))
|
||||
spdlog::set_error_handler([](const std::string &msg) { std::cerr << "my err handler: " << msg << std::endl; });
|
||||
spd::get("console")->info("some invalid message to trigger an error {}{}{}{}", 3);
|
||||
}
|
||||
1
example/logs/.gitignore
vendored
1
example/logs/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
*.txt
|
||||
@@ -1,46 +0,0 @@
|
||||
#include "spdlog/sinks/basic_file_sink.h"
|
||||
#include "spdlog/sinks/stdout_sinks.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
int main(int, char *[])
|
||||
{
|
||||
bool enable_debug = true;
|
||||
try
|
||||
{
|
||||
// This other example use a single logger with multiple sinks.
|
||||
// This means that the same log_msg is forwarded to multiple sinks;
|
||||
// Each sink can have it's own log level and a message will be logged.
|
||||
std::vector<spdlog::sink_ptr> sinks;
|
||||
sinks.push_back(std::make_shared<spdlog::sinks::stdout_sink_mt>());
|
||||
sinks.push_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>("./log_regular_file.txt"));
|
||||
sinks.push_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>("./log_debug_file.txt"));
|
||||
|
||||
spdlog::logger console_multisink("multisink", sinks.begin(), sinks.end());
|
||||
console_multisink.set_level(spdlog::level::warn);
|
||||
|
||||
sinks[0]->set_level(spdlog::level::trace); // console. Allow everything. Default value
|
||||
sinks[1]->set_level(spdlog::level::trace); // regular file. Allow everything. Default value
|
||||
sinks[2]->set_level(spdlog::level::off); // regular file. Ignore everything.
|
||||
|
||||
console_multisink.warn("warn: will print only on console and regular file");
|
||||
|
||||
if (enable_debug)
|
||||
{
|
||||
console_multisink.set_level(spdlog::level::debug); // level of the logger
|
||||
sinks[1]->set_level(spdlog::level::debug); // regular file
|
||||
sinks[2]->set_level(spdlog::level::debug); // debug file
|
||||
}
|
||||
console_multisink.debug("Debug: you should see this on console and both files");
|
||||
|
||||
// Release and close all loggers
|
||||
spdlog::drop_all();
|
||||
}
|
||||
// Exceptions will only be thrown upon failed logger or sink construction (not during logging)
|
||||
catch (const spdlog::spdlog_ex &ex)
|
||||
{
|
||||
std::cout << "Log init failed: " << ex.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
//
|
||||
// Copyright(c) 2015 Gabi Melman.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iomanip>
|
||||
#include <locale>
|
||||
#include <sstream>
|
||||
|
||||
namespace utils {
|
||||
|
||||
template<typename T>
|
||||
inline std::string format(const T &value)
|
||||
{
|
||||
static std::locale loc("");
|
||||
std::stringstream ss;
|
||||
ss.imbue(loc);
|
||||
ss << value;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline std::string format(const double &value)
|
||||
{
|
||||
static std::locale loc("");
|
||||
std::stringstream ss;
|
||||
ss.imbue(loc);
|
||||
ss << std::fixed << std::setprecision(1) << value;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
@@ -1,9 +0,0 @@
|
||||
#!/bin/bash
|
||||
echo -n "Running dos2unix "
|
||||
find . -name "*\.h" -o -name "*\.cpp"|grep -v bundled|xargs -I {} sh -c "dos2unix '{}' 2>/dev/null; echo -n '.'"
|
||||
echo
|
||||
echo -n "Running clang-format "
|
||||
find . -name "*\.h" -o -name "*\.cpp"|grep -v bundled|xargs -I {} sh -c "clang-format -i {}; echo -n '.'"
|
||||
echo
|
||||
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
|
||||
//
|
||||
// Copyright(c) 2018 Gabi Melman.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// Async logging using global thread pool
|
||||
// All loggers created here share same global thread pool.
|
||||
// Each log message is pushed to a queue along withe a shared pointer to the
|
||||
// logger.
|
||||
// If a logger deleted while having pending messages in the queue, it's actual
|
||||
// destruction will defer
|
||||
// until all its messages are processed by the thread pool.
|
||||
// This is because each message in the queue holds a shared_ptr to the
|
||||
// originating logger.
|
||||
|
||||
#include "spdlog/async_logger.h"
|
||||
#include "spdlog/details/registry.h"
|
||||
#include "spdlog/details/thread_pool.h"
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace spdlog {
|
||||
|
||||
namespace details {
|
||||
static const size_t default_async_q_size = 8192;
|
||||
}
|
||||
|
||||
// async logger factory - creates async loggers backed with thread pool.
|
||||
// if a global thread pool doesn't already exist, create it with default queue
|
||||
// size of 8192 items and single thread.
|
||||
template<async_overflow_policy OverflowPolicy = async_overflow_policy::block>
|
||||
struct async_factory_impl
|
||||
{
|
||||
template<typename Sink, typename... SinkArgs>
|
||||
static std::shared_ptr<async_logger> create(const std::string &logger_name, SinkArgs &&... args)
|
||||
{
|
||||
auto ®istry_inst = details::registry::instance();
|
||||
|
||||
// create global thread pool if not already exists..
|
||||
std::lock_guard<std::recursive_mutex> tp_lock(registry_inst.tp_mutex());
|
||||
auto tp = registry_inst.get_tp();
|
||||
if (tp == nullptr)
|
||||
{
|
||||
tp = std::make_shared<details::thread_pool>(details::default_async_q_size, 1);
|
||||
registry_inst.set_tp(tp);
|
||||
}
|
||||
|
||||
auto sink = std::make_shared<Sink>(std::forward<SinkArgs>(args)...);
|
||||
auto new_logger = std::make_shared<async_logger>(logger_name, std::move(sink), std::move(tp), OverflowPolicy);
|
||||
registry_inst.register_and_init(new_logger);
|
||||
return new_logger;
|
||||
}
|
||||
};
|
||||
|
||||
using async_factory = async_factory_impl<async_overflow_policy::block>;
|
||||
using async_factory_nonblock = async_factory_impl<async_overflow_policy::overrun_oldest>;
|
||||
|
||||
template<typename Sink, typename... SinkArgs>
|
||||
inline std::shared_ptr<spdlog::logger> create_async(const std::string &logger_name, SinkArgs &&... sink_args)
|
||||
{
|
||||
return async_factory::create<Sink>(logger_name, std::forward<SinkArgs>(sink_args)...);
|
||||
}
|
||||
|
||||
template<typename Sink, typename... SinkArgs>
|
||||
inline std::shared_ptr<spdlog::logger> create_async_nb(const std::string &logger_name, SinkArgs &&... sink_args)
|
||||
{
|
||||
return async_factory_nonblock::create<Sink>(logger_name, std::forward<SinkArgs>(sink_args)...);
|
||||
}
|
||||
|
||||
// set global thread pool.
|
||||
inline void init_thread_pool(size_t q_size, size_t thread_count)
|
||||
{
|
||||
auto tp = std::make_shared<details::thread_pool>(q_size, thread_count);
|
||||
details::registry::instance().set_tp(std::move(tp));
|
||||
}
|
||||
|
||||
// get the global thread pool.
|
||||
inline std::shared_ptr<spdlog::details::thread_pool> thread_pool()
|
||||
{
|
||||
return details::registry::instance().get_tp();
|
||||
}
|
||||
} // namespace spdlog
|
||||
@@ -1,73 +0,0 @@
|
||||
//
|
||||
// Copyright(c) 2015 Gabi Melman.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
// Very fast asynchronous logger (millions of logs per second on an average
|
||||
// desktop)
|
||||
// Uses pre allocated lockfree queue for maximum throughput even under large
|
||||
// number of threads.
|
||||
// Creates a single back thread to pop messages from the queue and log them.
|
||||
//
|
||||
// Upon each log write the logger:
|
||||
// 1. Checks if its log level is enough to log the message
|
||||
// 2. Push a new copy of the message to a queue (or block the caller until
|
||||
// space is available in the queue)
|
||||
// 3. will throw spdlog_ex upon log exceptions
|
||||
// Upon destruction, logs all remaining messages in the queue before
|
||||
// destructing..
|
||||
|
||||
#include "spdlog/common.h"
|
||||
#include "spdlog/logger.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace spdlog {
|
||||
|
||||
// Async overflow policy - block by default.
|
||||
enum class async_overflow_policy
|
||||
{
|
||||
block, // Block until message can be enqueued
|
||||
overrun_oldest // Discard oldest message in the queue if full when trying to
|
||||
// add new item.
|
||||
};
|
||||
|
||||
namespace details {
|
||||
class thread_pool;
|
||||
}
|
||||
|
||||
class async_logger final : public std::enable_shared_from_this<async_logger>, public logger
|
||||
{
|
||||
friend class details::thread_pool;
|
||||
|
||||
public:
|
||||
template<typename It>
|
||||
async_logger(std::string logger_name, It begin, It end, std::weak_ptr<details::thread_pool> tp,
|
||||
async_overflow_policy overflow_policy = async_overflow_policy::block);
|
||||
|
||||
async_logger(std::string logger_name, sinks_init_list sinks_list, std::weak_ptr<details::thread_pool> tp,
|
||||
async_overflow_policy overflow_policy = async_overflow_policy::block);
|
||||
|
||||
async_logger(std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp,
|
||||
async_overflow_policy overflow_policy = async_overflow_policy::block);
|
||||
|
||||
std::shared_ptr<logger> clone(std::string new_name) override;
|
||||
|
||||
protected:
|
||||
void sink_it_(details::log_msg &msg) override;
|
||||
void flush_() override;
|
||||
|
||||
void backend_log_(const details::log_msg &incoming_log_msg);
|
||||
void backend_flush_();
|
||||
|
||||
private:
|
||||
std::weak_ptr<details::thread_pool> thread_pool_;
|
||||
async_overflow_policy overflow_policy_;
|
||||
};
|
||||
} // namespace spdlog
|
||||
|
||||
#include "details/async_logger_impl.h"
|
||||
204
include/spdlog/bin_to_hex.h
Normal file
204
include/spdlog/bin_to_hex.h
Normal file
@@ -0,0 +1,204 @@
|
||||
//
|
||||
// Copyright(c) 2015 Gabi Melman.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cctype>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#if defined(__has_include)
|
||||
#if __has_include(<version>)
|
||||
#include <version>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if __cpp_lib_span >= 202002L
|
||||
#include <span>
|
||||
#endif
|
||||
|
||||
//
|
||||
// Support for logging binary data as hex
|
||||
// format flags, any combination of the following:
|
||||
// {:X} - print in uppercase.
|
||||
// {:s} - don't separate each byte with space.
|
||||
// {:p} - don't print the position on each line start.
|
||||
// {:n} - don't split the output to lines.
|
||||
// {:a} - show ASCII if :n is not set
|
||||
|
||||
//
|
||||
// Examples:
|
||||
//
|
||||
// std::vector<char> v(200, 0x0b);
|
||||
// logger->info("Some buffer {}", spdlog::to_hex(v));
|
||||
// char buf[128];
|
||||
// logger->info("Some buffer {:X}", spdlog::to_hex(std::begin(buf), std::end(buf)));
|
||||
// logger->info("Some buffer {:X}", spdlog::to_hex(std::begin(buf), std::end(buf), 16));
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
template <typename It>
|
||||
class dump_info {
|
||||
public:
|
||||
dump_info(It range_begin, It range_end, size_t size_per_line)
|
||||
: begin_(range_begin),
|
||||
end_(range_end),
|
||||
size_per_line_(size_per_line) {}
|
||||
|
||||
// do not use begin() and end() to avoid collision with fmt/ranges
|
||||
It get_begin() const { return begin_; }
|
||||
It get_end() const { return end_; }
|
||||
size_t size_per_line() const { return size_per_line_; }
|
||||
|
||||
private:
|
||||
It begin_, end_;
|
||||
size_t size_per_line_;
|
||||
};
|
||||
} // namespace details
|
||||
|
||||
// create a dump_info that wraps the given container
|
||||
template <typename Container>
|
||||
inline details::dump_info<typename Container::const_iterator> to_hex(const Container &container, size_t size_per_line = 32) {
|
||||
static_assert(sizeof(typename Container::value_type) == 1, "sizeof(Container::value_type) != 1");
|
||||
using Iter = typename Container::const_iterator;
|
||||
return details::dump_info<Iter>(std::begin(container), std::end(container), size_per_line);
|
||||
}
|
||||
|
||||
#if __cpp_lib_span >= 202002L
|
||||
|
||||
template <typename Value, size_t Extent>
|
||||
inline details::dump_info<typename std::span<Value, Extent>::iterator> to_hex(const std::span<Value, Extent> &container,
|
||||
size_t size_per_line = 32) {
|
||||
using Container = std::span<Value, Extent>;
|
||||
static_assert(sizeof(typename Container::value_type) == 1, "sizeof(Container::value_type) != 1");
|
||||
using Iter = typename Container::iterator;
|
||||
return details::dump_info<Iter>(std::begin(container), std::end(container), size_per_line);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// create dump_info from ranges
|
||||
template <typename It>
|
||||
inline details::dump_info<It> to_hex(const It range_begin, const It range_end, size_t size_per_line = 32) {
|
||||
return details::dump_info<It>(range_begin, range_end, size_per_line);
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
|
||||
template <typename T>
|
||||
struct fmt::formatter<spdlog::details::dump_info<T>, char> {
|
||||
const char delimiter = ' ';
|
||||
bool put_newlines = true;
|
||||
bool put_delimiters = true;
|
||||
bool use_uppercase = false;
|
||||
bool put_positions = true; // position on start of each line
|
||||
bool show_ascii = false;
|
||||
|
||||
// parse the format string flags
|
||||
template <typename ParseContext>
|
||||
constexpr auto parse(ParseContext &ctx) -> decltype(ctx.begin()) {
|
||||
auto it = ctx.begin();
|
||||
while (it != ctx.end() && *it != '}') {
|
||||
switch (*it) {
|
||||
case 'X':
|
||||
use_uppercase = true;
|
||||
break;
|
||||
case 's':
|
||||
put_delimiters = false;
|
||||
break;
|
||||
case 'p':
|
||||
put_positions = false;
|
||||
break;
|
||||
case 'n':
|
||||
put_newlines = false;
|
||||
show_ascii = false;
|
||||
break;
|
||||
case 'a':
|
||||
if (put_newlines) {
|
||||
show_ascii = true;
|
||||
}
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
|
||||
++it;
|
||||
}
|
||||
return it;
|
||||
}
|
||||
|
||||
// format the given bytes range as hex
|
||||
template <typename FormatContext, typename Container>
|
||||
auto format(const spdlog::details::dump_info<Container> &the_range, FormatContext &ctx) const -> decltype(ctx.out()) {
|
||||
constexpr const char *hex_upper = "0123456789ABCDEF";
|
||||
constexpr const char *hex_lower = "0123456789abcdef";
|
||||
const char *hex_chars = use_uppercase ? hex_upper : hex_lower;
|
||||
auto inserter = ctx.out();
|
||||
int size_per_line = static_cast<int>(the_range.size_per_line());
|
||||
auto start_of_line = the_range.get_begin();
|
||||
for (auto i = the_range.get_begin(); i != the_range.get_end(); i++) {
|
||||
auto ch = static_cast<unsigned char>(*i);
|
||||
|
||||
if (put_newlines && (i == the_range.get_begin() || i - start_of_line >= size_per_line)) {
|
||||
if (show_ascii && i != the_range.get_begin()) {
|
||||
*inserter++ = delimiter;
|
||||
*inserter++ = delimiter;
|
||||
for (auto j = start_of_line; j < i; j++) {
|
||||
auto pc = static_cast<unsigned char>(*j);
|
||||
*inserter++ = std::isprint(pc) ? static_cast<char>(*j) : '.';
|
||||
}
|
||||
}
|
||||
|
||||
put_newline(inserter, static_cast<size_t>(i - the_range.get_begin()));
|
||||
|
||||
// put first byte without delimiter in front of it
|
||||
*inserter++ = hex_chars[(ch >> 4) & 0x0f];
|
||||
*inserter++ = hex_chars[ch & 0x0f];
|
||||
start_of_line = i;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (put_delimiters && i != the_range.get_begin()) {
|
||||
*inserter++ = delimiter;
|
||||
}
|
||||
|
||||
*inserter++ = hex_chars[(ch >> 4) & 0x0f];
|
||||
*inserter++ = hex_chars[ch & 0x0f];
|
||||
}
|
||||
if (show_ascii) // add ascii to last line
|
||||
{
|
||||
if (the_range.get_end() - the_range.get_begin() > size_per_line) {
|
||||
auto blank_num = size_per_line - (the_range.get_end() - start_of_line);
|
||||
while (blank_num-- > 0) {
|
||||
*inserter++ = delimiter;
|
||||
*inserter++ = delimiter;
|
||||
if (put_delimiters) {
|
||||
*inserter++ = delimiter;
|
||||
}
|
||||
}
|
||||
}
|
||||
*inserter++ = delimiter;
|
||||
*inserter++ = delimiter;
|
||||
for (auto j = start_of_line; j != the_range.get_end(); j++) {
|
||||
auto pc = static_cast<unsigned char>(*j);
|
||||
*inserter++ = std::isprint(pc) ? static_cast<char>(*j) : '.';
|
||||
}
|
||||
}
|
||||
return inserter;
|
||||
}
|
||||
|
||||
// put newline(and position header)
|
||||
template <typename It>
|
||||
void put_newline(It inserter, std::size_t pos) const {
|
||||
#ifdef _WIN32
|
||||
*inserter++ = '\r';
|
||||
#endif
|
||||
*inserter++ = '\n';
|
||||
|
||||
if (put_positions) {
|
||||
spdlog::fmt_lib::format_to(inserter, SPDLOG_FMT_STRING("{:04X}: "), pos);
|
||||
}
|
||||
}
|
||||
}; // namespace fmt
|
||||
@@ -1,48 +1,44 @@
|
||||
//
|
||||
// Copyright(c) 2015 Gabi Melman.
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "spdlog/tweakme.h"
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
#include <string_view>
|
||||
#include <cstdint>
|
||||
|
||||
#if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT)
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include "./source_loc.h"
|
||||
#include "fmt/base.h"
|
||||
#include "fmt/xchar.h"
|
||||
|
||||
#if defined(SPDLOG_SHARED_LIB)
|
||||
#if defined(_WIN32)
|
||||
#ifdef spdlog_EXPORTS
|
||||
#define SPDLOG_API __declspec(dllexport)
|
||||
#else // !spdlog_EXPORTS
|
||||
#define SPDLOG_API __declspec(dllimport)
|
||||
#endif
|
||||
#else // !defined(_WIN32)
|
||||
#define SPDLOG_API __attribute__((visibility("default")))
|
||||
#endif
|
||||
#else // !defined(SPDLOG_SHARED_LIB)
|
||||
#define SPDLOG_API
|
||||
#endif
|
||||
|
||||
#include "spdlog/details/null_mutex.h"
|
||||
#define SPDLOG_FMT_RUNTIME(format_string) fmt::runtime(format_string)
|
||||
#define SPDLOG_FMT_STRING(format_string) FMT_STRING(format_string)
|
||||
|
||||
// visual studio upto 2013 does not support noexcept nor constexpr
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
||||
#define SPDLOG_NOEXCEPT throw()
|
||||
#define SPDLOG_CONSTEXPR
|
||||
#else
|
||||
#define SPDLOG_NOEXCEPT noexcept
|
||||
#define SPDLOG_CONSTEXPR constexpr
|
||||
#ifndef SPDLOG_FUNCTION
|
||||
#define SPDLOG_FUNCTION static_cast<const char *>(__FUNCTION__)
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define SPDLOG_DEPRECATED __attribute__((deprecated))
|
||||
#elif defined(_MSC_VER)
|
||||
#define SPDLOG_DEPRECATED __declspec(deprecated)
|
||||
#else
|
||||
#define SPDLOG_DEPRECATED
|
||||
#endif
|
||||
|
||||
#include "spdlog/fmt/fmt.h"
|
||||
|
||||
namespace spdlog {
|
||||
|
||||
class formatter;
|
||||
@@ -54,133 +50,90 @@ class sink;
|
||||
using log_clock = std::chrono::system_clock;
|
||||
using sink_ptr = std::shared_ptr<sinks::sink>;
|
||||
using sinks_init_list = std::initializer_list<sink_ptr>;
|
||||
using log_err_handler = std::function<void(const std::string &err_msg)>;
|
||||
using err_handler = std::function<void(const std::string &err_msg)>;
|
||||
using string_view_t = std::basic_string_view<char>;
|
||||
using wstring_view_t = std::basic_string_view<wchar_t>;
|
||||
|
||||
#if defined(SPDLOG_NO_ATOMIC_LEVELS)
|
||||
using level_t = details::null_atomic_int;
|
||||
#else
|
||||
using level_t = std::atomic<int>;
|
||||
namespace fmt_lib = fmt;
|
||||
using memory_buf_t = fmt::basic_memory_buffer<char, 250>;
|
||||
using wmemory_buf_t = fmt::basic_memory_buffer<wchar_t, 250>;
|
||||
|
||||
template <typename... Args>
|
||||
using format_string_t = fmt::format_string<Args...>;
|
||||
|
||||
#define SPDLOG_LEVEL_TRACE 0
|
||||
#define SPDLOG_LEVEL_DEBUG 1
|
||||
#define SPDLOG_LEVEL_INFO 2
|
||||
#define SPDLOG_LEVEL_WARN 3
|
||||
#define SPDLOG_LEVEL_ERROR 4
|
||||
#define SPDLOG_LEVEL_CRITICAL 5
|
||||
#define SPDLOG_LEVEL_OFF 6
|
||||
|
||||
#if !defined(SPDLOG_ACTIVE_LEVEL)
|
||||
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
|
||||
#endif
|
||||
|
||||
// Log level enum
|
||||
namespace level {
|
||||
enum level_enum
|
||||
{
|
||||
trace = 0,
|
||||
debug = 1,
|
||||
info = 2,
|
||||
warn = 3,
|
||||
err = 4,
|
||||
critical = 5,
|
||||
off = 6
|
||||
enum class level : std::uint8_t {
|
||||
trace = SPDLOG_LEVEL_TRACE,
|
||||
debug = SPDLOG_LEVEL_DEBUG,
|
||||
info = SPDLOG_LEVEL_INFO,
|
||||
warn = SPDLOG_LEVEL_WARN,
|
||||
err = SPDLOG_LEVEL_ERROR,
|
||||
critical = SPDLOG_LEVEL_CRITICAL,
|
||||
off = SPDLOG_LEVEL_OFF,
|
||||
n_levels = SPDLOG_LEVEL_OFF + 1
|
||||
};
|
||||
|
||||
#if !defined(SPDLOG_LEVEL_NAMES)
|
||||
#define SPDLOG_LEVEL_NAMES \
|
||||
{ \
|
||||
"trace", "debug", "info", "warning", "error", "critical", "off" \
|
||||
}
|
||||
#endif
|
||||
static const char *level_names[] SPDLOG_LEVEL_NAMES;
|
||||
using atomic_level_t = std::atomic<level>;
|
||||
|
||||
static const char *short_level_names[]{"T", "D", "I", "W", "E", "C", "O"};
|
||||
[[nodiscard]] constexpr size_t level_to_number(level lvl) noexcept { return static_cast<size_t>(lvl); }
|
||||
|
||||
inline const char *to_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
|
||||
{
|
||||
return level_names[l];
|
||||
constexpr auto levels_count = level_to_number(level::n_levels);
|
||||
constexpr std::array<std::string_view, levels_count> level_string_views{"trace", "debug", "info", "warning",
|
||||
"error", "critical", "off"};
|
||||
constexpr std::array<std::string_view, levels_count> short_level_names{"T", "D", "I", "W", "E", "C", "O"};
|
||||
|
||||
[[nodiscard]] constexpr std::string_view to_string_view(spdlog::level lvl) noexcept {
|
||||
return level_string_views.at(level_to_number(lvl));
|
||||
}
|
||||
|
||||
inline const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT
|
||||
{
|
||||
return short_level_names[l];
|
||||
[[nodiscard]] constexpr std::string_view to_short_string_view(spdlog::level lvl) noexcept {
|
||||
return short_level_names.at(level_to_number(lvl));
|
||||
}
|
||||
|
||||
inline spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT
|
||||
{
|
||||
static std::unordered_map<std::string, level_enum> name_to_level = // map string->level
|
||||
{{level_names[0], level::trace}, // trace
|
||||
{level_names[1], level::debug}, // debug
|
||||
{level_names[2], level::info}, // info
|
||||
{level_names[3], level::warn}, // warn
|
||||
{level_names[4], level::err}, // err
|
||||
{level_names[5], level::critical}, // critical
|
||||
{level_names[6], level::off}}; // off
|
||||
[[nodiscard]] SPDLOG_API spdlog::level level_from_str(const std::string &name) noexcept;
|
||||
|
||||
auto lvl_it = name_to_level.find(name);
|
||||
return lvl_it != name_to_level.end() ? lvl_it->second : level::off;
|
||||
}
|
||||
|
||||
using level_hasher = std::hash<int>;
|
||||
} // namespace level
|
||||
//
|
||||
// Color mode used by sinks with color support.
|
||||
//
|
||||
enum class color_mode { always, automatic, never };
|
||||
|
||||
//
|
||||
// Pattern time - specific time getting to use for pattern_formatter.
|
||||
// local time by default
|
||||
//
|
||||
enum class pattern_time_type
|
||||
{
|
||||
local, // log localtime
|
||||
utc // log utc
|
||||
enum class pattern_time_type {
|
||||
local, // log localtime
|
||||
utc // log utc
|
||||
};
|
||||
|
||||
//
|
||||
// Log exception
|
||||
//
|
||||
class spdlog_ex : public std::exception
|
||||
{
|
||||
class SPDLOG_API spdlog_ex : public std::exception {
|
||||
public:
|
||||
explicit spdlog_ex(std::string msg)
|
||||
: msg_(std::move(msg))
|
||||
{
|
||||
}
|
||||
explicit spdlog_ex(std::string msg);
|
||||
|
||||
spdlog_ex(const std::string &msg, int last_errno)
|
||||
{
|
||||
fmt::memory_buffer outbuf;
|
||||
fmt::format_system_error(outbuf, last_errno, msg);
|
||||
msg_ = fmt::to_string(outbuf);
|
||||
}
|
||||
spdlog_ex(const std::string &msg, int last_errno);
|
||||
|
||||
const char *what() const SPDLOG_NOEXCEPT override
|
||||
{
|
||||
return msg_.c_str();
|
||||
}
|
||||
[[nodiscard]] const char *what() const noexcept override;
|
||||
|
||||
private:
|
||||
std::string msg_;
|
||||
};
|
||||
|
||||
//
|
||||
// wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined)
|
||||
//
|
||||
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
|
||||
using filename_t = std::wstring;
|
||||
#else
|
||||
using filename_t = std::string;
|
||||
#endif
|
||||
[[noreturn]] SPDLOG_API void throw_spdlog_ex(const std::string &msg, int last_errno);
|
||||
[[noreturn]] SPDLOG_API void throw_spdlog_ex(std::string msg);
|
||||
|
||||
#define SPDLOG_CATCH_AND_HANDLE \
|
||||
catch (const std::exception &ex) \
|
||||
{ \
|
||||
err_handler_(ex.what()); \
|
||||
} \
|
||||
catch (...) \
|
||||
{ \
|
||||
err_handler_("Unknown exeption in logger"); \
|
||||
}
|
||||
|
||||
namespace details {
|
||||
// make_unique support for pre c++14
|
||||
|
||||
#if __cplusplus >= 201402L // C++14 and beyond
|
||||
using std::make_unique;
|
||||
#else
|
||||
template<typename T, typename... Args>
|
||||
std::unique_ptr<T> make_unique(Args &&... args)
|
||||
{
|
||||
static_assert(!std::is_array<T>::value, "arrays not supported");
|
||||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
#endif
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
||||
37
include/spdlog/details/async_log_msg.h
Normal file
37
include/spdlog/details/async_log_msg.h
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include "./log_msg.h"
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
|
||||
// Extend log_msg with internal buffer to store its payload.
|
||||
// This is needed since log_msg holds string_views that points to stack data.
|
||||
|
||||
class SPDLOG_API async_log_msg : public log_msg {
|
||||
public:
|
||||
enum class type:std::uint8_t { log, flush, terminate };
|
||||
async_log_msg() = default;
|
||||
explicit async_log_msg(type type);
|
||||
async_log_msg(type type, const log_msg &orig_msg);
|
||||
|
||||
~async_log_msg() = default;
|
||||
async_log_msg(const async_log_msg &other);
|
||||
async_log_msg(async_log_msg &&other) noexcept;
|
||||
async_log_msg &operator=(const async_log_msg &other);
|
||||
async_log_msg &operator=(async_log_msg &&other) noexcept;
|
||||
|
||||
type message_type() const {return msg_type_;}
|
||||
private:
|
||||
type msg_type_{type::log};
|
||||
memory_buf_t buffer_;
|
||||
void update_string_views();
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
@@ -1,110 +0,0 @@
|
||||
//
|
||||
// Copyright(c) 2015 Gabi Melman.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
// async logger implementation
|
||||
// uses a thread pool to perform the actual logging
|
||||
|
||||
#include "spdlog/details/thread_pool.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
template<typename It>
|
||||
inline spdlog::async_logger::async_logger(
|
||||
std::string logger_name, It begin, It end, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
|
||||
: logger(std::move(logger_name), begin, end)
|
||||
, thread_pool_(tp)
|
||||
, overflow_policy_(overflow_policy)
|
||||
{
|
||||
}
|
||||
|
||||
inline spdlog::async_logger::async_logger(
|
||||
std::string logger_name, sinks_init_list sinks_list, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
|
||||
: async_logger(std::move(logger_name), sinks_list.begin(), sinks_list.end(), tp, overflow_policy)
|
||||
{
|
||||
}
|
||||
|
||||
inline spdlog::async_logger::async_logger(
|
||||
std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
|
||||
: async_logger(std::move(logger_name), {single_sink}, tp, overflow_policy)
|
||||
{
|
||||
}
|
||||
|
||||
// send the log message to the thread pool
|
||||
inline void spdlog::async_logger::sink_it_(details::log_msg &msg)
|
||||
{
|
||||
#if defined(SPDLOG_ENABLE_MESSAGE_COUNTER)
|
||||
incr_msg_counter_(msg);
|
||||
#endif
|
||||
if (auto pool_ptr = thread_pool_.lock())
|
||||
{
|
||||
pool_ptr->post_log(shared_from_this(), std::move(msg), overflow_policy_);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw spdlog_ex("async log: thread pool doesn't exist anymore");
|
||||
}
|
||||
}
|
||||
|
||||
// send flush request to the thread pool
|
||||
inline void spdlog::async_logger::flush_()
|
||||
{
|
||||
if (auto pool_ptr = thread_pool_.lock())
|
||||
{
|
||||
pool_ptr->post_flush(shared_from_this(), overflow_policy_);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw spdlog_ex("async flush: thread pool doesn't exist anymore");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// backend functions - called from the thread pool to do the actual job
|
||||
//
|
||||
inline void spdlog::async_logger::backend_log_(const details::log_msg &incoming_log_msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (auto &s : sinks_)
|
||||
{
|
||||
if (s->should_log(incoming_log_msg.level))
|
||||
{
|
||||
s->log(incoming_log_msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
SPDLOG_CATCH_AND_HANDLE
|
||||
|
||||
if (should_flush_(incoming_log_msg))
|
||||
{
|
||||
backend_flush_();
|
||||
}
|
||||
}
|
||||
|
||||
inline void spdlog::async_logger::backend_flush_()
|
||||
{
|
||||
try
|
||||
{
|
||||
for (auto &sink : sinks_)
|
||||
{
|
||||
sink->flush();
|
||||
}
|
||||
}
|
||||
SPDLOG_CATCH_AND_HANDLE
|
||||
}
|
||||
|
||||
inline std::shared_ptr<spdlog::logger> spdlog::async_logger::clone(std::string new_name)
|
||||
{
|
||||
auto cloned = std::make_shared<spdlog::async_logger>(std::move(new_name), sinks_.begin(), sinks_.end(), thread_pool_, overflow_policy_);
|
||||
|
||||
cloned->set_level(this->level());
|
||||
cloned->flush_on(this->flush_level());
|
||||
cloned->set_error_handler(this->error_handler());
|
||||
return std::move(cloned);
|
||||
}
|
||||
@@ -1,72 +1,119 @@
|
||||
//
|
||||
// Copyright(c) 2018 Gabi Melman.
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
// cirucal q view of std::vector.
|
||||
// circular q view of std::vector.
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
template<typename T>
|
||||
class circular_q
|
||||
{
|
||||
template <typename T>
|
||||
class circular_q {
|
||||
size_t max_items_ = 0;
|
||||
typename std::vector<T>::size_type head_ = 0;
|
||||
typename std::vector<T>::size_type tail_ = 0;
|
||||
size_t overrun_counter_ = 0;
|
||||
std::vector<T> v_;
|
||||
|
||||
public:
|
||||
using item_type = T;
|
||||
using value_type = T;
|
||||
|
||||
// empty ctor - create a disabled queue with no elements allocated at all
|
||||
circular_q() = default;
|
||||
|
||||
explicit circular_q(size_t max_items)
|
||||
: max_items_(max_items + 1) // one item is reserved as marker for full q
|
||||
, v_(max_items_)
|
||||
{
|
||||
: max_items_(max_items + 1) // one item is reserved as marker for full q
|
||||
,
|
||||
v_(max_items_) {}
|
||||
|
||||
circular_q(const circular_q &) = default;
|
||||
circular_q &operator=(const circular_q &) = default;
|
||||
|
||||
// move cannot be default,
|
||||
// since we need to reset head_, tail_, etc. to zero in the moved object
|
||||
circular_q(circular_q &&other) noexcept { copy_moveable(std::move(other)); }
|
||||
|
||||
circular_q &operator=(circular_q &&other) noexcept {
|
||||
copy_moveable(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
|
||||
// push back, overrun (oldest) item if no room left
|
||||
void push_back(T &&item)
|
||||
{
|
||||
v_[tail_] = std::move(item);
|
||||
tail_ = (tail_ + 1) % max_items_;
|
||||
void push_back(T &&item) {
|
||||
if (max_items_ > 0) {
|
||||
v_[tail_] = std::move(item);
|
||||
tail_ = (tail_ + 1) % max_items_;
|
||||
|
||||
if (tail_ == head_) // overrun last item if full
|
||||
{
|
||||
head_ = (head_ + 1) % max_items_;
|
||||
++overrun_counter_;
|
||||
if (tail_ == head_) // overrun last item if full
|
||||
{
|
||||
head_ = (head_ + 1) % max_items_;
|
||||
++overrun_counter_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pop item from front.
|
||||
// Return const reference to the front item.
|
||||
// If there are no elements in the container, the behavior is undefined.
|
||||
void pop_front(T &popped_item)
|
||||
{
|
||||
popped_item = std::move(v_[head_]);
|
||||
head_ = (head_ + 1) % max_items_;
|
||||
[[nodiscard]] const T &front() const { return v_[head_]; }
|
||||
|
||||
// Return reference to the front item.
|
||||
// If there are no elements in the container, the behavior is undefined.
|
||||
[[nodiscard]] T &front() { return v_[head_]; }
|
||||
|
||||
// Return number of elements actually stored
|
||||
[[nodiscard]] size_t size() const {
|
||||
if (tail_ >= head_) {
|
||||
return tail_ - head_;
|
||||
} else {
|
||||
return max_items_ - (head_ - tail_);
|
||||
}
|
||||
}
|
||||
|
||||
bool empty()
|
||||
{
|
||||
return tail_ == head_;
|
||||
// Return const reference to item by index.
|
||||
// If index is out of range 0…size()-1, the behavior is undefined.
|
||||
const T &operator[](size_t idx) const {
|
||||
assert(idx < size());
|
||||
assert(max_items_ > 0);
|
||||
return v_[(head_ + idx) % max_items_];
|
||||
}
|
||||
|
||||
bool full()
|
||||
{
|
||||
// Pop item from front if not empty.
|
||||
void pop_front() {
|
||||
if (!empty()) {
|
||||
head_ = (head_ + 1) % max_items_;
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] bool empty() const { return tail_ == head_; }
|
||||
|
||||
[[nodiscard]] bool full() const {
|
||||
// head is ahead of the tail by 1
|
||||
return ((tail_ + 1) % max_items_) == head_;
|
||||
if (max_items_ > 0) {
|
||||
return ((tail_ + 1) % max_items_) == head_;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t overrun_counter() const
|
||||
{
|
||||
return overrun_counter_;
|
||||
}
|
||||
[[nodiscard]] size_t overrun_counter() const { return overrun_counter_; }
|
||||
|
||||
void reset_overrun_counter() { overrun_counter_ = 0; }
|
||||
|
||||
private:
|
||||
size_t max_items_;
|
||||
typename std::vector<T>::size_type head_ = 0;
|
||||
typename std::vector<T>::size_type tail_ = 0;
|
||||
// copy from other&& and reset it to disabled state
|
||||
void copy_moveable(circular_q &&other) noexcept {
|
||||
max_items_ = other.max_items_;
|
||||
head_ = other.head_;
|
||||
tail_ = other.tail_;
|
||||
overrun_counter_ = other.overrun_counter_;
|
||||
v_ = std::move(other.v_);
|
||||
|
||||
std::vector<T> v_;
|
||||
|
||||
size_t overrun_counter_ = 0;
|
||||
// put &&other in disabled, but valid state
|
||||
other.max_items_ = 0;
|
||||
other.head_ = other.tail_ = 0;
|
||||
other.overrun_counter_ = 0;
|
||||
}
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
#pragma once
|
||||
//
|
||||
// Copyright(c) 2018 Gabi Melman.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#include "spdlog/details/null_mutex.h"
|
||||
#include <cstdio>
|
||||
#include <mutex>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX // prevent windows redefining min/max
|
||||
#endif
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
struct console_stdout
|
||||
{
|
||||
static std::FILE *stream()
|
||||
{
|
||||
return stdout;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
static HANDLE handle()
|
||||
{
|
||||
return ::GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
struct console_stderr
|
||||
{
|
||||
static std::FILE *stream()
|
||||
{
|
||||
return stderr;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
static HANDLE handle()
|
||||
{
|
||||
return ::GetStdHandle(STD_ERROR_HANDLE);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
struct console_mutex
|
||||
{
|
||||
using mutex_t = std::mutex;
|
||||
static mutex_t &mutex()
|
||||
{
|
||||
static mutex_t s_mutex;
|
||||
return s_mutex;
|
||||
}
|
||||
};
|
||||
|
||||
struct console_nullmutex
|
||||
{
|
||||
using mutex_t = null_mutex;
|
||||
static mutex_t &mutex()
|
||||
{
|
||||
static mutex_t s_mutex;
|
||||
return s_mutex;
|
||||
}
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
23
include/spdlog/details/err_helper.h
Normal file
23
include/spdlog/details/err_helper.h
Normal file
@@ -0,0 +1,23 @@
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#include <exception>
|
||||
#include "spdlog/common.h"
|
||||
|
||||
// by default, prints the error to stderr, thread safe
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
class SPDLOG_API err_helper {
|
||||
err_handler custom_err_handler_;
|
||||
public:
|
||||
void handle_ex(const std::string& origin, const source_loc& loc, const std::exception& ex) const noexcept;
|
||||
void handle_unknown_ex(const std::string& origin, const source_loc& loc) const noexcept;
|
||||
void set_err_handler(err_handler handler);
|
||||
};
|
||||
|
||||
|
||||
}} // namespace spdlog::details
|
||||
@@ -1,152 +1,44 @@
|
||||
//
|
||||
// Copyright(c) 2015 Gabi Melman.
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tuple>
|
||||
|
||||
#include "../common.h"
|
||||
#include "../file_event_handlers.h"
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
// Helper class for file sinks.
|
||||
// When failing to open a file, retry several times(5) with a delay interval(10 ms).
|
||||
// Throw spdlog_ex exception on errors.
|
||||
|
||||
#include "spdlog/details/log_msg.h"
|
||||
#include "spdlog/details/os.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <tuple>
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
class file_helper
|
||||
{
|
||||
|
||||
class SPDLOG_API file_helper {
|
||||
public:
|
||||
const int open_tries = 5;
|
||||
const int open_interval = 10;
|
||||
|
||||
explicit file_helper() = default;
|
||||
file_helper() = default;
|
||||
explicit file_helper(file_event_handlers event_handlers);
|
||||
|
||||
file_helper(const file_helper &) = delete;
|
||||
file_helper &operator=(const file_helper &) = delete;
|
||||
~file_helper();
|
||||
|
||||
~file_helper()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
void open(const filename_t &fname, bool truncate = false)
|
||||
{
|
||||
close();
|
||||
auto *mode = truncate ? SPDLOG_FILENAME_T("wb") : SPDLOG_FILENAME_T("ab");
|
||||
_filename = fname;
|
||||
for (int tries = 0; tries < open_tries; ++tries)
|
||||
{
|
||||
if (!os::fopen_s(&fd_, fname, mode))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
details::os::sleep_for_millis(open_interval);
|
||||
}
|
||||
|
||||
throw spdlog_ex("Failed opening file " + os::filename_to_str(_filename) + " for writing", errno);
|
||||
}
|
||||
|
||||
void reopen(bool truncate)
|
||||
{
|
||||
if (_filename.empty())
|
||||
{
|
||||
throw spdlog_ex("Failed re opening file - was not opened before");
|
||||
}
|
||||
open(_filename, truncate);
|
||||
}
|
||||
|
||||
void flush()
|
||||
{
|
||||
std::fflush(fd_);
|
||||
}
|
||||
|
||||
void close()
|
||||
{
|
||||
if (fd_ != nullptr)
|
||||
{
|
||||
std::fclose(fd_);
|
||||
fd_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void write(const fmt::memory_buffer &buf)
|
||||
{
|
||||
size_t msg_size = buf.size();
|
||||
auto data = buf.data();
|
||||
if (std::fwrite(data, 1, msg_size, fd_) != msg_size)
|
||||
{
|
||||
throw spdlog_ex("Failed writing to file " + os::filename_to_str(_filename), errno);
|
||||
}
|
||||
}
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
if (fd_ == nullptr)
|
||||
{
|
||||
throw spdlog_ex("Cannot use size() on closed file " + os::filename_to_str(_filename));
|
||||
}
|
||||
return os::filesize(fd_);
|
||||
}
|
||||
|
||||
const filename_t &filename() const
|
||||
{
|
||||
return _filename;
|
||||
}
|
||||
|
||||
static bool file_exists(const filename_t &fname)
|
||||
{
|
||||
return os::file_exists(fname);
|
||||
}
|
||||
|
||||
//
|
||||
// return file path and its extension:
|
||||
//
|
||||
// "mylog.txt" => ("mylog", ".txt")
|
||||
// "mylog" => ("mylog", "")
|
||||
// "mylog." => ("mylog.", "")
|
||||
// "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt")
|
||||
//
|
||||
// the starting dot in filenames is ignored (hidden files):
|
||||
//
|
||||
// ".mylog" => (".mylog". "")
|
||||
// "my_folder/.mylog" => ("my_folder/.mylog", "")
|
||||
// "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt")
|
||||
static std::tuple<filename_t, filename_t> split_by_extenstion(const spdlog::filename_t &fname)
|
||||
{
|
||||
auto ext_index = fname.rfind('.');
|
||||
|
||||
// no valid extension found - return whole path and empty string as
|
||||
// extension
|
||||
if (ext_index == filename_t::npos || ext_index == 0 || ext_index == fname.size() - 1)
|
||||
{
|
||||
return std::make_tuple(fname, spdlog::filename_t());
|
||||
}
|
||||
|
||||
// treat casese like "/etc/rc.d/somelogfile or "/abc/.hiddenfile"
|
||||
auto folder_index = fname.rfind(details::os::folder_sep);
|
||||
if (folder_index != filename_t::npos && folder_index >= ext_index - 1)
|
||||
{
|
||||
return std::make_tuple(fname, spdlog::filename_t());
|
||||
}
|
||||
|
||||
// finally - return a valid base and extension tuple
|
||||
return std::make_tuple(fname.substr(0, ext_index), fname.substr(ext_index));
|
||||
}
|
||||
void open(const filename_t &fname, bool truncate = false);
|
||||
void reopen(bool truncate);
|
||||
void flush() const;
|
||||
void sync() const;
|
||||
void close();
|
||||
void write(const memory_buf_t &buf) const;
|
||||
size_t size() const;
|
||||
const filename_t &filename() const;
|
||||
|
||||
private:
|
||||
const int open_tries_ = 5;
|
||||
const unsigned int open_interval_ = 10;
|
||||
std::FILE *fd_{nullptr};
|
||||
filename_t _filename;
|
||||
filename_t filename_;
|
||||
file_event_handlers event_handlers_;
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -1,120 +1,109 @@
|
||||
//
|
||||
// Created by gabi on 6/15/18.
|
||||
//
|
||||
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
#pragma once
|
||||
|
||||
#include "chrono"
|
||||
#include "spdlog/fmt/fmt.h"
|
||||
#include <chrono>
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
// Some fmt helpers to efficiently format and pad ints and strings
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
namespace fmt_helper {
|
||||
|
||||
template<size_t Buffer_Size>
|
||||
inline void append_str(const std::string &str, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
{
|
||||
auto *str_ptr = str.data();
|
||||
dest.append(str_ptr, str_ptr + str.size());
|
||||
inline void append_string_view(spdlog::string_view_t view, memory_buf_t &dest) {
|
||||
auto *buf_ptr = view.data();
|
||||
dest.append(buf_ptr, buf_ptr + view.size());
|
||||
}
|
||||
|
||||
template<size_t Buffer_Size>
|
||||
inline void append_c_str(const char *c_str, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
{
|
||||
auto len = std::char_traits<char>::length(c_str);
|
||||
dest.append(c_str, c_str + len);
|
||||
}
|
||||
|
||||
template<size_t Buffer_Size1, size_t Buffer_Size2>
|
||||
inline void append_buf(const fmt::basic_memory_buffer<char, Buffer_Size1> &buf, fmt::basic_memory_buffer<char, Buffer_Size2> &dest)
|
||||
{
|
||||
auto *buf_ptr = buf.data();
|
||||
dest.append(buf_ptr, buf_ptr + buf.size());
|
||||
}
|
||||
|
||||
template<typename T, size_t Buffer_Size>
|
||||
inline void append_int(T n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
{
|
||||
template <typename T>
|
||||
inline void append_int(T n, memory_buf_t &dest) {
|
||||
fmt::format_int i(n);
|
||||
dest.append(i.data(), i.data() + i.size());
|
||||
}
|
||||
|
||||
template<size_t Buffer_Size>
|
||||
inline void pad2(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
{
|
||||
if (n > 99)
|
||||
{
|
||||
append_int(n, dest);
|
||||
return;
|
||||
template <typename T>
|
||||
constexpr unsigned int count_digits_fallback(T n) {
|
||||
// taken from fmt: https://github.com/fmtlib/fmt/blob/8.0.1/include/fmt/format.h#L899-L912
|
||||
unsigned int count = 1;
|
||||
for (;;) {
|
||||
// Integer division is slow so do it for a group of four digits instead
|
||||
// of for every digit. The idea comes from the talk by Alexandrescu
|
||||
// "Three Optimization Tips for C++". See speed-test for a comparison.
|
||||
if (n < 10) return count;
|
||||
if (n < 100) return count + 1;
|
||||
if (n < 1000) return count + 2;
|
||||
if (n < 10000) return count + 3;
|
||||
n /= 10000u;
|
||||
count += 4;
|
||||
}
|
||||
if (n > 9) // 10-99
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline unsigned int count_digits(T n) {
|
||||
using count_type = typename std::conditional<(sizeof(T) > sizeof(uint32_t)), uint64_t, uint32_t>::type;
|
||||
|
||||
return static_cast<unsigned int>(fmt::
|
||||
// fmt 7.0.0 renamed the internal namespace to detail.
|
||||
// See: https://github.com/fmtlib/fmt/issues/1538
|
||||
#if FMT_VERSION < 70000
|
||||
internal
|
||||
#else
|
||||
detail
|
||||
#endif
|
||||
::count_digits(static_cast<count_type>(n)));
|
||||
}
|
||||
|
||||
inline void pad2(int n, memory_buf_t &dest) {
|
||||
if (n >= 0 && n < 100) // 0-99
|
||||
{
|
||||
dest.push_back(static_cast<char>('0' + n / 10));
|
||||
dest.push_back(static_cast<char>('0' + n % 10));
|
||||
return;
|
||||
}
|
||||
if (n >= 0) // 0-9
|
||||
} else // unlikely, but just in case, let fmt deal with it
|
||||
{
|
||||
dest.push_back('0');
|
||||
dest.push_back(static_cast<char>('0' + n));
|
||||
return;
|
||||
fmt_lib::format_to(std::back_inserter(dest), SPDLOG_FMT_STRING("{:02}"), n);
|
||||
}
|
||||
// negatives (unlikely, but just in case, let fmt deal with it)
|
||||
fmt::format_to(dest, "{:02}", n);
|
||||
}
|
||||
|
||||
template<size_t Buffer_Size>
|
||||
inline void pad3(int n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
{
|
||||
if (n > 999)
|
||||
{
|
||||
append_int(n, dest);
|
||||
return;
|
||||
}
|
||||
|
||||
if (n > 99) // 100-999
|
||||
{
|
||||
dest.push_back(static_cast<char>('0' + n / 100));
|
||||
pad2(n % 100, dest);
|
||||
return;
|
||||
}
|
||||
if (n > 9) // 10-99
|
||||
{
|
||||
template <typename T>
|
||||
inline void pad_uint(T n, unsigned int width, memory_buf_t &dest) {
|
||||
static_assert(std::is_unsigned<T>::value, "pad_uint must get unsigned T");
|
||||
for (auto digits = count_digits(n); digits < width; digits++) {
|
||||
dest.push_back('0');
|
||||
dest.push_back(static_cast<char>('0' + n / 10));
|
||||
dest.push_back(static_cast<char>('0' + n % 10));
|
||||
return;
|
||||
}
|
||||
if (n >= 0)
|
||||
{
|
||||
dest.push_back('0');
|
||||
dest.push_back('0');
|
||||
dest.push_back(static_cast<char>('0' + n));
|
||||
return;
|
||||
}
|
||||
// negatives (unlikely, but just in case let fmt deal with it)
|
||||
fmt::format_to(dest, "{:03}", n);
|
||||
append_int(n, dest);
|
||||
}
|
||||
|
||||
template<size_t Buffer_Size>
|
||||
inline void pad6(size_t n, fmt::basic_memory_buffer<char, Buffer_Size> &dest)
|
||||
{
|
||||
if (n > 99999)
|
||||
{
|
||||
template <typename T>
|
||||
inline void pad3(T n, memory_buf_t &dest) {
|
||||
static_assert(std::is_unsigned<T>::value, "pad3 must get unsigned T");
|
||||
if (n < 1000) {
|
||||
dest.push_back(static_cast<char>(n / 100 + '0'));
|
||||
n = n % 100;
|
||||
dest.push_back(static_cast<char>((n / 10) + '0'));
|
||||
dest.push_back(static_cast<char>((n % 10) + '0'));
|
||||
} else {
|
||||
append_int(n, dest);
|
||||
return;
|
||||
}
|
||||
pad3(static_cast<int>(n / 1000), dest);
|
||||
pad3(static_cast<int>(n % 1000), dest);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void pad6(T n, memory_buf_t &dest) {
|
||||
pad_uint(n, 6, dest);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void pad9(T n, memory_buf_t &dest) {
|
||||
pad_uint(n, 9, dest);
|
||||
}
|
||||
|
||||
// return fraction of a second of the given time_point.
|
||||
// e.g.
|
||||
// fraction<std::milliseconds>(tp) -> will return the millis part of the second
|
||||
template<typename ToDuration>
|
||||
inline ToDuration time_fraction(const log_clock::time_point &tp)
|
||||
{
|
||||
template <typename ToDuration>
|
||||
inline ToDuration time_fraction(log_clock::time_point tp) {
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::seconds;
|
||||
auto duration = tp.time_since_epoch();
|
||||
@@ -122,6 +111,6 @@ inline ToDuration time_fraction(const log_clock::time_point &tp)
|
||||
return duration_cast<ToDuration>(duration) - duration_cast<ToDuration>(secs);
|
||||
}
|
||||
|
||||
} // namespace fmt_helper
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace fmt_helper
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -1,49 +1,33 @@
|
||||
//
|
||||
// Copyright(c) 2015 Gabi Melman.
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "spdlog/common.h"
|
||||
#include "spdlog/details/os.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
struct log_msg
|
||||
{
|
||||
struct SPDLOG_API log_msg {
|
||||
log_msg() = default;
|
||||
log_msg(log_clock::time_point log_time, const source_loc &loc, string_view_t logger_name, level lvl, string_view_t msg);
|
||||
log_msg(const source_loc &loc, string_view_t logger_name, level lvl, string_view_t msg);
|
||||
log_msg(string_view_t logger_name, level lvl, string_view_t msg);
|
||||
log_msg(const log_msg &other) = default;
|
||||
log_msg &operator=(const log_msg &other) = default;
|
||||
|
||||
log_msg(const std::string *loggers_name, level::level_enum lvl)
|
||||
: logger_name(loggers_name)
|
||||
, level(lvl)
|
||||
#ifndef SPDLOG_NO_DATETIME
|
||||
, time(os::now())
|
||||
#endif
|
||||
|
||||
#ifndef SPDLOG_NO_THREAD_ID
|
||||
, thread_id(os::thread_id())
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
log_msg(const log_msg &other) = delete;
|
||||
log_msg(log_msg &&other) = delete;
|
||||
log_msg &operator=(log_msg &&other) = delete;
|
||||
|
||||
const std::string *logger_name{nullptr};
|
||||
level::level_enum level;
|
||||
string_view_t logger_name;
|
||||
level log_level{level::off};
|
||||
log_clock::time_point time;
|
||||
size_t thread_id;
|
||||
fmt::memory_buffer raw;
|
||||
size_t msg_id;
|
||||
size_t thread_id{0};
|
||||
|
||||
// info about wrapping the formatted text with color (updated by pattern_formatter).
|
||||
// wrapping the formatted text with color (updated by pattern_formatter).
|
||||
mutable size_t color_range_start{0};
|
||||
mutable size_t color_range_end{0};
|
||||
|
||||
source_loc source;
|
||||
string_view_t payload;
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -1,383 +0,0 @@
|
||||
//
|
||||
// Copyright(c) 2015 Gabi Melman.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "spdlog/details/fmt_helper.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
// create logger with given name, sinks and the default pattern formatter
|
||||
// all other ctors will call this one
|
||||
template<typename It>
|
||||
inline spdlog::logger::logger(std::string logger_name, It begin, It end)
|
||||
: name_(std::move(logger_name))
|
||||
, sinks_(begin, end)
|
||||
, level_(level::info)
|
||||
, flush_level_(level::off)
|
||||
, last_err_time_(0)
|
||||
, msg_counter_(1) // message counter will start from 1. 0-message id will be
|
||||
// reserved for controll messages
|
||||
{
|
||||
err_handler_ = [this](const std::string &msg) { this->default_err_handler_(msg); };
|
||||
}
|
||||
|
||||
// ctor with sinks as init list
|
||||
inline spdlog::logger::logger(std::string logger_name, sinks_init_list sinks_list)
|
||||
: logger(std::move(logger_name), sinks_list.begin(), sinks_list.end())
|
||||
{
|
||||
}
|
||||
|
||||
// ctor with single sink
|
||||
inline spdlog::logger::logger(std::string logger_name, spdlog::sink_ptr single_sink)
|
||||
: logger(std::move(logger_name), {std::move(single_sink)})
|
||||
{
|
||||
}
|
||||
|
||||
inline spdlog::logger::~logger() = default;
|
||||
|
||||
inline void spdlog::logger::set_formatter(std::unique_ptr<spdlog::formatter> f)
|
||||
{
|
||||
for (auto &sink : sinks_)
|
||||
{
|
||||
sink->set_formatter(f->clone());
|
||||
}
|
||||
}
|
||||
|
||||
inline void spdlog::logger::set_pattern(std::string pattern, pattern_time_type time_type)
|
||||
{
|
||||
auto new_formatter = details::make_unique<spdlog::pattern_formatter>(std::move(pattern), time_type);
|
||||
set_formatter(std::move(new_formatter));
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void spdlog::logger::log(level::level_enum lvl, const char *fmt, const Args &... args)
|
||||
{
|
||||
if (!should_log(lvl))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
details::log_msg log_msg(&name_, lvl);
|
||||
fmt::format_to(log_msg.raw, fmt, args...);
|
||||
sink_it_(log_msg);
|
||||
}
|
||||
SPDLOG_CATCH_AND_HANDLE
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void spdlog::logger::log(level::level_enum lvl, const char *msg)
|
||||
{
|
||||
if (!should_log(lvl))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
details::log_msg log_msg(&name_, lvl);
|
||||
details::fmt_helper::append_c_str(msg, log_msg.raw);
|
||||
sink_it_(log_msg);
|
||||
}
|
||||
SPDLOG_CATCH_AND_HANDLE
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void spdlog::logger::log(level::level_enum lvl, const T &msg)
|
||||
{
|
||||
if (!should_log(lvl))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
details::log_msg log_msg(&name_, lvl);
|
||||
fmt::format_to(log_msg.raw, "{}", msg);
|
||||
sink_it_(log_msg);
|
||||
}
|
||||
SPDLOG_CATCH_AND_HANDLE
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void spdlog::logger::trace(const char *fmt, const Args &... args)
|
||||
{
|
||||
log(level::trace, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void spdlog::logger::debug(const char *fmt, const Args &... args)
|
||||
{
|
||||
log(level::debug, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void spdlog::logger::info(const char *fmt, const Args &... args)
|
||||
{
|
||||
log(level::info, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void spdlog::logger::warn(const char *fmt, const Args &... args)
|
||||
{
|
||||
log(level::warn, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void spdlog::logger::error(const char *fmt, const Args &... args)
|
||||
{
|
||||
log(level::err, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void spdlog::logger::critical(const char *fmt, const Args &... args)
|
||||
{
|
||||
log(level::critical, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void spdlog::logger::trace(const T &msg)
|
||||
{
|
||||
log(level::trace, msg);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void spdlog::logger::debug(const T &msg)
|
||||
{
|
||||
log(level::debug, msg);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void spdlog::logger::info(const T &msg)
|
||||
{
|
||||
log(level::info, msg);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void spdlog::logger::warn(const T &msg)
|
||||
{
|
||||
log(level::warn, msg);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void spdlog::logger::error(const T &msg)
|
||||
{
|
||||
log(level::err, msg);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void spdlog::logger::critical(const T &msg)
|
||||
{
|
||||
log(level::critical, msg);
|
||||
}
|
||||
|
||||
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
|
||||
inline void wbuf_to_utf8buf(const fmt::wmemory_buffer &wbuf, fmt::memory_buffer &target)
|
||||
{
|
||||
int wbuf_size = static_cast<int>(wbuf.size());
|
||||
if (wbuf_size == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto result_size = ::WideCharToMultiByte(CP_UTF8, 0, wbuf.data(), wbuf_size, NULL, 0, NULL, NULL);
|
||||
|
||||
if (result_size > 0)
|
||||
{
|
||||
target.resize(result_size);
|
||||
::WideCharToMultiByte(CP_UTF8, 0, wbuf.data(), wbuf_size, &target.data()[0], result_size, NULL, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw spdlog::spdlog_ex(fmt::format("WideCharToMultiByte failed. Last error: {}", ::GetLastError()));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void spdlog::logger::log(level::level_enum lvl, const wchar_t *fmt, const Args &... args)
|
||||
{
|
||||
if (!should_log(lvl))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// format to wmemory_buffer and convert to utf8
|
||||
details::log_msg log_msg(&name_, lvl);
|
||||
fmt::wmemory_buffer wbuf;
|
||||
fmt::format_to(wbuf, fmt, args...);
|
||||
wbuf_to_utf8buf(wbuf, log_msg.raw);
|
||||
sink_it_(log_msg);
|
||||
}
|
||||
SPDLOG_CATCH_AND_HANDLE
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void spdlog::logger::trace(const wchar_t *fmt, const Args &... args)
|
||||
{
|
||||
log(level::trace, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void spdlog::logger::debug(const wchar_t *fmt, const Args &... args)
|
||||
{
|
||||
log(level::debug, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void spdlog::logger::info(const wchar_t *fmt, const Args &... args)
|
||||
{
|
||||
log(level::info, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void spdlog::logger::warn(const wchar_t *fmt, const Args &... args)
|
||||
{
|
||||
log(level::warn, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void spdlog::logger::error(const wchar_t *fmt, const Args &... args)
|
||||
{
|
||||
log(level::err, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void spdlog::logger::critical(const wchar_t *fmt, const Args &... args)
|
||||
{
|
||||
log(level::critical, fmt, args...);
|
||||
}
|
||||
|
||||
#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
|
||||
//
|
||||
// name and level
|
||||
//
|
||||
inline const std::string &spdlog::logger::name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
inline void spdlog::logger::set_level(spdlog::level::level_enum log_level)
|
||||
{
|
||||
level_.store(log_level);
|
||||
}
|
||||
|
||||
inline void spdlog::logger::set_error_handler(spdlog::log_err_handler err_handler)
|
||||
{
|
||||
err_handler_ = std::move(err_handler);
|
||||
}
|
||||
|
||||
inline spdlog::log_err_handler spdlog::logger::error_handler()
|
||||
{
|
||||
return err_handler_;
|
||||
}
|
||||
|
||||
inline void spdlog::logger::flush()
|
||||
{
|
||||
try
|
||||
{
|
||||
flush_();
|
||||
}
|
||||
SPDLOG_CATCH_AND_HANDLE
|
||||
}
|
||||
|
||||
inline void spdlog::logger::flush_on(level::level_enum log_level)
|
||||
{
|
||||
flush_level_.store(log_level);
|
||||
}
|
||||
|
||||
inline spdlog::level::level_enum spdlog::logger::flush_level() const
|
||||
{
|
||||
return static_cast<spdlog::level::level_enum>(flush_level_.load(std::memory_order_relaxed));
|
||||
}
|
||||
|
||||
inline bool spdlog::logger::should_flush_(const details::log_msg &msg)
|
||||
{
|
||||
auto flush_level = flush_level_.load(std::memory_order_relaxed);
|
||||
return (msg.level >= flush_level) && (msg.level != level::off);
|
||||
}
|
||||
|
||||
inline spdlog::level::level_enum spdlog::logger::level() const
|
||||
{
|
||||
return static_cast<spdlog::level::level_enum>(level_.load(std::memory_order_relaxed));
|
||||
}
|
||||
|
||||
inline bool spdlog::logger::should_log(spdlog::level::level_enum msg_level) const
|
||||
{
|
||||
return msg_level >= level_.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
//
|
||||
// protected virtual called at end of each user log call (if enabled) by the
|
||||
// line_logger
|
||||
//
|
||||
inline void spdlog::logger::sink_it_(details::log_msg &msg)
|
||||
{
|
||||
#if defined(SPDLOG_ENABLE_MESSAGE_COUNTER)
|
||||
incr_msg_counter_(msg);
|
||||
#endif
|
||||
for (auto &sink : sinks_)
|
||||
{
|
||||
if (sink->should_log(msg.level))
|
||||
{
|
||||
sink->log(msg);
|
||||
}
|
||||
}
|
||||
|
||||
if (should_flush_(msg))
|
||||
{
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
inline void spdlog::logger::flush_()
|
||||
{
|
||||
for (auto &sink : sinks_)
|
||||
{
|
||||
sink->flush();
|
||||
}
|
||||
}
|
||||
|
||||
inline void spdlog::logger::default_err_handler_(const std::string &msg)
|
||||
{
|
||||
auto now = time(nullptr);
|
||||
if (now - last_err_time_ < 60)
|
||||
{
|
||||
return;
|
||||
}
|
||||
last_err_time_ = now;
|
||||
auto tm_time = details::os::localtime(now);
|
||||
char date_buf[100];
|
||||
std::strftime(date_buf, sizeof(date_buf), "%Y-%m-%d %H:%M:%S", &tm_time);
|
||||
fmt::print(stderr, "[*** LOG ERROR ***] [{}] [{}] {}\n", date_buf, name(), msg);
|
||||
}
|
||||
|
||||
inline void spdlog::logger::incr_msg_counter_(details::log_msg &msg)
|
||||
{
|
||||
msg.msg_id = msg_counter_.fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
inline const std::vector<spdlog::sink_ptr> &spdlog::logger::sinks() const
|
||||
{
|
||||
return sinks_;
|
||||
}
|
||||
|
||||
inline std::vector<spdlog::sink_ptr> &spdlog::logger::sinks()
|
||||
{
|
||||
return sinks_;
|
||||
}
|
||||
|
||||
inline std::shared_ptr<spdlog::logger> spdlog::logger::clone(std::string logger_name)
|
||||
{
|
||||
auto cloned = std::make_shared<spdlog::logger>(std::move(logger_name), sinks_.begin(), sinks_.end());
|
||||
cloned->set_level(this->level());
|
||||
cloned->flush_on(this->flush_level());
|
||||
cloned->set_error_handler(this->error_handler());
|
||||
return cloned;
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// Copyright(c) 2018 Gabi Melman.
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
// multi producer-multi consumer blocking queue.
|
||||
// enqueue(..) - will block until room found to put the new message.
|
||||
@@ -12,28 +10,25 @@
|
||||
// dequeue_for(..) - will block until the queue is not empty or timeout have
|
||||
// passed.
|
||||
|
||||
#include "spdlog/details/circular_q.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
|
||||
#include "./circular_q.h"
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
template<typename T>
|
||||
class mpmc_blocking_queue
|
||||
{
|
||||
template <typename T>
|
||||
class mpmc_blocking_queue {
|
||||
public:
|
||||
using item_type = T;
|
||||
explicit mpmc_blocking_queue(size_t max_items)
|
||||
: q_(max_items)
|
||||
{
|
||||
}
|
||||
: q_(max_items) {}
|
||||
|
||||
#ifndef __MINGW32__
|
||||
// try to enqueue and block if no room left
|
||||
void enqueue(T &&item)
|
||||
{
|
||||
void enqueue(T &&item) {
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(queue_mutex_);
|
||||
pop_cv_.wait(lock, [this] { return !this->q_.full(); });
|
||||
@@ -42,9 +37,8 @@ public:
|
||||
push_cv_.notify_one();
|
||||
}
|
||||
|
||||
// enqueue immediately. overrun oldest message in the queue if no room left.
|
||||
void enqueue_nowait(T &&item)
|
||||
{
|
||||
// enqueue immediately. overrun the oldest message in the queue if no room left.
|
||||
void enqueue_nowait(T &&item) {
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(queue_mutex_);
|
||||
q_.push_back(std::move(item));
|
||||
@@ -52,29 +46,55 @@ public:
|
||||
push_cv_.notify_one();
|
||||
}
|
||||
|
||||
// try to dequeue item. if no item found. wait upto timeout and try again
|
||||
// Return true, if succeeded dequeue item, false otherwise
|
||||
bool dequeue_for(T &popped_item, std::chrono::milliseconds wait_duration)
|
||||
{
|
||||
void enqueue_if_have_room(T &&item) {
|
||||
bool pushed = false;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(queue_mutex_);
|
||||
if (!push_cv_.wait_for(lock, wait_duration, [this] { return !this->q_.empty(); }))
|
||||
{
|
||||
if (!q_.full()) {
|
||||
q_.push_back(std::move(item));
|
||||
pushed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (pushed) {
|
||||
push_cv_.notify_one();
|
||||
} else {
|
||||
++discard_counter_;
|
||||
}
|
||||
}
|
||||
|
||||
// dequeue with a timeout.
|
||||
// Return true, if succeeded dequeue item, false otherwise
|
||||
bool dequeue_for(T &popped_item, std::chrono::milliseconds wait_duration) {
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(queue_mutex_);
|
||||
if (!push_cv_.wait_for(lock, wait_duration, [this] { return !this->q_.empty(); })) {
|
||||
return false;
|
||||
}
|
||||
q_.pop_front(popped_item);
|
||||
popped_item = std::move(q_.front());
|
||||
q_.pop_front();
|
||||
}
|
||||
pop_cv_.notify_one();
|
||||
return true;
|
||||
}
|
||||
|
||||
// blocking dequeue without a timeout.
|
||||
void dequeue(T &popped_item) {
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(queue_mutex_);
|
||||
push_cv_.wait(lock, [this] { return !this->q_.empty(); });
|
||||
popped_item = std::move(q_.front());
|
||||
q_.pop_front();
|
||||
}
|
||||
pop_cv_.notify_one();
|
||||
}
|
||||
|
||||
#else
|
||||
// apparently mingw deadlocks if the mutex is released before cv.notify_one(),
|
||||
// so release the mutex at the very end each function.
|
||||
|
||||
// try to enqueue and block if no room left
|
||||
void enqueue(T &&item)
|
||||
{
|
||||
void enqueue(T &&item) {
|
||||
std::unique_lock<std::mutex> lock(queue_mutex_);
|
||||
pop_cv_.wait(lock, [this] { return !this->q_.full(); });
|
||||
q_.push_back(std::move(item));
|
||||
@@ -82,40 +102,76 @@ public:
|
||||
}
|
||||
|
||||
// enqueue immediately. overrun oldest message in the queue if no room left.
|
||||
void enqueue_nowait(T &&item)
|
||||
{
|
||||
void enqueue_nowait(T &&item) {
|
||||
std::unique_lock<std::mutex> lock(queue_mutex_);
|
||||
q_.push_back(std::move(item));
|
||||
push_cv_.notify_one();
|
||||
}
|
||||
|
||||
// try to dequeue item. if no item found. wait upto timeout and try again
|
||||
// Return true, if succeeded dequeue item, false otherwise
|
||||
bool dequeue_for(T &popped_item, std::chrono::milliseconds wait_duration)
|
||||
{
|
||||
void enqueue_if_have_room(T &&item) {
|
||||
bool pushed = false;
|
||||
std::unique_lock<std::mutex> lock(queue_mutex_);
|
||||
if (!push_cv_.wait_for(lock, wait_duration, [this] { return !this->q_.empty(); }))
|
||||
{
|
||||
if (!q_.full()) {
|
||||
q_.push_back(std::move(item));
|
||||
pushed = true;
|
||||
}
|
||||
|
||||
if (pushed) {
|
||||
push_cv_.notify_one();
|
||||
} else {
|
||||
++discard_counter_;
|
||||
}
|
||||
}
|
||||
|
||||
// dequeue with a timeout.
|
||||
// Return true, if succeeded dequeue item, false otherwise
|
||||
bool dequeue_for(T &popped_item, std::chrono::milliseconds wait_duration) {
|
||||
std::unique_lock<std::mutex> lock(queue_mutex_);
|
||||
if (!push_cv_.wait_for(lock, wait_duration, [this] { return !this->q_.empty(); })) {
|
||||
return false;
|
||||
}
|
||||
q_.pop_front(popped_item);
|
||||
popped_item = std::move(q_.front());
|
||||
q_.pop_front();
|
||||
pop_cv_.notify_one();
|
||||
return true;
|
||||
}
|
||||
|
||||
// blocking dequeue without a timeout.
|
||||
void dequeue(T &popped_item) {
|
||||
std::unique_lock<std::mutex> lock(queue_mutex_);
|
||||
push_cv_.wait(lock, [this] { return !this->q_.empty(); });
|
||||
popped_item = std::move(q_.front());
|
||||
q_.pop_front();
|
||||
pop_cv_.notify_one();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
size_t overrun_counter()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(queue_mutex_);
|
||||
size_t overrun_counter() {
|
||||
std::lock_guard<std::mutex> lock(queue_mutex_);
|
||||
return q_.overrun_counter();
|
||||
}
|
||||
|
||||
size_t discard_counter() { return discard_counter_.load(std::memory_order_relaxed); }
|
||||
|
||||
size_t size() {
|
||||
std::lock_guard<std::mutex> lock(queue_mutex_);
|
||||
return q_.size();
|
||||
}
|
||||
|
||||
void reset_overrun_counter() {
|
||||
std::lock_guard<std::mutex> lock(queue_mutex_);
|
||||
q_.reset_overrun_counter();
|
||||
}
|
||||
|
||||
void reset_discard_counter() { discard_counter_.store(0, std::memory_order_relaxed); }
|
||||
|
||||
private:
|
||||
std::mutex queue_mutex_;
|
||||
std::condition_variable push_cv_;
|
||||
std::condition_variable pop_cv_;
|
||||
spdlog::details::circular_q<T> q_;
|
||||
std::atomic<size_t> discard_counter_{0};
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -1,45 +1,38 @@
|
||||
//
|
||||
// Copyright(c) 2015 Gabi Melman.
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
// null, no cost dummy "mutex" and dummy "atomic" int
|
||||
#include <utility>
|
||||
|
||||
// null, no cost dummy "mutex" and dummy "atomic" log level
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
struct null_mutex
|
||||
{
|
||||
void lock() {}
|
||||
void unlock() {}
|
||||
bool try_lock()
|
||||
{
|
||||
return true;
|
||||
struct null_mutex {
|
||||
void lock() const {}
|
||||
void unlock() const {}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct null_atomic {
|
||||
T value;
|
||||
|
||||
null_atomic() = default;
|
||||
|
||||
explicit constexpr null_atomic(T new_value)
|
||||
: value(new_value) {}
|
||||
|
||||
[[nodiscard]] T load(std::memory_order = std::memory_order_seq_cst) const { return value; }
|
||||
|
||||
void store(T new_value, std::memory_order = std::memory_order_seq_cst) { value = new_value; }
|
||||
|
||||
T exchange(T new_value, std::memory_order = std::memory_order_seq_cst) {
|
||||
std::swap(new_value, value);
|
||||
return new_value; // return value before the call
|
||||
}
|
||||
};
|
||||
|
||||
struct null_atomic_int
|
||||
{
|
||||
int value;
|
||||
null_atomic_int() = default;
|
||||
|
||||
explicit null_atomic_int(int val)
|
||||
: value(val)
|
||||
{
|
||||
}
|
||||
|
||||
int load(std::memory_order) const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
void store(int val)
|
||||
{
|
||||
value = val;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -1,422 +1,128 @@
|
||||
//
|
||||
// Copyright(c) 2015 Gabi Melman.
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ctime> // std::time_t
|
||||
#include <tuple>
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <thread>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX // prevent windows redefining min/max
|
||||
#endif
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <io.h> // _get_osfhandle and _isatty support
|
||||
#include <process.h> // _get_pid support
|
||||
#include <windows.h>
|
||||
|
||||
#ifdef __MINGW32__
|
||||
#include <share.h>
|
||||
#endif
|
||||
|
||||
#else // unix
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <sys/syscall.h> //Use gettid() syscall under linux to get thread id
|
||||
|
||||
#elif __FreeBSD__
|
||||
#include <sys/thr.h> //Use thr_self() syscall under FreeBSD to get thread id
|
||||
#endif
|
||||
|
||||
#endif // unix
|
||||
|
||||
#ifndef __has_feature // Clang - feature checking macros.
|
||||
#define __has_feature(x) 0 // Compatibility with non-clang compilers.
|
||||
#endif
|
||||
#include "../filename_t.h"
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
namespace os {
|
||||
|
||||
inline spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT
|
||||
{
|
||||
SPDLOG_API spdlog::log_clock::time_point now() noexcept;
|
||||
|
||||
#if defined __linux__ && defined SPDLOG_CLOCK_COARSE
|
||||
timespec ts;
|
||||
::clock_gettime(CLOCK_REALTIME_COARSE, &ts);
|
||||
return std::chrono::time_point<log_clock, typename log_clock::duration>(
|
||||
std::chrono::duration_cast<typename log_clock::duration>(std::chrono::seconds(ts.tv_sec) + std::chrono::nanoseconds(ts.tv_nsec)));
|
||||
SPDLOG_API std::tm localtime(const std::time_t &time_tt) noexcept;
|
||||
|
||||
#else
|
||||
return log_clock::now();
|
||||
#endif
|
||||
}
|
||||
inline std::tm localtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT
|
||||
{
|
||||
SPDLOG_API std::tm localtime() noexcept;
|
||||
|
||||
SPDLOG_API std::tm gmtime(const std::time_t &time_tt) noexcept;
|
||||
|
||||
SPDLOG_API std::tm gmtime() noexcept;
|
||||
|
||||
// eol definition and folder separator for the current os
|
||||
#ifdef _WIN32
|
||||
std::tm tm;
|
||||
localtime_s(&tm, &time_tt);
|
||||
constexpr static const char *default_eol = "\r\n";
|
||||
#else
|
||||
std::tm tm;
|
||||
localtime_r(&time_tt, &tm);
|
||||
constexpr static const char *default_eol = "\n";
|
||||
#endif
|
||||
return tm;
|
||||
}
|
||||
|
||||
inline std::tm localtime() SPDLOG_NOEXCEPT
|
||||
{
|
||||
std::time_t now_t = time(nullptr);
|
||||
return localtime(now_t);
|
||||
}
|
||||
|
||||
inline std::tm gmtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
std::tm tm;
|
||||
gmtime_s(&tm, &time_tt);
|
||||
#else
|
||||
std::tm tm;
|
||||
gmtime_r(&time_tt, &tm);
|
||||
#endif
|
||||
return tm;
|
||||
}
|
||||
|
||||
inline std::tm gmtime() SPDLOG_NOEXCEPT
|
||||
{
|
||||
std::time_t now_t = time(nullptr);
|
||||
return gmtime(now_t);
|
||||
}
|
||||
|
||||
// eol definition
|
||||
#if !defined(SPDLOG_EOL)
|
||||
#ifdef _WIN32
|
||||
#define SPDLOG_EOL "\r\n"
|
||||
#else
|
||||
#define SPDLOG_EOL "\n"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
SPDLOG_CONSTEXPR static const char *default_eol = SPDLOG_EOL;
|
||||
|
||||
// folder separator
|
||||
#ifdef _WIN32
|
||||
SPDLOG_CONSTEXPR static const char folder_sep = '\\';
|
||||
#else
|
||||
SPDLOG_CONSTEXPR static const char folder_sep = '/';
|
||||
#endif
|
||||
|
||||
inline void prevent_child_fd(FILE *f)
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
#if !defined(__cplusplus_winrt)
|
||||
auto file_handle = (HANDLE)_get_osfhandle(_fileno(f));
|
||||
if (!::SetHandleInformation(file_handle, HANDLE_FLAG_INHERIT, 0))
|
||||
throw spdlog_ex("SetHandleInformation failed", errno);
|
||||
#endif
|
||||
#else
|
||||
auto fd = fileno(f);
|
||||
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
|
||||
{
|
||||
throw spdlog_ex("fcntl with FD_CLOEXEC failed", errno);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// fopen_s on non windows for writing
|
||||
inline bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
#ifdef SPDLOG_WCHAR_FILENAMES
|
||||
*fp = _wfsopen((filename.c_str()), mode.c_str(), _SH_DENYNO);
|
||||
#else
|
||||
*fp = _fsopen((filename.c_str()), mode.c_str(), _SH_DENYNO);
|
||||
#endif
|
||||
#else // unix
|
||||
*fp = fopen((filename.c_str()), mode.c_str());
|
||||
#endif
|
||||
|
||||
#ifdef SPDLOG_PREVENT_CHILD_FD
|
||||
if (*fp != nullptr)
|
||||
{
|
||||
prevent_child_fd(*fp);
|
||||
}
|
||||
#endif
|
||||
return *fp == nullptr;
|
||||
}
|
||||
|
||||
inline int remove(const filename_t &filename) SPDLOG_NOEXCEPT
|
||||
{
|
||||
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
|
||||
return _wremove(filename.c_str());
|
||||
#else
|
||||
return std::remove(filename.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
inline int rename(const filename_t &filename1, const filename_t &filename2) SPDLOG_NOEXCEPT
|
||||
{
|
||||
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
|
||||
return _wrename(filename1.c_str(), filename2.c_str());
|
||||
#else
|
||||
return std::rename(filename1.c_str(), filename2.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
// Return if file exists
|
||||
inline bool file_exists(const filename_t &filename) SPDLOG_NOEXCEPT
|
||||
{
|
||||
#ifdef _WIN32
|
||||
#ifdef SPDLOG_WCHAR_FILENAMES
|
||||
auto attribs = GetFileAttributesW(filename.c_str());
|
||||
#else
|
||||
auto attribs = GetFileAttributesA(filename.c_str());
|
||||
#endif
|
||||
return (attribs != INVALID_FILE_ATTRIBUTES && !(attribs & FILE_ATTRIBUTE_DIRECTORY));
|
||||
#else // common linux/unix all have the stat system call
|
||||
struct stat buffer;
|
||||
return (stat(filename.c_str(), &buffer) == 0);
|
||||
#endif
|
||||
}
|
||||
SPDLOG_API bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode);
|
||||
|
||||
// Return file size according to open FILE* object
|
||||
inline size_t filesize(FILE *f)
|
||||
{
|
||||
if (f == nullptr)
|
||||
{
|
||||
throw spdlog_ex("Failed getting file size. fd is null");
|
||||
}
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||
int fd = _fileno(f);
|
||||
#if _WIN64 // 64 bits
|
||||
struct _stat64 st;
|
||||
if (_fstat64(fd, &st) == 0)
|
||||
{
|
||||
return st.st_size;
|
||||
}
|
||||
|
||||
#else // windows 32 bits
|
||||
long ret = _filelength(fd);
|
||||
if (ret >= 0)
|
||||
{
|
||||
return static_cast<size_t>(ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#else // unix
|
||||
int fd = fileno(f);
|
||||
// 64 bits(but not in osx or cygwin, where fstat64 is deprecated)
|
||||
#if !defined(__FreeBSD__) && !defined(__APPLE__) && (defined(__x86_64__) || defined(__ppc64__)) && !defined(__CYGWIN__)
|
||||
struct stat64 st;
|
||||
if (fstat64(fd, &st) == 0)
|
||||
{
|
||||
return static_cast<size_t>(st.st_size);
|
||||
}
|
||||
#else // unix 32 bits or cygwin
|
||||
struct stat st;
|
||||
|
||||
if (fstat(fd, &st) == 0)
|
||||
{
|
||||
return static_cast<size_t>(st.st_size);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
throw spdlog_ex("Failed getting file size from fd", errno);
|
||||
}
|
||||
SPDLOG_API size_t filesize(FILE *f);
|
||||
|
||||
// Return utc offset in minutes or throw spdlog_ex on failure
|
||||
inline int utc_minutes_offset(const std::tm &tm = details::os::localtime())
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
#if _WIN32_WINNT < _WIN32_WINNT_WS08
|
||||
TIME_ZONE_INFORMATION tzinfo;
|
||||
auto rv = GetTimeZoneInformation(&tzinfo);
|
||||
#else
|
||||
DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
|
||||
auto rv = GetDynamicTimeZoneInformation(&tzinfo);
|
||||
#endif
|
||||
if (rv == TIME_ZONE_ID_INVALID)
|
||||
throw spdlog::spdlog_ex("Failed getting timezone info. ", errno);
|
||||
|
||||
int offset = -tzinfo.Bias;
|
||||
if (tm.tm_isdst)
|
||||
{
|
||||
offset -= tzinfo.DaylightBias;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset -= tzinfo.StandardBias;
|
||||
}
|
||||
return offset;
|
||||
#else
|
||||
|
||||
#if defined(sun) || defined(__sun) || defined(_AIX)
|
||||
// 'tm_gmtoff' field is BSD extension and it's missing on SunOS/Solaris
|
||||
struct helper
|
||||
{
|
||||
static long int calculate_gmt_offset(const std::tm &localtm = details::os::localtime(), const std::tm &gmtm = details::os::gmtime())
|
||||
{
|
||||
int local_year = localtm.tm_year + (1900 - 1);
|
||||
int gmt_year = gmtm.tm_year + (1900 - 1);
|
||||
|
||||
long int days = (
|
||||
// difference in day of year
|
||||
localtm.tm_yday -
|
||||
gmtm.tm_yday
|
||||
|
||||
// + intervening leap days
|
||||
+ ((local_year >> 2) - (gmt_year >> 2)) - (local_year / 100 - gmt_year / 100) +
|
||||
((local_year / 100 >> 2) - (gmt_year / 100 >> 2))
|
||||
|
||||
// + difference in years * 365 */
|
||||
+ (long int)(local_year - gmt_year) * 365);
|
||||
|
||||
long int hours = (24 * days) + (localtm.tm_hour - gmtm.tm_hour);
|
||||
long int mins = (60 * hours) + (localtm.tm_min - gmtm.tm_min);
|
||||
long int secs = (60 * mins) + (localtm.tm_sec - gmtm.tm_sec);
|
||||
|
||||
return secs;
|
||||
}
|
||||
};
|
||||
|
||||
auto offset_seconds = helper::calculate_gmt_offset(tm);
|
||||
#else
|
||||
auto offset_seconds = tm.tm_gmtoff;
|
||||
#endif
|
||||
|
||||
return static_cast<int>(offset_seconds / 60);
|
||||
#endif
|
||||
}
|
||||
SPDLOG_API int utc_minutes_offset(const std::tm &tm = details::os::localtime());
|
||||
|
||||
// Return current thread id as size_t
|
||||
// It exists because the std::this_thread::get_id() is much slower(especially
|
||||
// under VS 2013)
|
||||
inline size_t _thread_id() SPDLOG_NOEXCEPT
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return static_cast<size_t>(::GetCurrentThreadId());
|
||||
#elif __linux__
|
||||
#if defined(__ANDROID__) && defined(__ANDROID_API__) && (__ANDROID_API__ < 21)
|
||||
#define SYS_gettid __NR_gettid
|
||||
#endif
|
||||
return static_cast<size_t>(syscall(SYS_gettid));
|
||||
#elif __FreeBSD__
|
||||
long tid;
|
||||
thr_self(&tid);
|
||||
return static_cast<size_t>(tid);
|
||||
#elif __APPLE__
|
||||
uint64_t tid;
|
||||
pthread_threadid_np(nullptr, &tid);
|
||||
return static_cast<size_t>(tid);
|
||||
#else // Default to standard C++11 (other Unix)
|
||||
return static_cast<size_t>(std::hash<std::thread::id>()(std::this_thread::get_id()));
|
||||
#endif
|
||||
}
|
||||
SPDLOG_API size_t _thread_id() noexcept;
|
||||
|
||||
// Return current thread id as size_t (from thread local storage)
|
||||
inline size_t thread_id() SPDLOG_NOEXCEPT
|
||||
{
|
||||
#if defined(SPDLOG_DISABLE_TID_CACHING) || (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__cplusplus_winrt) || \
|
||||
(defined(__clang__) && !__has_feature(cxx_thread_local))
|
||||
return _thread_id();
|
||||
#else // cache thread id in tls
|
||||
static thread_local const size_t tid = _thread_id();
|
||||
return tid;
|
||||
#endif
|
||||
}
|
||||
SPDLOG_API size_t thread_id() noexcept;
|
||||
|
||||
// This is avoid msvc issue in sleep_for that happens if the clock changes.
|
||||
// See https://github.com/gabime/spdlog/issues/609
|
||||
inline void sleep_for_millis(int milliseconds) SPDLOG_NOEXCEPT
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
::Sleep(milliseconds);
|
||||
#else
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
|
||||
#endif
|
||||
}
|
||||
SPDLOG_API void sleep_for_millis(unsigned int milliseconds) noexcept;
|
||||
|
||||
// wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined)
|
||||
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
|
||||
#define SPDLOG_FILENAME_T(s) L##s
|
||||
inline std::string filename_to_str(const filename_t &filename)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> c;
|
||||
return c.to_bytes(filename);
|
||||
}
|
||||
#else
|
||||
#define SPDLOG_FILENAME_T(s) s
|
||||
inline std::string filename_to_str(const filename_t &filename)
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline int pid()
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
return static_cast<int>(::GetCurrentProcessId());
|
||||
#else
|
||||
return static_cast<int>(::getpid());
|
||||
#endif
|
||||
}
|
||||
// Return pid
|
||||
SPDLOG_API int pid() noexcept;
|
||||
|
||||
// Determine if the terminal supports colors
|
||||
// Source: https://github.com/agauniyal/rang/
|
||||
inline bool is_color_terminal() SPDLOG_NOEXCEPT
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return true;
|
||||
#else
|
||||
static constexpr const char *Terms[] = {
|
||||
"ansi", "color", "console", "cygwin", "gnome", "konsole", "kterm", "linux", "msys", "putty", "rxvt", "screen", "vt100", "xterm"};
|
||||
SPDLOG_API bool is_color_terminal() noexcept;
|
||||
|
||||
const char *env_p = std::getenv("TERM");
|
||||
if (env_p == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static const bool result =
|
||||
std::any_of(std::begin(Terms), std::end(Terms), [&](const char *term) { return std::strstr(env_p, term) != nullptr; });
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Detrmine if the terminal attached
|
||||
// Determine if the terminal attached
|
||||
// Source: https://github.com/agauniyal/rang/
|
||||
inline bool in_terminal(FILE *file) SPDLOG_NOEXCEPT
|
||||
{
|
||||
SPDLOG_API bool in_terminal(FILE *file) noexcept;
|
||||
|
||||
#ifdef _WIN32
|
||||
return _isatty(_fileno(file)) != 0;
|
||||
#else
|
||||
return isatty(fileno(file)) != 0;
|
||||
#if (defined _WIN32)
|
||||
SPDLOG_API void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target);
|
||||
SPDLOG_API void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target);
|
||||
#endif
|
||||
}
|
||||
} // namespace os
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
// non thread safe, cross platform getenv/getenv_s
|
||||
// return empty string if field not found
|
||||
SPDLOG_API std::string getenv(const char *field);
|
||||
|
||||
// Do fsync by FILE objectpointer.
|
||||
// Return true on success.
|
||||
SPDLOG_API bool fsync(FILE *fp);
|
||||
|
||||
// Do non-locking fwrite if possible by the os or use the regular locking fwrite
|
||||
// Return true on success.
|
||||
SPDLOG_API bool fwrite_bytes(const void *ptr, const size_t n_bytes, FILE *fp);
|
||||
|
||||
//
|
||||
// std::filesystem wrapper functions
|
||||
//
|
||||
|
||||
// Return directory name from given path or empty string
|
||||
// "abc/file" => "abc"
|
||||
// "abc/" => "abc"
|
||||
// "abc" => ""
|
||||
SPDLOG_API filename_t dir_name(const filename_t &path);
|
||||
|
||||
// Create a dir from the given path.
|
||||
// Return true if succeeded or if this dir already exists.
|
||||
SPDLOG_API bool create_dir(const filename_t &path);
|
||||
|
||||
// Remove filename. return true on success
|
||||
SPDLOG_API bool remove(const filename_t &filename);
|
||||
|
||||
// Remove file if exists. return 0 on success
|
||||
// Note: Non atomic (might return failure to delete if concurrently deleted by other process/thread)
|
||||
SPDLOG_API bool remove_if_exists(const filename_t &filename);
|
||||
|
||||
// Rename file. return true on success
|
||||
SPDLOG_API bool rename(const filename_t &filename1, const filename_t &filename2) noexcept;
|
||||
|
||||
// Return if file exists.
|
||||
SPDLOG_API bool path_exists(const filename_t &filename) noexcept;
|
||||
|
||||
// Return file path and its extension:
|
||||
//
|
||||
// "mylog.txt" => ("mylog", ".txt")
|
||||
// "mylog" => ("mylog", "")
|
||||
// "mylog." => ("mylog.", "")
|
||||
// "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt")
|
||||
//
|
||||
// the starting dot in filenames is ignored (hidden files):
|
||||
//
|
||||
// ".mylog" => (".mylog". "")
|
||||
// "my_folder/.mylog" => ("my_folder/.mylog", "")
|
||||
// "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt")
|
||||
SPDLOG_API std::tuple<filename_t, filename_t> split_by_extension(const filename_t &fname);
|
||||
|
||||
// Try tp convert filename to string. Return "??" if failed
|
||||
SPDLOG_API std::string filename_to_str(const filename_t &filename);
|
||||
|
||||
} // namespace os
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -1,774 +0,0 @@
|
||||
//
|
||||
// Copyright(c) 2015 Gabi Melman.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "spdlog/details/fmt_helper.h"
|
||||
#include "spdlog/details/log_msg.h"
|
||||
#include "spdlog/details/os.h"
|
||||
#include "spdlog/fmt/fmt.h"
|
||||
#include "spdlog/formatter.h"
|
||||
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
class flag_formatter
|
||||
{
|
||||
public:
|
||||
virtual ~flag_formatter() = default;
|
||||
virtual void format(const details::log_msg &msg, const std::tm &tm_time, fmt::memory_buffer &dest) = 0;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// name & level pattern appenders
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
class name_formatter : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_str(*msg.logger_name, dest);
|
||||
}
|
||||
};
|
||||
|
||||
// log level appender
|
||||
class level_formatter : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_c_str(level::to_c_str(msg.level), dest);
|
||||
}
|
||||
};
|
||||
|
||||
// short log level appender
|
||||
class short_level_formatter : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_c_str(level::to_short_c_str(msg.level), dest);
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Date time pattern appenders
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const char *ampm(const tm &t)
|
||||
{
|
||||
return t.tm_hour >= 12 ? "PM" : "AM";
|
||||
}
|
||||
|
||||
static int to12h(const tm &t)
|
||||
{
|
||||
return t.tm_hour > 12 ? t.tm_hour - 12 : t.tm_hour;
|
||||
}
|
||||
|
||||
// Abbreviated weekday name
|
||||
static const char *days[]{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
||||
class a_formatter : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_c_str(days[tm_time.tm_wday], dest);
|
||||
}
|
||||
};
|
||||
|
||||
// Full weekday name
|
||||
static const char *full_days[]{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
|
||||
class A_formatter : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_c_str(full_days[tm_time.tm_wday], dest);
|
||||
}
|
||||
};
|
||||
|
||||
// Abbreviated month
|
||||
static const char *months[]{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"};
|
||||
class b_formatter : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_c_str(months[tm_time.tm_mon], dest);
|
||||
}
|
||||
};
|
||||
|
||||
// Full month name
|
||||
static const char *full_months[]{
|
||||
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
|
||||
class B_formatter : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_c_str(full_months[tm_time.tm_mon], dest);
|
||||
}
|
||||
};
|
||||
|
||||
// Date and time representation (Thu Aug 23 15:35:46 2014)
|
||||
class c_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
// fmt::format_to(dest, "{} {} {} ", days[tm_time.tm_wday],
|
||||
// months[tm_time.tm_mon], tm_time.tm_mday);
|
||||
// date
|
||||
fmt_helper::append_str(days[tm_time.tm_wday], dest);
|
||||
dest.push_back(' ');
|
||||
fmt_helper::append_str(months[tm_time.tm_mon], dest);
|
||||
dest.push_back(' ');
|
||||
fmt_helper::append_int(tm_time.tm_mday, dest);
|
||||
dest.push_back(' ');
|
||||
// time
|
||||
|
||||
fmt_helper::pad2(tm_time.tm_hour, dest);
|
||||
dest.push_back(':');
|
||||
fmt_helper::pad2(tm_time.tm_min, dest);
|
||||
dest.push_back(':');
|
||||
fmt_helper::pad2(tm_time.tm_sec, dest);
|
||||
dest.push_back(' ');
|
||||
fmt_helper::append_int(tm_time.tm_year + 1900, dest);
|
||||
}
|
||||
};
|
||||
|
||||
// year - 2 digit
|
||||
class C_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::pad2(tm_time.tm_year % 100, dest);
|
||||
}
|
||||
};
|
||||
|
||||
// Short MM/DD/YY date, equivalent to %m/%d/%y 08/23/01
|
||||
class D_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::pad2(tm_time.tm_mon + 1, dest);
|
||||
dest.push_back('/');
|
||||
fmt_helper::pad2(tm_time.tm_mday, dest);
|
||||
dest.push_back('/');
|
||||
fmt_helper::pad2(tm_time.tm_year % 100, dest);
|
||||
}
|
||||
};
|
||||
|
||||
// year - 4 digit
|
||||
class Y_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_int(tm_time.tm_year + 1900, dest);
|
||||
}
|
||||
};
|
||||
|
||||
// month 1-12
|
||||
class m_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::pad2(tm_time.tm_mon + 1, dest);
|
||||
}
|
||||
};
|
||||
|
||||
// day of month 1-31
|
||||
class d_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::pad2(tm_time.tm_mday, dest);
|
||||
}
|
||||
};
|
||||
|
||||
// hours in 24 format 0-23
|
||||
class H_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::pad2(tm_time.tm_hour, dest);
|
||||
}
|
||||
};
|
||||
|
||||
// hours in 12 format 1-12
|
||||
class I_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::pad2(to12h(tm_time), dest);
|
||||
}
|
||||
};
|
||||
|
||||
// minutes 0-59
|
||||
class M_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::pad2(tm_time.tm_min, dest);
|
||||
}
|
||||
};
|
||||
|
||||
// seconds 0-59
|
||||
class S_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::pad2(tm_time.tm_sec, dest);
|
||||
}
|
||||
};
|
||||
|
||||
// milliseconds
|
||||
class e_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
auto millis = fmt_helper::time_fraction<std::chrono::milliseconds>(msg.time);
|
||||
fmt_helper::pad3(static_cast<int>(millis.count()), dest);
|
||||
}
|
||||
};
|
||||
|
||||
// microseconds
|
||||
class f_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
auto micros = fmt_helper::time_fraction<std::chrono::microseconds>(msg.time);
|
||||
fmt_helper::pad6(static_cast<size_t>(micros.count()), dest);
|
||||
}
|
||||
};
|
||||
|
||||
// nanoseconds
|
||||
class F_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
auto ns = fmt_helper::time_fraction<std::chrono::nanoseconds>(msg.time);
|
||||
fmt::format_to(dest, "{:09}", ns.count());
|
||||
}
|
||||
};
|
||||
|
||||
// seconds since epoch
|
||||
class E_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
auto duration = msg.time.time_since_epoch();
|
||||
auto seconds = std::chrono::duration_cast<std::chrono::seconds>(duration).count();
|
||||
fmt_helper::append_int(seconds, dest);
|
||||
}
|
||||
};
|
||||
|
||||
// AM/PM
|
||||
class p_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_c_str(ampm(tm_time), dest);
|
||||
}
|
||||
};
|
||||
|
||||
// 12 hour clock 02:55:02 pm
|
||||
class r_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::pad2(to12h(tm_time), dest);
|
||||
dest.push_back(':');
|
||||
fmt_helper::pad2(tm_time.tm_min, dest);
|
||||
dest.push_back(':');
|
||||
fmt_helper::pad2(tm_time.tm_sec, dest);
|
||||
dest.push_back(' ');
|
||||
fmt_helper::append_c_str(ampm(tm_time), dest);
|
||||
}
|
||||
};
|
||||
|
||||
// 24-hour HH:MM time, equivalent to %H:%M
|
||||
class R_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::pad2(tm_time.tm_hour, dest);
|
||||
dest.push_back(':');
|
||||
fmt_helper::pad2(tm_time.tm_min, dest);
|
||||
}
|
||||
};
|
||||
|
||||
// ISO 8601 time format (HH:MM:SS), equivalent to %H:%M:%S
|
||||
class T_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
// fmt::format_to(dest, "{:02}:{:02}:{:02}", tm_time.tm_hour,
|
||||
// tm_time.tm_min, tm_time.tm_sec);
|
||||
fmt_helper::pad2(tm_time.tm_hour, dest);
|
||||
dest.push_back(':');
|
||||
fmt_helper::pad2(tm_time.tm_min, dest);
|
||||
dest.push_back(':');
|
||||
fmt_helper::pad2(tm_time.tm_sec, dest);
|
||||
}
|
||||
};
|
||||
|
||||
// ISO 8601 offset from UTC in timezone (+-HH:MM)
|
||||
class z_formatter final : public flag_formatter
|
||||
{
|
||||
public:
|
||||
const std::chrono::seconds cache_refresh = std::chrono::seconds(5);
|
||||
|
||||
z_formatter() = default;
|
||||
z_formatter(const z_formatter &) = delete;
|
||||
z_formatter &operator=(const z_formatter &) = delete;
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
#ifdef _WIN32
|
||||
int total_minutes = get_cached_offset(msg, tm_time);
|
||||
#else
|
||||
// No need to chache under gcc,
|
||||
// it is very fast (already stored in tm.tm_gmtoff)
|
||||
(void)(msg);
|
||||
int total_minutes = os::utc_minutes_offset(tm_time);
|
||||
#endif
|
||||
bool is_negative = total_minutes < 0;
|
||||
if (is_negative)
|
||||
{
|
||||
total_minutes = -total_minutes;
|
||||
dest.push_back('-');
|
||||
}
|
||||
else
|
||||
{
|
||||
dest.push_back('+');
|
||||
}
|
||||
|
||||
fmt_helper::pad2(total_minutes / 60, dest); // hours
|
||||
dest.push_back(':');
|
||||
fmt_helper::pad2(total_minutes % 60, dest); // minutes
|
||||
}
|
||||
|
||||
private:
|
||||
log_clock::time_point last_update_{std::chrono::seconds(0)};
|
||||
#ifdef _WIN32
|
||||
int offset_minutes_{0};
|
||||
|
||||
int get_cached_offset(const log_msg &msg, const std::tm &tm_time)
|
||||
{
|
||||
if (msg.time - last_update_ >= cache_refresh)
|
||||
{
|
||||
offset_minutes_ = os::utc_minutes_offset(tm_time);
|
||||
last_update_ = msg.time;
|
||||
}
|
||||
return offset_minutes_;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
// Thread id
|
||||
class t_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::pad6(msg.thread_id, dest);
|
||||
}
|
||||
};
|
||||
|
||||
// Current pid
|
||||
class pid_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_int(details::os::pid(), dest);
|
||||
}
|
||||
};
|
||||
|
||||
// message counter formatter
|
||||
class i_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::pad6(msg.msg_id, dest);
|
||||
}
|
||||
};
|
||||
|
||||
class v_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_buf(msg.raw, dest);
|
||||
}
|
||||
};
|
||||
|
||||
class ch_formatter final : public flag_formatter
|
||||
{
|
||||
public:
|
||||
explicit ch_formatter(char ch)
|
||||
: ch_(ch)
|
||||
{
|
||||
}
|
||||
void format(const details::log_msg &, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
dest.push_back(ch_);
|
||||
}
|
||||
|
||||
private:
|
||||
char ch_;
|
||||
};
|
||||
|
||||
// aggregate user chars to display as is
|
||||
class aggregate_formatter final : public flag_formatter
|
||||
{
|
||||
public:
|
||||
aggregate_formatter() = default;
|
||||
|
||||
void add_ch(char ch)
|
||||
{
|
||||
str_ += ch;
|
||||
}
|
||||
void format(const details::log_msg &, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
fmt_helper::append_str(str_, dest);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string str_;
|
||||
};
|
||||
|
||||
// mark the color range. expect it to be in the form of "%^colored text%$"
|
||||
class color_start_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
msg.color_range_start = dest.size();
|
||||
}
|
||||
};
|
||||
class color_stop_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &msg, const std::tm &, fmt::memory_buffer &dest) override
|
||||
{
|
||||
msg.color_range_end = dest.size();
|
||||
}
|
||||
};
|
||||
|
||||
// Full info formatter
|
||||
// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] %v
|
||||
class full_formatter final : public flag_formatter
|
||||
{
|
||||
void format(const details::log_msg &msg, const std::tm &tm_time, fmt::memory_buffer &dest) override
|
||||
{
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::milliseconds;
|
||||
using std::chrono::seconds;
|
||||
|
||||
#ifndef SPDLOG_NO_DATETIME
|
||||
|
||||
// cache the date/time part for the next second.
|
||||
auto duration = msg.time.time_since_epoch();
|
||||
auto secs = duration_cast<seconds>(duration);
|
||||
|
||||
if (cache_timestamp_ != secs || cached_datetime_.size() == 0)
|
||||
{
|
||||
cached_datetime_.clear();
|
||||
cached_datetime_.push_back('[');
|
||||
fmt_helper::append_int(tm_time.tm_year + 1900, cached_datetime_);
|
||||
cached_datetime_.push_back('-');
|
||||
|
||||
fmt_helper::pad2(tm_time.tm_mon + 1, cached_datetime_);
|
||||
cached_datetime_.push_back('-');
|
||||
|
||||
fmt_helper::pad2(tm_time.tm_mday, cached_datetime_);
|
||||
cached_datetime_.push_back(' ');
|
||||
|
||||
fmt_helper::pad2(tm_time.tm_hour, cached_datetime_);
|
||||
cached_datetime_.push_back(':');
|
||||
|
||||
fmt_helper::pad2(tm_time.tm_min, cached_datetime_);
|
||||
cached_datetime_.push_back(':');
|
||||
|
||||
fmt_helper::pad2(tm_time.tm_sec, cached_datetime_);
|
||||
cached_datetime_.push_back('.');
|
||||
|
||||
cache_timestamp_ = secs;
|
||||
}
|
||||
fmt_helper::append_buf(cached_datetime_, dest);
|
||||
|
||||
auto millis = fmt_helper::time_fraction<milliseconds>(msg.time);
|
||||
fmt_helper::pad3(static_cast<int>(millis.count()), dest);
|
||||
dest.push_back(']');
|
||||
dest.push_back(' ');
|
||||
|
||||
#else // no datetime needed
|
||||
(void)tm_time;
|
||||
#endif
|
||||
|
||||
#ifndef SPDLOG_NO_NAME
|
||||
dest.push_back('[');
|
||||
fmt_helper::append_str(*msg.logger_name, dest);
|
||||
dest.push_back(']');
|
||||
dest.push_back(' ');
|
||||
#endif
|
||||
|
||||
dest.push_back('[');
|
||||
// wrap the level name with color
|
||||
msg.color_range_start = dest.size();
|
||||
fmt_helper::append_c_str(level::to_c_str(msg.level), dest);
|
||||
msg.color_range_end = dest.size();
|
||||
dest.push_back(']');
|
||||
dest.push_back(' ');
|
||||
fmt_helper::append_buf(msg.raw, dest);
|
||||
}
|
||||
|
||||
private:
|
||||
std::chrono::seconds cache_timestamp_{0};
|
||||
fmt::basic_memory_buffer<char, 128> cached_datetime_;
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
|
||||
class pattern_formatter final : public formatter
|
||||
{
|
||||
public:
|
||||
explicit pattern_formatter(
|
||||
std::string pattern, pattern_time_type time_type = pattern_time_type::local, std::string eol = spdlog::details::os::default_eol)
|
||||
: pattern_(std::move(pattern))
|
||||
, eol_(std::move(eol))
|
||||
, pattern_time_type_(time_type)
|
||||
, last_log_secs_(0)
|
||||
{
|
||||
std::memset(&cached_tm_, 0, sizeof(cached_tm_));
|
||||
compile_pattern_(pattern_);
|
||||
}
|
||||
|
||||
pattern_formatter(const pattern_formatter &other) = delete;
|
||||
pattern_formatter &operator=(const pattern_formatter &other) = delete;
|
||||
|
||||
std::unique_ptr<formatter> clone() const override
|
||||
{
|
||||
return details::make_unique<pattern_formatter>(pattern_, pattern_time_type_, eol_);
|
||||
}
|
||||
|
||||
void format(const details::log_msg &msg, fmt::memory_buffer &dest) override
|
||||
{
|
||||
#ifndef SPDLOG_NO_DATETIME
|
||||
auto secs = std::chrono::duration_cast<std::chrono::seconds>(msg.time.time_since_epoch());
|
||||
if (secs != last_log_secs_)
|
||||
{
|
||||
cached_tm_ = get_time_(msg);
|
||||
last_log_secs_ = secs;
|
||||
}
|
||||
#endif
|
||||
for (auto &f : formatters_)
|
||||
{
|
||||
f->format(msg, cached_tm_, dest);
|
||||
}
|
||||
// write eol
|
||||
details::fmt_helper::append_str(eol_, dest);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string pattern_;
|
||||
std::string eol_;
|
||||
pattern_time_type pattern_time_type_;
|
||||
std::tm cached_tm_;
|
||||
std::chrono::seconds last_log_secs_;
|
||||
|
||||
std::vector<std::unique_ptr<details::flag_formatter>> formatters_;
|
||||
|
||||
std::tm get_time_(const details::log_msg &msg)
|
||||
{
|
||||
if (pattern_time_type_ == pattern_time_type::local)
|
||||
{
|
||||
return details::os::localtime(log_clock::to_time_t(msg.time));
|
||||
}
|
||||
return details::os::gmtime(log_clock::to_time_t(msg.time));
|
||||
}
|
||||
|
||||
void handle_flag_(char flag)
|
||||
{
|
||||
switch (flag)
|
||||
{
|
||||
// logger name
|
||||
case 'n':
|
||||
formatters_.push_back(details::make_unique<details::name_formatter>());
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
formatters_.push_back(details::make_unique<details::level_formatter>());
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
formatters_.push_back(details::make_unique<details::short_level_formatter>());
|
||||
break;
|
||||
|
||||
case ('t'):
|
||||
formatters_.push_back(details::make_unique<details::t_formatter>());
|
||||
break;
|
||||
|
||||
case ('v'):
|
||||
formatters_.push_back(details::make_unique<details::v_formatter>());
|
||||
break;
|
||||
|
||||
case ('a'):
|
||||
formatters_.push_back(details::make_unique<details::a_formatter>());
|
||||
break;
|
||||
|
||||
case ('A'):
|
||||
formatters_.push_back(details::make_unique<details::A_formatter>());
|
||||
break;
|
||||
|
||||
case ('b'):
|
||||
case ('h'):
|
||||
formatters_.push_back(details::make_unique<details::b_formatter>());
|
||||
break;
|
||||
|
||||
case ('B'):
|
||||
formatters_.push_back(details::make_unique<details::B_formatter>());
|
||||
break;
|
||||
case ('c'):
|
||||
formatters_.push_back(details::make_unique<details::c_formatter>());
|
||||
break;
|
||||
|
||||
case ('C'):
|
||||
formatters_.push_back(details::make_unique<details::C_formatter>());
|
||||
break;
|
||||
|
||||
case ('Y'):
|
||||
formatters_.push_back(details::make_unique<details::Y_formatter>());
|
||||
break;
|
||||
|
||||
case ('D'):
|
||||
case ('x'):
|
||||
formatters_.push_back(details::make_unique<details::D_formatter>());
|
||||
break;
|
||||
|
||||
case ('m'):
|
||||
formatters_.push_back(details::make_unique<details::m_formatter>());
|
||||
break;
|
||||
|
||||
case ('d'):
|
||||
formatters_.push_back(details::make_unique<details::d_formatter>());
|
||||
break;
|
||||
|
||||
case ('H'):
|
||||
formatters_.push_back(details::make_unique<details::H_formatter>());
|
||||
break;
|
||||
|
||||
case ('I'):
|
||||
formatters_.push_back(details::make_unique<details::I_formatter>());
|
||||
break;
|
||||
|
||||
case ('M'):
|
||||
formatters_.push_back(details::make_unique<details::M_formatter>());
|
||||
break;
|
||||
|
||||
case ('S'):
|
||||
formatters_.push_back(details::make_unique<details::S_formatter>());
|
||||
break;
|
||||
|
||||
case ('e'):
|
||||
formatters_.push_back(details::make_unique<details::e_formatter>());
|
||||
break;
|
||||
|
||||
case ('f'):
|
||||
formatters_.push_back(details::make_unique<details::f_formatter>());
|
||||
break;
|
||||
case ('F'):
|
||||
formatters_.push_back(details::make_unique<details::F_formatter>());
|
||||
break;
|
||||
|
||||
case ('E'):
|
||||
formatters_.push_back(details::make_unique<details::E_formatter>());
|
||||
break;
|
||||
|
||||
case ('p'):
|
||||
formatters_.push_back(details::make_unique<details::p_formatter>());
|
||||
break;
|
||||
|
||||
case ('r'):
|
||||
formatters_.push_back(details::make_unique<details::r_formatter>());
|
||||
break;
|
||||
|
||||
case ('R'):
|
||||
formatters_.push_back(details::make_unique<details::R_formatter>());
|
||||
break;
|
||||
|
||||
case ('T'):
|
||||
case ('X'):
|
||||
formatters_.push_back(details::make_unique<details::T_formatter>());
|
||||
break;
|
||||
|
||||
case ('z'):
|
||||
formatters_.push_back(details::make_unique<details::z_formatter>());
|
||||
break;
|
||||
|
||||
case ('+'):
|
||||
formatters_.push_back(details::make_unique<details::full_formatter>());
|
||||
break;
|
||||
|
||||
case ('P'):
|
||||
formatters_.push_back(details::make_unique<details::pid_formatter>());
|
||||
break;
|
||||
#ifdef SPDLOG_ENABLE_MESSAGE_COUNTER
|
||||
case ('i'):
|
||||
formatters_.push_back(details::make_unique<details::i_formatter>());
|
||||
break;
|
||||
#endif
|
||||
case ('^'):
|
||||
formatters_.push_back(details::make_unique<details::color_start_formatter>());
|
||||
break;
|
||||
|
||||
case ('$'):
|
||||
formatters_.push_back(details::make_unique<details::color_stop_formatter>());
|
||||
break;
|
||||
|
||||
default: // Unknown flag appears as is
|
||||
formatters_.push_back(details::make_unique<details::ch_formatter>('%'));
|
||||
formatters_.push_back(details::make_unique<details::ch_formatter>(flag));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void compile_pattern_(const std::string &pattern)
|
||||
{
|
||||
auto end = pattern.end();
|
||||
std::unique_ptr<details::aggregate_formatter> user_chars;
|
||||
formatters_.clear();
|
||||
for (auto it = pattern.begin(); it != end; ++it)
|
||||
{
|
||||
if (*it == '%')
|
||||
{
|
||||
if (user_chars) // append user chars found so far
|
||||
{
|
||||
formatters_.push_back(std::move(user_chars));
|
||||
}
|
||||
if (++it != end)
|
||||
{
|
||||
handle_flag_(*it);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else // chars not following the % sign should be displayed as is
|
||||
{
|
||||
if (!user_chars)
|
||||
{
|
||||
user_chars = details::make_unique<details::aggregate_formatter>();
|
||||
}
|
||||
user_chars->add_ch(*it);
|
||||
}
|
||||
}
|
||||
if (user_chars) // append raw chars found so far
|
||||
{
|
||||
formatters_.push_back(std::move(user_chars));
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace spdlog
|
||||
@@ -1,71 +0,0 @@
|
||||
|
||||
//
|
||||
// Copyright(c) 2018 Gabi Melman.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
// periodic worker thread - periodically executes the given callback function.
|
||||
//
|
||||
// RAII over the owned thread:
|
||||
// creates the thread on construction.
|
||||
// stops and joins the thread on destruction.
|
||||
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
class periodic_worker
|
||||
{
|
||||
public:
|
||||
periodic_worker(const std::function<void()> &callback_fun, std::chrono::seconds interval)
|
||||
{
|
||||
active_ = (interval > std::chrono::seconds::zero());
|
||||
if (!active_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
worker_thread_ = std::thread([this, callback_fun, interval]() {
|
||||
for (;;)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(this->mutex_);
|
||||
if (this->cv_.wait_for(lock, interval, [this] { return !this->active_; }))
|
||||
{
|
||||
return; // active_ == false, so exit this thread
|
||||
}
|
||||
callback_fun();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
periodic_worker(const periodic_worker &) = delete;
|
||||
periodic_worker &operator=(const periodic_worker &) = delete;
|
||||
|
||||
// stop the worker thread and join it
|
||||
~periodic_worker()
|
||||
{
|
||||
if (worker_thread_.joinable())
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
active_ = false;
|
||||
}
|
||||
cv_.notify_one();
|
||||
worker_thread_.join();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool active_;
|
||||
std::thread worker_thread_;
|
||||
std::mutex mutex_;
|
||||
std::condition_variable cv_;
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
@@ -1,214 +0,0 @@
|
||||
//
|
||||
// Copyright(c) 2015 Gabi Melman.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
// Loggers registy of unique name->logger pointer
|
||||
// An attempt to create a logger with an already existing name will be ignored
|
||||
// If user requests a non existing logger, nullptr will be returned
|
||||
// This class is thread safe
|
||||
|
||||
#include "spdlog/common.h"
|
||||
#include "spdlog/details/periodic_worker.h"
|
||||
#include "spdlog/logger.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
class thread_pool;
|
||||
|
||||
class registry
|
||||
{
|
||||
public:
|
||||
registry(const registry &) = delete;
|
||||
registry &operator=(const registry &) = delete;
|
||||
|
||||
void register_logger(std::shared_ptr<logger> new_logger)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
auto logger_name = new_logger->name();
|
||||
throw_if_exists_(logger_name);
|
||||
loggers_[logger_name] = std::move(new_logger);
|
||||
}
|
||||
|
||||
void register_and_init(std::shared_ptr<logger> new_logger)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
auto logger_name = new_logger->name();
|
||||
throw_if_exists_(logger_name);
|
||||
|
||||
// set the global formatter pattern
|
||||
new_logger->set_formatter(formatter_->clone());
|
||||
|
||||
if (err_handler_)
|
||||
{
|
||||
new_logger->set_error_handler(err_handler_);
|
||||
}
|
||||
|
||||
new_logger->set_level(level_);
|
||||
new_logger->flush_on(flush_level_);
|
||||
|
||||
// add to registry
|
||||
loggers_[logger_name] = std::move(new_logger);
|
||||
}
|
||||
|
||||
std::shared_ptr<logger> get(const std::string &logger_name)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
auto found = loggers_.find(logger_name);
|
||||
return found == loggers_.end() ? nullptr : found->second;
|
||||
}
|
||||
|
||||
void set_tp(std::shared_ptr<thread_pool> tp)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(tp_mutex_);
|
||||
tp_ = std::move(tp);
|
||||
}
|
||||
|
||||
std::shared_ptr<thread_pool> get_tp()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(tp_mutex_);
|
||||
return tp_;
|
||||
}
|
||||
|
||||
// Set global formatter. Each sink in each logger will get a clone of this object
|
||||
void set_formatter(std::unique_ptr<formatter> formatter)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
formatter_ = std::move(formatter);
|
||||
for (auto &l : loggers_)
|
||||
{
|
||||
l.second->set_formatter(formatter_->clone());
|
||||
}
|
||||
}
|
||||
|
||||
void set_level(level::level_enum log_level)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
for (auto &l : loggers_)
|
||||
{
|
||||
l.second->set_level(log_level);
|
||||
}
|
||||
level_ = log_level;
|
||||
}
|
||||
|
||||
void flush_on(level::level_enum log_level)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
for (auto &l : loggers_)
|
||||
{
|
||||
l.second->flush_on(log_level);
|
||||
}
|
||||
flush_level_ = log_level;
|
||||
}
|
||||
|
||||
void flush_every(std::chrono::seconds interval)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(flusher_mutex_);
|
||||
std::function<void()> clbk = std::bind(®istry::flush_all, this);
|
||||
periodic_flusher_ = details::make_unique<periodic_worker>(clbk, interval);
|
||||
}
|
||||
|
||||
void set_error_handler(log_err_handler handler)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
for (auto &l : loggers_)
|
||||
{
|
||||
l.second->set_error_handler(handler);
|
||||
}
|
||||
err_handler_ = handler;
|
||||
}
|
||||
|
||||
void apply_all(const std::function<void(const std::shared_ptr<logger>)> &fun)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
for (auto &l : loggers_)
|
||||
{
|
||||
fun(l.second);
|
||||
}
|
||||
}
|
||||
|
||||
void flush_all()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
for (auto &l : loggers_)
|
||||
{
|
||||
l.second->flush();
|
||||
}
|
||||
}
|
||||
|
||||
void drop(const std::string &logger_name)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
loggers_.erase(logger_name);
|
||||
}
|
||||
|
||||
void drop_all()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
loggers_.clear();
|
||||
}
|
||||
|
||||
// clean all reasources and threads started by the registry
|
||||
void shutdown()
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(flusher_mutex_);
|
||||
periodic_flusher_.reset();
|
||||
}
|
||||
|
||||
drop_all();
|
||||
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(tp_mutex_);
|
||||
tp_.reset();
|
||||
}
|
||||
}
|
||||
|
||||
std::recursive_mutex &tp_mutex()
|
||||
{
|
||||
return tp_mutex_;
|
||||
}
|
||||
|
||||
static registry &instance()
|
||||
{
|
||||
static registry s_instance;
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
private:
|
||||
registry()
|
||||
: formatter_(new pattern_formatter("%+"))
|
||||
{
|
||||
}
|
||||
|
||||
~registry() = default;
|
||||
|
||||
void throw_if_exists_(const std::string &logger_name)
|
||||
{
|
||||
if (loggers_.find(logger_name) != loggers_.end())
|
||||
{
|
||||
throw spdlog_ex("logger with name '" + logger_name + "' already exists");
|
||||
}
|
||||
}
|
||||
|
||||
std::mutex logger_map_mutex_, flusher_mutex_;
|
||||
std::recursive_mutex tp_mutex_;
|
||||
std::unordered_map<std::string, std::shared_ptr<logger>> loggers_;
|
||||
std::unique_ptr<formatter> formatter_;
|
||||
level::level_enum level_ = level::info;
|
||||
level::level_enum flush_level_ = level::off;
|
||||
log_err_handler err_handler_;
|
||||
std::shared_ptr<thread_pool> tp_;
|
||||
std::unique_ptr<periodic_worker> periodic_flusher_;
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
125
include/spdlog/details/tcp_client_unix.h
Normal file
125
include/spdlog/details/tcp_client_unix.h
Normal file
@@ -0,0 +1,125 @@
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
#error include tcp_client_windows.h instead
|
||||
#endif
|
||||
|
||||
// tcp client helper
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../common.h"
|
||||
#include "./os.h"
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
class tcp_client_unix {
|
||||
int socket_ = -1;
|
||||
|
||||
public:
|
||||
bool is_connected() const { return socket_ != -1; }
|
||||
|
||||
void close() {
|
||||
if (is_connected()) {
|
||||
::close(socket_);
|
||||
socket_ = -1;
|
||||
}
|
||||
}
|
||||
|
||||
int fd() const { return socket_; }
|
||||
|
||||
~tcp_client_unix() { close(); }
|
||||
|
||||
// try to connect or throw on failure
|
||||
void connect(const std::string &host, int port) {
|
||||
close();
|
||||
struct addrinfo hints {};
|
||||
memset(&hints, 0, sizeof(struct addrinfo));
|
||||
hints.ai_family = AF_UNSPEC; // To work with IPv4, IPv6, and so on
|
||||
hints.ai_socktype = SOCK_STREAM; // TCP
|
||||
hints.ai_flags = AI_NUMERICSERV; // port passed as as numeric value
|
||||
hints.ai_protocol = 0;
|
||||
|
||||
auto port_str = std::to_string(port);
|
||||
struct addrinfo *addrinfo_result;
|
||||
auto rv = ::getaddrinfo(host.c_str(), port_str.c_str(), &hints, &addrinfo_result);
|
||||
if (rv != 0) {
|
||||
throw_spdlog_ex(fmt_lib::format("::getaddrinfo failed: {}", gai_strerror(rv)));
|
||||
}
|
||||
|
||||
// Try each address until we successfully connect(2).
|
||||
int last_errno = 0;
|
||||
for (auto *rp = addrinfo_result; rp != nullptr; rp = rp->ai_next) {
|
||||
#if defined(SOCK_CLOEXEC)
|
||||
constexpr int flags = SOCK_CLOEXEC;
|
||||
#else
|
||||
constexpr int flags = 0;
|
||||
#endif
|
||||
socket_ = ::socket(rp->ai_family, rp->ai_socktype | flags, rp->ai_protocol);
|
||||
if (socket_ == -1) {
|
||||
last_errno = errno;
|
||||
continue;
|
||||
}
|
||||
rv = ::connect(socket_, rp->ai_addr, rp->ai_addrlen);
|
||||
if (rv == 0) {
|
||||
break;
|
||||
}
|
||||
last_errno = errno;
|
||||
::close(socket_);
|
||||
socket_ = -1;
|
||||
}
|
||||
::freeaddrinfo(addrinfo_result);
|
||||
if (socket_ == -1) {
|
||||
throw_spdlog_ex("::connect failed", last_errno);
|
||||
}
|
||||
|
||||
// set TCP_NODELAY
|
||||
int enable_flag = 1;
|
||||
::setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char *>(&enable_flag), sizeof(enable_flag));
|
||||
|
||||
// prevent sigpipe on systems where MSG_NOSIGNAL is not available
|
||||
#if defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL)
|
||||
::setsockopt(socket_, SOL_SOCKET, SO_NOSIGPIPE, reinterpret_cast<char *>(&enable_flag), sizeof(enable_flag));
|
||||
#endif
|
||||
|
||||
#if !defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL)
|
||||
#error "tcp_sink would raise SIGPIPE since neither SO_NOSIGPIPE nor MSG_NOSIGNAL are available"
|
||||
#endif
|
||||
}
|
||||
|
||||
// Send exactly n_bytes of the given data.
|
||||
// On error close the connection and throw.
|
||||
void send(const char *data, size_t n_bytes) {
|
||||
size_t bytes_sent = 0;
|
||||
while (bytes_sent < n_bytes) {
|
||||
#if defined(MSG_NOSIGNAL)
|
||||
const int send_flags = MSG_NOSIGNAL;
|
||||
#else
|
||||
const int send_flags = 0;
|
||||
#endif
|
||||
auto write_result = ::send(socket_, data + bytes_sent, n_bytes - bytes_sent, send_flags);
|
||||
if (write_result < 0) {
|
||||
close();
|
||||
throw_spdlog_ex("write(2) failed", errno);
|
||||
}
|
||||
|
||||
if (write_result == 0) // (probably should not happen but in any case..)
|
||||
{
|
||||
break;
|
||||
}
|
||||
bytes_sent += static_cast<size_t>(write_result);
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
133
include/spdlog/details/tcp_client_windows.h
Normal file
133
include/spdlog/details/tcp_client_windows.h
Normal file
@@ -0,0 +1,133 @@
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
#pragma once
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
// tcp client helper
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../common.h"
|
||||
#include "./os.h"
|
||||
|
||||
#pragma comment(lib, "Ws2_32.lib")
|
||||
#pragma comment(lib, "Mswsock.lib")
|
||||
#pragma comment(lib, "AdvApi32.lib")
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
class tcp_client_unix {
|
||||
SOCKET socket_ = INVALID_SOCKET;
|
||||
|
||||
static void init_winsock_() {
|
||||
WSADATA wsaData;
|
||||
auto rv = WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
if (rv != 0) {
|
||||
throw_winsock_error_("WSAStartup failed", ::WSAGetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
static void throw_winsock_error_(const std::string &msg, int last_error) {
|
||||
char buf[512];
|
||||
::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, last_error,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, (sizeof(buf) / sizeof(char)), NULL);
|
||||
|
||||
throw_spdlog_ex(fmt_lib::format("tcp_sink - {}: {}", msg, buf));
|
||||
}
|
||||
|
||||
public:
|
||||
tcp_client_unix() { init_winsock_(); }
|
||||
|
||||
~tcp_client_unix() {
|
||||
close();
|
||||
::WSACleanup();
|
||||
}
|
||||
|
||||
bool is_connected() const { return socket_ != INVALID_SOCKET; }
|
||||
|
||||
void close() {
|
||||
::closesocket(socket_);
|
||||
socket_ = INVALID_SOCKET;
|
||||
}
|
||||
|
||||
SOCKET fd() const { return socket_; }
|
||||
|
||||
// try to connect or throw on failure
|
||||
void connect(const std::string &host, int port) {
|
||||
if (is_connected()) {
|
||||
close();
|
||||
}
|
||||
struct addrinfo hints {};
|
||||
ZeroMemory(&hints, sizeof(hints));
|
||||
|
||||
hints.ai_family = AF_UNSPEC; // To work with IPv4, IPv6, and so on
|
||||
hints.ai_socktype = SOCK_STREAM; // TCP
|
||||
hints.ai_flags = AI_NUMERICSERV; // port passed as as numeric value
|
||||
hints.ai_protocol = 0;
|
||||
|
||||
auto port_str = std::to_string(port);
|
||||
struct addrinfo *addrinfo_result;
|
||||
auto rv = ::getaddrinfo(host.c_str(), port_str.c_str(), &hints, &addrinfo_result);
|
||||
int last_error = 0;
|
||||
if (rv != 0) {
|
||||
last_error = ::WSAGetLastError();
|
||||
WSACleanup();
|
||||
throw_winsock_error_("getaddrinfo failed", last_error);
|
||||
}
|
||||
|
||||
// Try each address until we successfully connect(2).
|
||||
|
||||
for (auto *rp = addrinfo_result; rp != nullptr; rp = rp->ai_next) {
|
||||
socket_ = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
|
||||
if (socket_ == INVALID_SOCKET) {
|
||||
last_error = ::WSAGetLastError();
|
||||
WSACleanup();
|
||||
continue;
|
||||
}
|
||||
if (::connect(socket_, rp->ai_addr, (int)rp->ai_addrlen) == 0) {
|
||||
break;
|
||||
} else {
|
||||
last_error = ::WSAGetLastError();
|
||||
close();
|
||||
}
|
||||
}
|
||||
::freeaddrinfo(addrinfo_result);
|
||||
if (socket_ == INVALID_SOCKET) {
|
||||
WSACleanup();
|
||||
throw_winsock_error_("connect failed", last_error);
|
||||
}
|
||||
|
||||
// set TCP_NODELAY
|
||||
int enable_flag = 1;
|
||||
::setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char *>(&enable_flag), sizeof(enable_flag));
|
||||
}
|
||||
|
||||
// Send exactly n_bytes of the given data.
|
||||
// On error close the connection and throw.
|
||||
void send(const char *data, size_t n_bytes) {
|
||||
size_t bytes_sent = 0;
|
||||
while (bytes_sent < n_bytes) {
|
||||
const int send_flags = 0;
|
||||
auto write_result = ::send(socket_, data + bytes_sent, (int)(n_bytes - bytes_sent), send_flags);
|
||||
if (write_result == SOCKET_ERROR) {
|
||||
int last_error = ::WSAGetLastError();
|
||||
close();
|
||||
throw_winsock_error_("send failed", last_error);
|
||||
}
|
||||
|
||||
if (write_result == 0) // (probably should not happen but in any case..)
|
||||
{
|
||||
break;
|
||||
}
|
||||
bytes_sent += static_cast<size_t>(write_result);
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
@@ -1,228 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "spdlog/details/log_msg.h"
|
||||
#include "spdlog/details/mpmc_blocking_q.h"
|
||||
#include "spdlog/details/os.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
using async_logger_ptr = std::shared_ptr<spdlog::async_logger>;
|
||||
|
||||
enum class async_msg_type
|
||||
{
|
||||
log,
|
||||
flush,
|
||||
terminate
|
||||
};
|
||||
|
||||
// Async msg to move to/from the queue
|
||||
// Movable only. should never be copied
|
||||
struct async_msg
|
||||
{
|
||||
async_msg_type msg_type;
|
||||
level::level_enum level;
|
||||
log_clock::time_point time;
|
||||
size_t thread_id;
|
||||
fmt::basic_memory_buffer<char, 176> raw;
|
||||
|
||||
size_t msg_id;
|
||||
async_logger_ptr worker_ptr;
|
||||
|
||||
async_msg() = default;
|
||||
~async_msg() = default;
|
||||
|
||||
// should only be moved in or out of the queue..
|
||||
async_msg(const async_msg &) = delete;
|
||||
|
||||
// support for vs2013 move
|
||||
#if defined(_MSC_VER) && _MSC_VER <= 1800
|
||||
async_msg(async_msg &&other) SPDLOG_NOEXCEPT : msg_type(other.msg_type),
|
||||
level(other.level),
|
||||
time(other.time),
|
||||
thread_id(other.thread_id),
|
||||
raw(move(other.raw)),
|
||||
msg_id(other.msg_id),
|
||||
worker_ptr(std::move(other.worker_ptr))
|
||||
{
|
||||
}
|
||||
|
||||
async_msg &operator=(async_msg &&other) SPDLOG_NOEXCEPT
|
||||
{
|
||||
msg_type = other.msg_type;
|
||||
level = other.level;
|
||||
time = other.time;
|
||||
thread_id = other.thread_id;
|
||||
raw = std::move(other.raw);
|
||||
msg_id = other.msg_id;
|
||||
worker_ptr = std::move(other.worker_ptr);
|
||||
return *this;
|
||||
}
|
||||
#else // (_MSC_VER) && _MSC_VER <= 1800
|
||||
async_msg(async_msg &&) = default;
|
||||
async_msg &operator=(async_msg &&) = default;
|
||||
#endif
|
||||
|
||||
// construct from log_msg with given type
|
||||
async_msg(async_logger_ptr &&worker, async_msg_type the_type, details::log_msg &&m)
|
||||
: msg_type(the_type)
|
||||
, level(m.level)
|
||||
, time(m.time)
|
||||
, thread_id(m.thread_id)
|
||||
, msg_id(m.msg_id)
|
||||
, worker_ptr(std::move(worker))
|
||||
{
|
||||
fmt_helper::append_buf(m.raw, raw);
|
||||
}
|
||||
|
||||
async_msg(async_logger_ptr &&worker, async_msg_type the_type)
|
||||
: async_msg(std::move(worker), the_type, details::log_msg())
|
||||
{
|
||||
}
|
||||
|
||||
explicit async_msg(async_msg_type the_type)
|
||||
: async_msg(nullptr, the_type, details::log_msg())
|
||||
{
|
||||
}
|
||||
|
||||
// copy into log_msg
|
||||
void to_log_msg(log_msg &msg)
|
||||
{
|
||||
msg.logger_name = &worker_ptr->name();
|
||||
msg.level = level;
|
||||
msg.time = time;
|
||||
msg.thread_id = thread_id;
|
||||
fmt_helper::append_buf(raw, msg.raw);
|
||||
msg.msg_id = msg_id;
|
||||
msg.color_range_start = 0;
|
||||
msg.color_range_end = 0;
|
||||
}
|
||||
};
|
||||
|
||||
class thread_pool
|
||||
{
|
||||
public:
|
||||
using item_type = async_msg;
|
||||
using q_type = details::mpmc_blocking_queue<item_type>;
|
||||
|
||||
thread_pool(size_t q_max_items, size_t threads_n)
|
||||
: q_(q_max_items)
|
||||
{
|
||||
// std::cout << "thread_pool() q_size_bytes: " << q_size_bytes <<
|
||||
// "\tthreads_n: " << threads_n << std::endl;
|
||||
if (threads_n == 0 || threads_n > 1000)
|
||||
{
|
||||
throw spdlog_ex("spdlog::thread_pool(): invalid threads_n param (valid "
|
||||
"range is 1-1000)");
|
||||
}
|
||||
for (size_t i = 0; i < threads_n; i++)
|
||||
{
|
||||
threads_.emplace_back(&thread_pool::worker_loop_, this);
|
||||
}
|
||||
}
|
||||
|
||||
// message all threads to terminate gracefully join them
|
||||
~thread_pool()
|
||||
{
|
||||
try
|
||||
{
|
||||
for (size_t i = 0; i < threads_.size(); i++)
|
||||
{
|
||||
post_async_msg_(async_msg(async_msg_type::terminate), async_overflow_policy::block);
|
||||
}
|
||||
|
||||
for (auto &t : threads_)
|
||||
{
|
||||
t.join();
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
thread_pool(const thread_pool &) = delete;
|
||||
thread_pool &operator=(thread_pool &&) = delete;
|
||||
|
||||
void post_log(async_logger_ptr &&worker_ptr, details::log_msg &&msg, async_overflow_policy overflow_policy)
|
||||
{
|
||||
async_msg async_m(std::move(worker_ptr), async_msg_type::log, std::move(msg));
|
||||
post_async_msg_(std::move(async_m), overflow_policy);
|
||||
}
|
||||
|
||||
void post_flush(async_logger_ptr &&worker_ptr, async_overflow_policy overflow_policy)
|
||||
{
|
||||
post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy);
|
||||
}
|
||||
|
||||
size_t overrun_counter()
|
||||
{
|
||||
return q_.overrun_counter();
|
||||
}
|
||||
|
||||
private:
|
||||
q_type q_;
|
||||
|
||||
std::vector<std::thread> threads_;
|
||||
|
||||
void post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy)
|
||||
{
|
||||
if (overflow_policy == async_overflow_policy::block)
|
||||
{
|
||||
q_.enqueue(std::move(new_msg));
|
||||
}
|
||||
else
|
||||
{
|
||||
q_.enqueue_nowait(std::move(new_msg));
|
||||
}
|
||||
}
|
||||
|
||||
void worker_loop_()
|
||||
{
|
||||
while (process_next_msg_()) {};
|
||||
}
|
||||
|
||||
// process next message in the queue
|
||||
// return true if this thread should still be active (while no terminate msg
|
||||
// was received)
|
||||
bool process_next_msg_()
|
||||
{
|
||||
async_msg incoming_async_msg;
|
||||
bool dequeued = q_.dequeue_for(incoming_async_msg, std::chrono::seconds(10));
|
||||
if (!dequeued)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (incoming_async_msg.msg_type)
|
||||
{
|
||||
case async_msg_type::log:
|
||||
{
|
||||
log_msg msg;
|
||||
incoming_async_msg.to_log_msg(msg);
|
||||
incoming_async_msg.worker_ptr->backend_log_(msg);
|
||||
return true;
|
||||
}
|
||||
case async_msg_type::flush:
|
||||
{
|
||||
incoming_async_msg.worker_ptr->backend_flush_();
|
||||
return true;
|
||||
}
|
||||
|
||||
case async_msg_type::terminate:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
assert(false && "Unexpected async_msg_type");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
81
include/spdlog/details/udp_client_unix.h
Normal file
81
include/spdlog/details/udp_client_unix.h
Normal file
@@ -0,0 +1,81 @@
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
#pragma once
|
||||
|
||||
// Helper RAII over unix udp client socket.
|
||||
// Will throw on construction if the socket creation failed.
|
||||
|
||||
#include "../common.h"
|
||||
#include "./os.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#error "include udp_client_windows.h instead"
|
||||
#endif
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
class udp_client_unix {
|
||||
static constexpr int TX_BUFFER_SIZE = 1024 * 10;
|
||||
int socket_ = -1;
|
||||
struct sockaddr_in sockAddr_;
|
||||
|
||||
void cleanup_() {
|
||||
if (socket_ != -1) {
|
||||
::close(socket_);
|
||||
socket_ = -1;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
udp_client_unix(const std::string &host, uint16_t port) {
|
||||
socket_ = ::socket(PF_INET, SOCK_DGRAM, 0);
|
||||
if (socket_ < 0) {
|
||||
throw_spdlog_ex("error: Create Socket Failed!");
|
||||
}
|
||||
|
||||
int option_value = TX_BUFFER_SIZE;
|
||||
if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<const char *>(&option_value), sizeof(option_value)) <
|
||||
0) {
|
||||
cleanup_();
|
||||
throw_spdlog_ex("error: setsockopt(SO_SNDBUF) Failed!");
|
||||
}
|
||||
|
||||
sockAddr_.sin_family = AF_INET;
|
||||
sockAddr_.sin_port = htons(port);
|
||||
|
||||
if (::inet_aton(host.c_str(), &sockAddr_.sin_addr) == 0) {
|
||||
cleanup_();
|
||||
throw_spdlog_ex("error: Invalid address!");
|
||||
}
|
||||
|
||||
::memset(sockAddr_.sin_zero, 0x00, sizeof(sockAddr_.sin_zero));
|
||||
}
|
||||
|
||||
~udp_client_unix() { cleanup_(); }
|
||||
|
||||
int fd() const { return socket_; }
|
||||
|
||||
// Send exactly n_bytes of the given data.
|
||||
// On error close the connection and throw.
|
||||
void send(const char *data, size_t n_bytes) {
|
||||
ssize_t toslen = 0;
|
||||
socklen_t tolen = sizeof(struct sockaddr);
|
||||
if ((toslen = ::sendto(socket_, data, n_bytes, 0, (struct sockaddr *)&sockAddr_, tolen)) == -1) {
|
||||
throw_spdlog_ex("sendto(2) failed", errno);
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
98
include/spdlog/details/udp_client_windows.h
Normal file
98
include/spdlog/details/udp_client_windows.h
Normal file
@@ -0,0 +1,98 @@
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
#pragma once
|
||||
|
||||
// Helper RAII over winsock udp client socket.
|
||||
// Will throw on construction if socket creation failed.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../common.h"
|
||||
#include "./os.h"
|
||||
#include "./windows_include.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma comment(lib, "Ws2_32.lib")
|
||||
#pragma comment(lib, "Mswsock.lib")
|
||||
#pragma comment(lib, "AdvApi32.lib")
|
||||
#endif
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
class udp_client_unix {
|
||||
static constexpr int TX_BUFFER_SIZE = 1024 * 10;
|
||||
SOCKET socket_ = INVALID_SOCKET;
|
||||
sockaddr_in addr_ = {};
|
||||
|
||||
static void init_winsock_() {
|
||||
WSADATA wsaData;
|
||||
auto rv = ::WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
if (rv != 0) {
|
||||
throw_winsock_error_("WSAStartup failed", ::WSAGetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
static void throw_winsock_error_(const std::string &msg, int last_error) {
|
||||
char buf[512];
|
||||
::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, last_error,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, (sizeof(buf) / sizeof(char)), NULL);
|
||||
|
||||
throw_spdlog_ex(fmt_lib::format("udp_sink - {}: {}", msg, buf));
|
||||
}
|
||||
|
||||
void cleanup_() {
|
||||
if (socket_ != INVALID_SOCKET) {
|
||||
::closesocket(socket_);
|
||||
}
|
||||
socket_ = INVALID_SOCKET;
|
||||
::WSACleanup();
|
||||
}
|
||||
|
||||
public:
|
||||
udp_client_unix(const std::string &host, uint16_t port) {
|
||||
init_winsock_();
|
||||
|
||||
addr_.sin_family = PF_INET;
|
||||
addr_.sin_port = htons(port);
|
||||
addr_.sin_addr.s_addr = INADDR_ANY;
|
||||
if (InetPtonA(PF_INET, host.c_str(), &addr_.sin_addr.s_addr) != 1) {
|
||||
int last_error = ::WSAGetLastError();
|
||||
::WSACleanup();
|
||||
throw_winsock_error_("error: Invalid address!", last_error);
|
||||
}
|
||||
|
||||
socket_ = ::socket(PF_INET, SOCK_DGRAM, 0);
|
||||
if (socket_ == INVALID_SOCKET) {
|
||||
int last_error = ::WSAGetLastError();
|
||||
::WSACleanup();
|
||||
throw_winsock_error_("error: Create Socket failed", last_error);
|
||||
}
|
||||
|
||||
int option_value = TX_BUFFER_SIZE;
|
||||
if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<const char *>(&option_value), sizeof(option_value)) <
|
||||
0) {
|
||||
int last_error = ::WSAGetLastError();
|
||||
cleanup_();
|
||||
throw_winsock_error_("error: setsockopt(SO_SNDBUF) Failed!", last_error);
|
||||
}
|
||||
}
|
||||
|
||||
~udp_client_unix() { cleanup_(); }
|
||||
|
||||
SOCKET fd() const { return socket_; }
|
||||
|
||||
void send(const char *data, size_t n_bytes) {
|
||||
socklen_t tolen = sizeof(struct sockaddr);
|
||||
if (::sendto(socket_, data, static_cast<int>(n_bytes), 0, (struct sockaddr *)&addr_, tolen) == -1) {
|
||||
throw_spdlog_ex("sendto(2) failed", errno);
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
11
include/spdlog/details/windows_include.h
Normal file
11
include/spdlog/details/windows_include.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX // prevent windows redefining min/max
|
||||
#endif
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
20
include/spdlog/file_event_handlers.h
Normal file
20
include/spdlog/file_event_handlers.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "./filename_t.h"
|
||||
|
||||
namespace spdlog {
|
||||
struct file_event_handlers {
|
||||
file_event_handlers()
|
||||
: before_open(nullptr),
|
||||
after_open(nullptr),
|
||||
before_close(nullptr),
|
||||
after_close(nullptr) {}
|
||||
|
||||
std::function<void(const filename_t &filename)> before_open;
|
||||
std::function<void(const filename_t &filename, std::FILE *file_stream)> after_open;
|
||||
std::function<void(const filename_t &filename, std::FILE *file_stream)> before_close;
|
||||
std::function<void(const filename_t &filename)> after_close;
|
||||
};
|
||||
} // namespace spdlog
|
||||
18
include/spdlog/filename_t.h
Normal file
18
include/spdlog/filename_t.h
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
#ifdef _WIN32
|
||||
// In windows, add L prefix for filename literals (e.g. L"filename.txt")
|
||||
#define SPDLOG_FILENAME_T_INNER(s) L##s
|
||||
#define SPDLOG_FILENAME_T(s) SPDLOG_FILENAME_T_INNER(s)
|
||||
#else
|
||||
#define SPDLOG_FILENAME_T(s) s
|
||||
#endif
|
||||
|
||||
namespace spdlog {
|
||||
using filename_t = std::filesystem::path;
|
||||
} // namespace spdlog
|
||||
@@ -1,172 +0,0 @@
|
||||
//
|
||||
// Copyright(c) 2015 Gabi Melman.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// Support for logging binary data as hex
|
||||
// format flags:
|
||||
// {:X} - print in uppercase.
|
||||
// {:s} - don't separate each byte with space.
|
||||
// {:p} - don't print the position on each line start.
|
||||
// {:n} - don't split the output to lines.
|
||||
|
||||
//
|
||||
// Examples:
|
||||
//
|
||||
// std::vector<char> v(200, 0x0b);
|
||||
// logger->info("Some buffer {}", spdlog::to_hex(v));
|
||||
// char buf[128];
|
||||
// logger->info("Some buffer {:X}", spdlog::to_hex(std::begin(buf), std::end(buf)));
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
template<typename It>
|
||||
class bytes_range
|
||||
{
|
||||
public:
|
||||
bytes_range(It range_begin, It range_end)
|
||||
: begin_(range_begin)
|
||||
, end_(range_end)
|
||||
{
|
||||
}
|
||||
|
||||
It begin() const
|
||||
{
|
||||
return begin_;
|
||||
}
|
||||
It end() const
|
||||
{
|
||||
return end_;
|
||||
}
|
||||
|
||||
private:
|
||||
It begin_, end_;
|
||||
};
|
||||
} // namespace details
|
||||
|
||||
// create a bytes_range that wraps the given container
|
||||
template<typename Container>
|
||||
inline details::bytes_range<typename Container::const_iterator> to_hex(const Container &container)
|
||||
{
|
||||
static_assert(sizeof(typename Container::value_type) == 1, "sizeof(Container::value_type) != 1");
|
||||
using Iter = typename Container::const_iterator;
|
||||
return details::bytes_range<Iter>(std::begin(container), std::end(container));
|
||||
}
|
||||
|
||||
// create bytes_range from ranges
|
||||
template<typename It>
|
||||
inline details::bytes_range<It> to_hex(const It range_begin, const It range_end)
|
||||
{
|
||||
return details::bytes_range<It>(range_begin, range_end);
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
|
||||
namespace fmt {
|
||||
|
||||
template<typename T>
|
||||
struct formatter<spdlog::details::bytes_range<T>>
|
||||
{
|
||||
const std::size_t line_size = 100;
|
||||
const char delimiter = ' ';
|
||||
|
||||
bool put_newlines = true;
|
||||
bool put_delimiters = true;
|
||||
bool use_uppercase = false;
|
||||
bool put_positions = true; // position on start of each line
|
||||
|
||||
// parse the format string flags
|
||||
template<typename ParseContext>
|
||||
auto parse(ParseContext &ctx) -> decltype(ctx.begin())
|
||||
{
|
||||
auto it = ctx.begin();
|
||||
while (*it && *it != '}')
|
||||
{
|
||||
switch (*it)
|
||||
{
|
||||
case 'X':
|
||||
use_uppercase = true;
|
||||
break;
|
||||
case 's':
|
||||
put_delimiters = false;
|
||||
break;
|
||||
case 'p':
|
||||
put_positions = false;
|
||||
break;
|
||||
case 'n':
|
||||
put_newlines = false;
|
||||
break;
|
||||
}
|
||||
|
||||
++it;
|
||||
}
|
||||
return it;
|
||||
}
|
||||
|
||||
// format the given bytes range as hex
|
||||
template<typename FormatContext, typename Container>
|
||||
auto format(const spdlog::details::bytes_range<Container> &the_range, FormatContext &ctx) -> decltype(ctx.out())
|
||||
{
|
||||
constexpr const char *hex_upper = "0123456789ABCDEF";
|
||||
constexpr const char *hex_lower = "0123456789abcdef";
|
||||
const char *hex_chars = use_uppercase ? hex_upper : hex_lower;
|
||||
|
||||
std::size_t pos = 0;
|
||||
std::size_t column = line_size;
|
||||
auto inserter = ctx.begin();
|
||||
|
||||
for (auto &item : the_range)
|
||||
{
|
||||
auto ch = static_cast<unsigned char>(item);
|
||||
pos++;
|
||||
|
||||
if (put_newlines && column >= line_size)
|
||||
{
|
||||
column = put_newline(inserter, pos);
|
||||
|
||||
// put first byte without delimiter in front of it
|
||||
*inserter++ = hex_chars[(ch >> 4) & 0x0f];
|
||||
*inserter++ = hex_chars[ch & 0x0f];
|
||||
column += 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (put_delimiters)
|
||||
{
|
||||
*inserter++ = delimiter;
|
||||
++column;
|
||||
}
|
||||
|
||||
*inserter++ = hex_chars[(ch >> 4) & 0x0f];
|
||||
*inserter++ = hex_chars[ch & 0x0f];
|
||||
column += 2;
|
||||
}
|
||||
return inserter;
|
||||
}
|
||||
|
||||
// put newline(and position header)
|
||||
// return the next column
|
||||
template<typename It>
|
||||
std::size_t put_newline(It inserter, std::size_t pos)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
*inserter++ = '\r';
|
||||
#endif
|
||||
*inserter++ = '\n';
|
||||
|
||||
if (put_positions)
|
||||
{
|
||||
fmt::format_to(inserter, "{:<04X}: ", pos - 1);
|
||||
return 7;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace fmt
|
||||
@@ -1,23 +0,0 @@
|
||||
Copyright (c) 2012 - 2016, Victor Zverovich
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -1,257 +0,0 @@
|
||||
// Formatting library for C++ - the core API
|
||||
//
|
||||
// Copyright (c) 2012 - present, Victor Zverovich
|
||||
// All rights reserved.
|
||||
//
|
||||
// For the license information refer to format.h.
|
||||
//
|
||||
// Copyright (c) 2018 - present, Remotion (Igor Schulz)
|
||||
// All Rights Reserved
|
||||
// {fmt} support for rgb color output.
|
||||
|
||||
#ifndef FMT_COLORS_H_
|
||||
#define FMT_COLORS_H_
|
||||
|
||||
#include "format.h"
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
|
||||
// rgb is a struct for red, green and blue colors.
|
||||
// We use rgb as name because some editors will show it as color direct in the
|
||||
// editor.
|
||||
struct rgb
|
||||
{
|
||||
FMT_CONSTEXPR_DECL rgb()
|
||||
: r(0)
|
||||
, g(0)
|
||||
, b(0)
|
||||
{
|
||||
}
|
||||
FMT_CONSTEXPR_DECL rgb(uint8_t r_, uint8_t g_, uint8_t b_)
|
||||
: r(r_)
|
||||
, g(g_)
|
||||
, b(b_)
|
||||
{
|
||||
}
|
||||
FMT_CONSTEXPR_DECL rgb(uint32_t hex)
|
||||
: r((hex >> 16) & 0xFF)
|
||||
, g((hex >> 8) & 0xFF)
|
||||
, b((hex)&0xFF)
|
||||
{
|
||||
}
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
|
||||
FMT_CONSTEXPR inline void to_esc(uint8_t c, char out[], int offset)
|
||||
{
|
||||
out[offset + 0] = static_cast<char>('0' + c / 100);
|
||||
out[offset + 1] = static_cast<char>('0' + c / 10 % 10);
|
||||
out[offset + 2] = static_cast<char>('0' + c % 10);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
FMT_FUNC void vprint_rgb(rgb fd, string_view format, format_args args)
|
||||
{
|
||||
char escape_fd[] = "\x1b[38;2;000;000;000m";
|
||||
static FMT_CONSTEXPR_DECL const char RESET_COLOR[] = "\x1b[0m";
|
||||
internal::to_esc(fd.r, escape_fd, 7);
|
||||
internal::to_esc(fd.g, escape_fd, 11);
|
||||
internal::to_esc(fd.b, escape_fd, 15);
|
||||
|
||||
std::fputs(escape_fd, stdout);
|
||||
vprint(format, args);
|
||||
std::fputs(RESET_COLOR, stdout);
|
||||
}
|
||||
|
||||
FMT_FUNC void vprint_rgb(rgb fd, rgb bg, string_view format, format_args args)
|
||||
{
|
||||
char escape_fd[] = "\x1b[38;2;000;000;000m"; // foreground color
|
||||
char escape_bg[] = "\x1b[48;2;000;000;000m"; // background color
|
||||
static FMT_CONSTEXPR_DECL const char RESET_COLOR[] = "\x1b[0m";
|
||||
internal::to_esc(fd.r, escape_fd, 7);
|
||||
internal::to_esc(fd.g, escape_fd, 11);
|
||||
internal::to_esc(fd.b, escape_fd, 15);
|
||||
|
||||
internal::to_esc(bg.r, escape_bg, 7);
|
||||
internal::to_esc(bg.g, escape_bg, 11);
|
||||
internal::to_esc(bg.b, escape_bg, 15);
|
||||
|
||||
std::fputs(escape_fd, stdout);
|
||||
std::fputs(escape_bg, stdout);
|
||||
vprint(format, args);
|
||||
std::fputs(RESET_COLOR, stdout);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
inline void print_rgb(rgb fd, string_view format_str, const Args &... args)
|
||||
{
|
||||
vprint_rgb(fd, format_str, make_format_args(args...));
|
||||
}
|
||||
|
||||
// rgb foreground color
|
||||
template<typename... Args>
|
||||
inline void print(rgb fd, string_view format_str, const Args &... args)
|
||||
{
|
||||
vprint_rgb(fd, format_str, make_format_args(args...));
|
||||
}
|
||||
|
||||
// rgb foreground color and background color
|
||||
template<typename... Args>
|
||||
inline void print(rgb fd, rgb bg, string_view format_str, const Args &... args)
|
||||
{
|
||||
vprint_rgb(fd, bg, format_str, make_format_args(args...));
|
||||
}
|
||||
|
||||
enum class color : uint32_t
|
||||
{
|
||||
alice_blue = 0xF0F8FF, // rgb(240,248,255)
|
||||
antique_white = 0xFAEBD7, // rgb(250,235,215)
|
||||
aqua = 0x00FFFF, // rgb(0,255,255)
|
||||
aquamarine = 0x7FFFD4, // rgb(127,255,212)
|
||||
azure = 0xF0FFFF, // rgb(240,255,255)
|
||||
beige = 0xF5F5DC, // rgb(245,245,220)
|
||||
bisque = 0xFFE4C4, // rgb(255,228,196)
|
||||
black = 0x000000, // rgb(0,0,0)
|
||||
blanched_almond = 0xFFEBCD, // rgb(255,235,205)
|
||||
blue = 0x0000FF, // rgb(0,0,255)
|
||||
blue_violet = 0x8A2BE2, // rgb(138,43,226)
|
||||
brown = 0xA52A2A, // rgb(165,42,42)
|
||||
burly_wood = 0xDEB887, // rgb(222,184,135)
|
||||
cadet_blue = 0x5F9EA0, // rgb(95,158,160)
|
||||
chartreuse = 0x7FFF00, // rgb(127,255,0)
|
||||
chocolate = 0xD2691E, // rgb(210,105,30)
|
||||
coral = 0xFF7F50, // rgb(255,127,80)
|
||||
cornflower_blue = 0x6495ED, // rgb(100,149,237)
|
||||
cornsilk = 0xFFF8DC, // rgb(255,248,220)
|
||||
crimson = 0xDC143C, // rgb(220,20,60)
|
||||
cyan = 0x00FFFF, // rgb(0,255,255)
|
||||
dark_blue = 0x00008B, // rgb(0,0,139)
|
||||
dark_cyan = 0x008B8B, // rgb(0,139,139)
|
||||
dark_golden_rod = 0xB8860B, // rgb(184,134,11)
|
||||
dark_gray = 0xA9A9A9, // rgb(169,169,169)
|
||||
dark_green = 0x006400, // rgb(0,100,0)
|
||||
dark_khaki = 0xBDB76B, // rgb(189,183,107)
|
||||
dark_magenta = 0x8B008B, // rgb(139,0,139)
|
||||
dark_olive_green = 0x556B2F, // rgb(85,107,47)
|
||||
dark_orange = 0xFF8C00, // rgb(255,140,0)
|
||||
dark_orchid = 0x9932CC, // rgb(153,50,204)
|
||||
dark_red = 0x8B0000, // rgb(139,0,0)
|
||||
dark_salmon = 0xE9967A, // rgb(233,150,122)
|
||||
dark_sea_green = 0x8FBC8F, // rgb(143,188,143)
|
||||
dark_slate_blue = 0x483D8B, // rgb(72,61,139)
|
||||
dark_slate_gray = 0x2F4F4F, // rgb(47,79,79)
|
||||
dark_turquoise = 0x00CED1, // rgb(0,206,209)
|
||||
dark_violet = 0x9400D3, // rgb(148,0,211)
|
||||
deep_pink = 0xFF1493, // rgb(255,20,147)
|
||||
deep_sky_blue = 0x00BFFF, // rgb(0,191,255)
|
||||
dim_gray = 0x696969, // rgb(105,105,105)
|
||||
dodger_blue = 0x1E90FF, // rgb(30,144,255)
|
||||
fire_brick = 0xB22222, // rgb(178,34,34)
|
||||
floral_white = 0xFFFAF0, // rgb(255,250,240)
|
||||
forest_green = 0x228B22, // rgb(34,139,34)
|
||||
fuchsia = 0xFF00FF, // rgb(255,0,255)
|
||||
gainsboro = 0xDCDCDC, // rgb(220,220,220)
|
||||
ghost_white = 0xF8F8FF, // rgb(248,248,255)
|
||||
gold = 0xFFD700, // rgb(255,215,0)
|
||||
golden_rod = 0xDAA520, // rgb(218,165,32)
|
||||
gray = 0x808080, // rgb(128,128,128)
|
||||
green = 0x008000, // rgb(0,128,0)
|
||||
green_yellow = 0xADFF2F, // rgb(173,255,47)
|
||||
honey_dew = 0xF0FFF0, // rgb(240,255,240)
|
||||
hot_pink = 0xFF69B4, // rgb(255,105,180)
|
||||
indian_red = 0xCD5C5C, // rgb(205,92,92)
|
||||
indigo = 0x4B0082, // rgb(75,0,130)
|
||||
ivory = 0xFFFFF0, // rgb(255,255,240)
|
||||
khaki = 0xF0E68C, // rgb(240,230,140)
|
||||
lavender = 0xE6E6FA, // rgb(230,230,250)
|
||||
lavender_blush = 0xFFF0F5, // rgb(255,240,245)
|
||||
lawn_green = 0x7CFC00, // rgb(124,252,0)
|
||||
lemon_chiffon = 0xFFFACD, // rgb(255,250,205)
|
||||
light_blue = 0xADD8E6, // rgb(173,216,230)
|
||||
light_coral = 0xF08080, // rgb(240,128,128)
|
||||
light_cyan = 0xE0FFFF, // rgb(224,255,255)
|
||||
light_golden_rod_yellow = 0xFAFAD2, // rgb(250,250,210)
|
||||
light_gray = 0xD3D3D3, // rgb(211,211,211)
|
||||
light_green = 0x90EE90, // rgb(144,238,144)
|
||||
light_pink = 0xFFB6C1, // rgb(255,182,193)
|
||||
light_salmon = 0xFFA07A, // rgb(255,160,122)
|
||||
light_sea_green = 0x20B2AA, // rgb(32,178,170)
|
||||
light_sky_blue = 0x87CEFA, // rgb(135,206,250)
|
||||
light_slate_gray = 0x778899, // rgb(119,136,153)
|
||||
light_steel_blue = 0xB0C4DE, // rgb(176,196,222)
|
||||
light_yellow = 0xFFFFE0, // rgb(255,255,224)
|
||||
lime = 0x00FF00, // rgb(0,255,0)
|
||||
lime_green = 0x32CD32, // rgb(50,205,50)
|
||||
linen = 0xFAF0E6, // rgb(250,240,230)
|
||||
magenta = 0xFF00FF, // rgb(255,0,255)
|
||||
maroon = 0x800000, // rgb(128,0,0)
|
||||
medium_aqua_marine = 0x66CDAA, // rgb(102,205,170)
|
||||
medium_blue = 0x0000CD, // rgb(0,0,205)
|
||||
medium_orchid = 0xBA55D3, // rgb(186,85,211)
|
||||
medium_purple = 0x9370DB, // rgb(147,112,219)
|
||||
medium_sea_green = 0x3CB371, // rgb(60,179,113)
|
||||
medium_slate_blue = 0x7B68EE, // rgb(123,104,238)
|
||||
medium_spring_green = 0x00FA9A, // rgb(0,250,154)
|
||||
medium_turquoise = 0x48D1CC, // rgb(72,209,204)
|
||||
medium_violet_red = 0xC71585, // rgb(199,21,133)
|
||||
midnight_blue = 0x191970, // rgb(25,25,112)
|
||||
mint_cream = 0xF5FFFA, // rgb(245,255,250)
|
||||
misty_rose = 0xFFE4E1, // rgb(255,228,225)
|
||||
moccasin = 0xFFE4B5, // rgb(255,228,181)
|
||||
navajo_white = 0xFFDEAD, // rgb(255,222,173)
|
||||
navy = 0x000080, // rgb(0,0,128)
|
||||
old_lace = 0xFDF5E6, // rgb(253,245,230)
|
||||
olive = 0x808000, // rgb(128,128,0)
|
||||
olive_drab = 0x6B8E23, // rgb(107,142,35)
|
||||
orange = 0xFFA500, // rgb(255,165,0)
|
||||
orange_red = 0xFF4500, // rgb(255,69,0)
|
||||
orchid = 0xDA70D6, // rgb(218,112,214)
|
||||
pale_golden_rod = 0xEEE8AA, // rgb(238,232,170)
|
||||
pale_green = 0x98FB98, // rgb(152,251,152)
|
||||
pale_turquoise = 0xAFEEEE, // rgb(175,238,238)
|
||||
pale_violet_red = 0xDB7093, // rgb(219,112,147)
|
||||
papaya_whip = 0xFFEFD5, // rgb(255,239,213)
|
||||
peach_puff = 0xFFDAB9, // rgb(255,218,185)
|
||||
peru = 0xCD853F, // rgb(205,133,63)
|
||||
pink = 0xFFC0CB, // rgb(255,192,203)
|
||||
plum = 0xDDA0DD, // rgb(221,160,221)
|
||||
powder_blue = 0xB0E0E6, // rgb(176,224,230)
|
||||
purple = 0x800080, // rgb(128,0,128)
|
||||
rebecca_purple = 0x663399, // rgb(102,51,153)
|
||||
red = 0xFF0000, // rgb(255,0,0)
|
||||
rosy_brown = 0xBC8F8F, // rgb(188,143,143)
|
||||
royal_blue = 0x4169E1, // rgb(65,105,225)
|
||||
saddle_brown = 0x8B4513, // rgb(139,69,19)
|
||||
salmon = 0xFA8072, // rgb(250,128,114)
|
||||
sandy_brown = 0xF4A460, // rgb(244,164,96)
|
||||
sea_green = 0x2E8B57, // rgb(46,139,87)
|
||||
sea_shell = 0xFFF5EE, // rgb(255,245,238)
|
||||
sienna = 0xA0522D, // rgb(160,82,45)
|
||||
silver = 0xC0C0C0, // rgb(192,192,192)
|
||||
sky_blue = 0x87CEEB, // rgb(135,206,235)
|
||||
slate_blue = 0x6A5ACD, // rgb(106,90,205)
|
||||
slate_gray = 0x708090, // rgb(112,128,144)
|
||||
snow = 0xFFFAFA, // rgb(255,250,250)
|
||||
spring_green = 0x00FF7F, // rgb(0,255,127)
|
||||
steel_blue = 0x4682B4, // rgb(70,130,180)
|
||||
tan = 0xD2B48C, // rgb(210,180,140)
|
||||
teal = 0x008080, // rgb(0,128,128)
|
||||
thistle = 0xD8BFD8, // rgb(216,191,216)
|
||||
tomato = 0xFF6347, // rgb(255,99,71)
|
||||
turquoise = 0x40E0D0, // rgb(64,224,208)
|
||||
violet = 0xEE82EE, // rgb(238,130,238)
|
||||
wheat = 0xF5DEB3, // rgb(245,222,179)
|
||||
white = 0xFFFFFF, // rgb(255,255,255)
|
||||
white_smoke = 0xF5F5F5, // rgb(245,245,245)
|
||||
yellow = 0xFFFF00, // rgb(255,255,0)
|
||||
yellow_green = 0x9ACD32, // rgb(154,205,50)
|
||||
}; // enum class colors
|
||||
|
||||
FMT_END_NAMESPACE
|
||||
|
||||
#endif // FMT_COLORS_H_
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,866 +0,0 @@
|
||||
// Formatting library for C++
|
||||
//
|
||||
// Copyright (c) 2012 - 2016, Victor Zverovich
|
||||
// All rights reserved.
|
||||
//
|
||||
// For the license information refer to format.h.
|
||||
|
||||
#ifndef FMT_FORMAT_INL_H_
|
||||
#define FMT_FORMAT_INL_H_
|
||||
|
||||
#include "format.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <cctype>
|
||||
#include <cerrno>
|
||||
#include <climits>
|
||||
#include <cmath>
|
||||
#include <cstdarg>
|
||||
#include <cstddef> // for std::ptrdiff_t
|
||||
#include <cstring> // for std::memmove
|
||||
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
|
||||
# include <locale>
|
||||
#endif
|
||||
|
||||
#if FMT_USE_WINDOWS_H
|
||||
# if !defined(FMT_HEADER_ONLY) && !defined(WIN32_LEAN_AND_MEAN)
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# endif
|
||||
# if defined(NOMINMAX) || defined(FMT_WIN_MINMAX)
|
||||
# include <windows.h>
|
||||
# else
|
||||
# define NOMINMAX
|
||||
# include <windows.h>
|
||||
# undef NOMINMAX
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if FMT_EXCEPTIONS
|
||||
# define FMT_TRY try
|
||||
# define FMT_CATCH(x) catch (x)
|
||||
#else
|
||||
# define FMT_TRY if (true)
|
||||
# define FMT_CATCH(x) if (false)
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable: 4127) // conditional expression is constant
|
||||
# pragma warning(disable: 4702) // unreachable code
|
||||
// Disable deprecation warning for strerror. The latter is not called but
|
||||
// MSVC fails to detect it.
|
||||
# pragma warning(disable: 4996)
|
||||
#endif
|
||||
|
||||
// Dummy implementations of strerror_r and strerror_s called if corresponding
|
||||
// system functions are not available.
|
||||
inline fmt::internal::null<> strerror_r(int, char *, ...) {
|
||||
return fmt::internal::null<>();
|
||||
}
|
||||
inline fmt::internal::null<> strerror_s(char *, std::size_t, ...) {
|
||||
return fmt::internal::null<>();
|
||||
}
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
|
||||
namespace {
|
||||
|
||||
#ifndef _MSC_VER
|
||||
# define FMT_SNPRINTF snprintf
|
||||
#else // _MSC_VER
|
||||
inline int fmt_snprintf(char *buffer, size_t size, const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int result = vsnprintf_s(buffer, size, _TRUNCATE, format, args);
|
||||
va_end(args);
|
||||
return result;
|
||||
}
|
||||
# define FMT_SNPRINTF fmt_snprintf
|
||||
#endif // _MSC_VER
|
||||
|
||||
#if defined(_WIN32) && defined(__MINGW32__) && !defined(__NO_ISOCEXT)
|
||||
# define FMT_SWPRINTF snwprintf
|
||||
#else
|
||||
# define FMT_SWPRINTF swprintf
|
||||
#endif // defined(_WIN32) && defined(__MINGW32__) && !defined(__NO_ISOCEXT)
|
||||
|
||||
typedef void (*FormatFunc)(internal::buffer &, int, string_view);
|
||||
|
||||
// Portable thread-safe version of strerror.
|
||||
// Sets buffer to point to a string describing the error code.
|
||||
// This can be either a pointer to a string stored in buffer,
|
||||
// or a pointer to some static immutable string.
|
||||
// Returns one of the following values:
|
||||
// 0 - success
|
||||
// ERANGE - buffer is not large enough to store the error message
|
||||
// other - failure
|
||||
// Buffer should be at least of size 1.
|
||||
int safe_strerror(
|
||||
int error_code, char *&buffer, std::size_t buffer_size) FMT_NOEXCEPT {
|
||||
FMT_ASSERT(buffer != FMT_NULL && buffer_size != 0, "invalid buffer");
|
||||
|
||||
class dispatcher {
|
||||
private:
|
||||
int error_code_;
|
||||
char *&buffer_;
|
||||
std::size_t buffer_size_;
|
||||
|
||||
// A noop assignment operator to avoid bogus warnings.
|
||||
void operator=(const dispatcher &) {}
|
||||
|
||||
// Handle the result of XSI-compliant version of strerror_r.
|
||||
int handle(int result) {
|
||||
// glibc versions before 2.13 return result in errno.
|
||||
return result == -1 ? errno : result;
|
||||
}
|
||||
|
||||
// Handle the result of GNU-specific version of strerror_r.
|
||||
int handle(char *message) {
|
||||
// If the buffer is full then the message is probably truncated.
|
||||
if (message == buffer_ && strlen(buffer_) == buffer_size_ - 1)
|
||||
return ERANGE;
|
||||
buffer_ = message;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Handle the case when strerror_r is not available.
|
||||
int handle(internal::null<>) {
|
||||
return fallback(strerror_s(buffer_, buffer_size_, error_code_));
|
||||
}
|
||||
|
||||
// Fallback to strerror_s when strerror_r is not available.
|
||||
int fallback(int result) {
|
||||
// If the buffer is full then the message is probably truncated.
|
||||
return result == 0 && strlen(buffer_) == buffer_size_ - 1 ?
|
||||
ERANGE : result;
|
||||
}
|
||||
|
||||
// Fallback to strerror if strerror_r and strerror_s are not available.
|
||||
int fallback(internal::null<>) {
|
||||
errno = 0;
|
||||
buffer_ = strerror(error_code_);
|
||||
return errno;
|
||||
}
|
||||
|
||||
public:
|
||||
dispatcher(int err_code, char *&buf, std::size_t buf_size)
|
||||
: error_code_(err_code), buffer_(buf), buffer_size_(buf_size) {}
|
||||
|
||||
int run() {
|
||||
return handle(strerror_r(error_code_, buffer_, buffer_size_));
|
||||
}
|
||||
};
|
||||
return dispatcher(error_code, buffer, buffer_size).run();
|
||||
}
|
||||
|
||||
void format_error_code(internal::buffer &out, int error_code,
|
||||
string_view message) FMT_NOEXCEPT {
|
||||
// Report error code making sure that the output fits into
|
||||
// inline_buffer_size to avoid dynamic memory allocation and potential
|
||||
// bad_alloc.
|
||||
out.resize(0);
|
||||
static const char SEP[] = ": ";
|
||||
static const char ERROR_STR[] = "error ";
|
||||
// Subtract 2 to account for terminating null characters in SEP and ERROR_STR.
|
||||
std::size_t error_code_size = sizeof(SEP) + sizeof(ERROR_STR) - 2;
|
||||
typedef internal::int_traits<int>::main_type main_type;
|
||||
main_type abs_value = static_cast<main_type>(error_code);
|
||||
if (internal::is_negative(error_code)) {
|
||||
abs_value = 0 - abs_value;
|
||||
++error_code_size;
|
||||
}
|
||||
error_code_size += internal::count_digits(abs_value);
|
||||
writer w(out);
|
||||
if (message.size() <= inline_buffer_size - error_code_size) {
|
||||
w.write(message);
|
||||
w.write(SEP);
|
||||
}
|
||||
w.write(ERROR_STR);
|
||||
w.write(error_code);
|
||||
assert(out.size() <= inline_buffer_size);
|
||||
}
|
||||
|
||||
void report_error(FormatFunc func, int error_code,
|
||||
string_view message) FMT_NOEXCEPT {
|
||||
memory_buffer full_message;
|
||||
func(full_message, error_code, message);
|
||||
// Use Writer::data instead of Writer::c_str to avoid potential memory
|
||||
// allocation.
|
||||
std::fwrite(full_message.data(), full_message.size(), 1, stderr);
|
||||
std::fputc('\n', stderr);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
|
||||
class locale {
|
||||
private:
|
||||
std::locale locale_;
|
||||
|
||||
public:
|
||||
explicit locale(std::locale loc = std::locale()) : locale_(loc) {}
|
||||
std::locale get() { return locale_; }
|
||||
};
|
||||
|
||||
FMT_FUNC size_t internal::count_code_points(u8string_view s) {
|
||||
const char8_t *data = s.data();
|
||||
int num_code_points = 0;
|
||||
for (size_t i = 0, size = s.size(); i != size; ++i) {
|
||||
if ((data[i].value & 0xc0) != 0x80)
|
||||
++num_code_points;
|
||||
}
|
||||
return num_code_points;
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
FMT_FUNC Char internal::thousands_sep(locale_provider *lp) {
|
||||
std::locale loc = lp ? lp->locale().get() : std::locale();
|
||||
return std::use_facet<std::numpunct<Char>>(loc).thousands_sep();
|
||||
}
|
||||
#else
|
||||
template <typename Char>
|
||||
FMT_FUNC Char internal::thousands_sep(locale_provider *lp) {
|
||||
return FMT_STATIC_THOUSANDS_SEPARATOR;
|
||||
}
|
||||
#endif
|
||||
|
||||
FMT_FUNC void system_error::init(
|
||||
int err_code, string_view format_str, format_args args) {
|
||||
error_code_ = err_code;
|
||||
memory_buffer buffer;
|
||||
format_system_error(buffer, err_code, vformat(format_str, args));
|
||||
std::runtime_error &base = *this;
|
||||
base = std::runtime_error(to_string(buffer));
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
template <typename T>
|
||||
int char_traits<char>::format_float(
|
||||
char *buffer, std::size_t size, const char *format, int precision, T value) {
|
||||
return precision < 0 ?
|
||||
FMT_SNPRINTF(buffer, size, format, value) :
|
||||
FMT_SNPRINTF(buffer, size, format, precision, value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int char_traits<wchar_t>::format_float(
|
||||
wchar_t *buffer, std::size_t size, const wchar_t *format, int precision,
|
||||
T value) {
|
||||
return precision < 0 ?
|
||||
FMT_SWPRINTF(buffer, size, format, value) :
|
||||
FMT_SWPRINTF(buffer, size, format, precision, value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const char basic_data<T>::DIGITS[] =
|
||||
"0001020304050607080910111213141516171819"
|
||||
"2021222324252627282930313233343536373839"
|
||||
"4041424344454647484950515253545556575859"
|
||||
"6061626364656667686970717273747576777879"
|
||||
"8081828384858687888990919293949596979899";
|
||||
|
||||
#define FMT_POWERS_OF_10(factor) \
|
||||
factor * 10, \
|
||||
factor * 100, \
|
||||
factor * 1000, \
|
||||
factor * 10000, \
|
||||
factor * 100000, \
|
||||
factor * 1000000, \
|
||||
factor * 10000000, \
|
||||
factor * 100000000, \
|
||||
factor * 1000000000
|
||||
|
||||
template <typename T>
|
||||
const uint32_t basic_data<T>::POWERS_OF_10_32[] = {
|
||||
1, FMT_POWERS_OF_10(1)
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
const uint32_t basic_data<T>::ZERO_OR_POWERS_OF_10_32[] = {
|
||||
0, FMT_POWERS_OF_10(1)
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
const uint64_t basic_data<T>::ZERO_OR_POWERS_OF_10_64[] = {
|
||||
0,
|
||||
FMT_POWERS_OF_10(1),
|
||||
FMT_POWERS_OF_10(1000000000ull),
|
||||
10000000000000000000ull
|
||||
};
|
||||
|
||||
// Normalized 64-bit significands of pow(10, k), for k = -348, -340, ..., 340.
|
||||
// These are generated by support/compute-powers.py.
|
||||
template <typename T>
|
||||
const uint64_t basic_data<T>::POW10_SIGNIFICANDS[] = {
|
||||
0xfa8fd5a0081c0288, 0xbaaee17fa23ebf76, 0x8b16fb203055ac76,
|
||||
0xcf42894a5dce35ea, 0x9a6bb0aa55653b2d, 0xe61acf033d1a45df,
|
||||
0xab70fe17c79ac6ca, 0xff77b1fcbebcdc4f, 0xbe5691ef416bd60c,
|
||||
0x8dd01fad907ffc3c, 0xd3515c2831559a83, 0x9d71ac8fada6c9b5,
|
||||
0xea9c227723ee8bcb, 0xaecc49914078536d, 0x823c12795db6ce57,
|
||||
0xc21094364dfb5637, 0x9096ea6f3848984f, 0xd77485cb25823ac7,
|
||||
0xa086cfcd97bf97f4, 0xef340a98172aace5, 0xb23867fb2a35b28e,
|
||||
0x84c8d4dfd2c63f3b, 0xc5dd44271ad3cdba, 0x936b9fcebb25c996,
|
||||
0xdbac6c247d62a584, 0xa3ab66580d5fdaf6, 0xf3e2f893dec3f126,
|
||||
0xb5b5ada8aaff80b8, 0x87625f056c7c4a8b, 0xc9bcff6034c13053,
|
||||
0x964e858c91ba2655, 0xdff9772470297ebd, 0xa6dfbd9fb8e5b88f,
|
||||
0xf8a95fcf88747d94, 0xb94470938fa89bcf, 0x8a08f0f8bf0f156b,
|
||||
0xcdb02555653131b6, 0x993fe2c6d07b7fac, 0xe45c10c42a2b3b06,
|
||||
0xaa242499697392d3, 0xfd87b5f28300ca0e, 0xbce5086492111aeb,
|
||||
0x8cbccc096f5088cc, 0xd1b71758e219652c, 0x9c40000000000000,
|
||||
0xe8d4a51000000000, 0xad78ebc5ac620000, 0x813f3978f8940984,
|
||||
0xc097ce7bc90715b3, 0x8f7e32ce7bea5c70, 0xd5d238a4abe98068,
|
||||
0x9f4f2726179a2245, 0xed63a231d4c4fb27, 0xb0de65388cc8ada8,
|
||||
0x83c7088e1aab65db, 0xc45d1df942711d9a, 0x924d692ca61be758,
|
||||
0xda01ee641a708dea, 0xa26da3999aef774a, 0xf209787bb47d6b85,
|
||||
0xb454e4a179dd1877, 0x865b86925b9bc5c2, 0xc83553c5c8965d3d,
|
||||
0x952ab45cfa97a0b3, 0xde469fbd99a05fe3, 0xa59bc234db398c25,
|
||||
0xf6c69a72a3989f5c, 0xb7dcbf5354e9bece, 0x88fcf317f22241e2,
|
||||
0xcc20ce9bd35c78a5, 0x98165af37b2153df, 0xe2a0b5dc971f303a,
|
||||
0xa8d9d1535ce3b396, 0xfb9b7cd9a4a7443c, 0xbb764c4ca7a44410,
|
||||
0x8bab8eefb6409c1a, 0xd01fef10a657842c, 0x9b10a4e5e9913129,
|
||||
0xe7109bfba19c0c9d, 0xac2820d9623bf429, 0x80444b5e7aa7cf85,
|
||||
0xbf21e44003acdd2d, 0x8e679c2f5e44ff8f, 0xd433179d9c8cb841,
|
||||
0x9e19db92b4e31ba9, 0xeb96bf6ebadf77d9, 0xaf87023b9bf0ee6b,
|
||||
};
|
||||
|
||||
// Binary exponents of pow(10, k), for k = -348, -340, ..., 340, corresponding
|
||||
// to significands above.
|
||||
template <typename T>
|
||||
const int16_t basic_data<T>::POW10_EXPONENTS[] = {
|
||||
-1220, -1193, -1166, -1140, -1113, -1087, -1060, -1034, -1007, -980, -954,
|
||||
-927, -901, -874, -847, -821, -794, -768, -741, -715, -688, -661,
|
||||
-635, -608, -582, -555, -529, -502, -475, -449, -422, -396, -369,
|
||||
-343, -316, -289, -263, -236, -210, -183, -157, -130, -103, -77,
|
||||
-50, -24, 3, 30, 56, 83, 109, 136, 162, 189, 216,
|
||||
242, 269, 295, 322, 348, 375, 402, 428, 455, 481, 508,
|
||||
534, 561, 588, 614, 641, 667, 694, 720, 747, 774, 800,
|
||||
827, 853, 880, 907, 933, 960, 986, 1013, 1039, 1066
|
||||
};
|
||||
|
||||
template <typename T> const char basic_data<T>::RESET_COLOR[] = "\x1b[0m";
|
||||
template <typename T> const wchar_t basic_data<T>::WRESET_COLOR[] = L"\x1b[0m";
|
||||
|
||||
// A handmade floating-point number f * pow(2, e).
|
||||
class fp {
|
||||
private:
|
||||
typedef uint64_t significand_type;
|
||||
|
||||
// All sizes are in bits.
|
||||
static FMT_CONSTEXPR_DECL const int char_size =
|
||||
std::numeric_limits<unsigned char>::digits;
|
||||
// Subtract 1 to account for an implicit most significant bit in the
|
||||
// normalized form.
|
||||
static FMT_CONSTEXPR_DECL const int double_significand_size =
|
||||
std::numeric_limits<double>::digits - 1;
|
||||
static FMT_CONSTEXPR_DECL const uint64_t implicit_bit =
|
||||
1ull << double_significand_size;
|
||||
|
||||
public:
|
||||
significand_type f;
|
||||
int e;
|
||||
|
||||
static FMT_CONSTEXPR_DECL const int significand_size =
|
||||
sizeof(significand_type) * char_size;
|
||||
|
||||
fp(): f(0), e(0) {}
|
||||
fp(uint64_t f, int e): f(f), e(e) {}
|
||||
|
||||
// Constructs fp from an IEEE754 double. It is a template to prevent compile
|
||||
// errors on platforms where double is not IEEE754.
|
||||
template <typename Double>
|
||||
explicit fp(Double d) {
|
||||
// Assume double is in the format [sign][exponent][significand].
|
||||
typedef std::numeric_limits<Double> limits;
|
||||
const int double_size = static_cast<int>(sizeof(Double) * char_size);
|
||||
const int exponent_size =
|
||||
double_size - double_significand_size - 1; // -1 for sign
|
||||
const uint64_t significand_mask = implicit_bit - 1;
|
||||
const uint64_t exponent_mask = (~0ull >> 1) & ~significand_mask;
|
||||
const int exponent_bias = (1 << exponent_size) - limits::max_exponent - 1;
|
||||
auto u = bit_cast<uint64_t>(d);
|
||||
auto biased_e = (u & exponent_mask) >> double_significand_size;
|
||||
f = u & significand_mask;
|
||||
if (biased_e != 0)
|
||||
f += implicit_bit;
|
||||
else
|
||||
biased_e = 1; // Subnormals use biased exponent 1 (min exponent).
|
||||
e = static_cast<int>(biased_e - exponent_bias - double_significand_size);
|
||||
}
|
||||
|
||||
// Normalizes the value converted from double and multiplied by (1 << SHIFT).
|
||||
template <int SHIFT = 0>
|
||||
void normalize() {
|
||||
// Handle subnormals.
|
||||
auto shifted_implicit_bit = implicit_bit << SHIFT;
|
||||
while ((f & shifted_implicit_bit) == 0) {
|
||||
f <<= 1;
|
||||
--e;
|
||||
}
|
||||
// Subtract 1 to account for hidden bit.
|
||||
auto offset = significand_size - double_significand_size - SHIFT - 1;
|
||||
f <<= offset;
|
||||
e -= offset;
|
||||
}
|
||||
|
||||
// Compute lower and upper boundaries (m^- and m^+ in the Grisu paper), where
|
||||
// a boundary is a value half way between the number and its predecessor
|
||||
// (lower) or successor (upper). The upper boundary is normalized and lower
|
||||
// has the same exponent but may be not normalized.
|
||||
void compute_boundaries(fp &lower, fp &upper) const {
|
||||
lower = f == implicit_bit ?
|
||||
fp((f << 2) - 1, e - 2) : fp((f << 1) - 1, e - 1);
|
||||
upper = fp((f << 1) + 1, e - 1);
|
||||
upper.normalize<1>(); // 1 is to account for the exponent shift above.
|
||||
lower.f <<= lower.e - upper.e;
|
||||
lower.e = upper.e;
|
||||
}
|
||||
};
|
||||
|
||||
// Returns an fp number representing x - y. Result may not be normalized.
|
||||
inline fp operator-(fp x, fp y) {
|
||||
FMT_ASSERT(x.f >= y.f && x.e == y.e, "invalid operands");
|
||||
return fp(x.f - y.f, x.e);
|
||||
}
|
||||
|
||||
// Computes an fp number r with r.f = x.f * y.f / pow(2, 64) rounded to nearest
|
||||
// with half-up tie breaking, r.e = x.e + y.e + 64. Result may not be normalized.
|
||||
FMT_API fp operator*(fp x, fp y);
|
||||
|
||||
// Returns cached power (of 10) c_k = c_k.f * pow(2, c_k.e) such that its
|
||||
// (binary) exponent satisfies min_exponent <= c_k.e <= min_exponent + 3.
|
||||
FMT_API fp get_cached_power(int min_exponent, int &pow10_exponent);
|
||||
|
||||
FMT_FUNC fp operator*(fp x, fp y) {
|
||||
// Multiply 32-bit parts of significands.
|
||||
uint64_t mask = (1ULL << 32) - 1;
|
||||
uint64_t a = x.f >> 32, b = x.f & mask;
|
||||
uint64_t c = y.f >> 32, d = y.f & mask;
|
||||
uint64_t ac = a * c, bc = b * c, ad = a * d, bd = b * d;
|
||||
// Compute mid 64-bit of result and round.
|
||||
uint64_t mid = (bd >> 32) + (ad & mask) + (bc & mask) + (1U << 31);
|
||||
return fp(ac + (ad >> 32) + (bc >> 32) + (mid >> 32), x.e + y.e + 64);
|
||||
}
|
||||
|
||||
FMT_FUNC fp get_cached_power(int min_exponent, int &pow10_exponent) {
|
||||
const double one_over_log2_10 = 0.30102999566398114; // 1 / log2(10)
|
||||
int index = static_cast<int>(std::ceil(
|
||||
(min_exponent + fp::significand_size - 1) * one_over_log2_10));
|
||||
// Decimal exponent of the first (smallest) cached power of 10.
|
||||
const int first_dec_exp = -348;
|
||||
// Difference between 2 consecutive decimal exponents in cached powers of 10.
|
||||
const int dec_exp_step = 8;
|
||||
index = (index - first_dec_exp - 1) / dec_exp_step + 1;
|
||||
pow10_exponent = first_dec_exp + index * dec_exp_step;
|
||||
return fp(data::POW10_SIGNIFICANDS[index], data::POW10_EXPONENTS[index]);
|
||||
}
|
||||
|
||||
// Generates output using Grisu2 digit-gen algorithm.
|
||||
FMT_FUNC void grisu2_gen_digits(
|
||||
const fp &scaled_value, const fp &scaled_upper, uint64_t delta,
|
||||
char *buffer, size_t &size, int &dec_exp) {
|
||||
internal::fp one(1ull << -scaled_upper.e, scaled_upper.e);
|
||||
// hi (p1 in Grisu) contains the most significant digits of scaled_upper.
|
||||
// hi = floor(scaled_upper / one).
|
||||
uint32_t hi = static_cast<uint32_t>(scaled_upper.f >> -one.e);
|
||||
// lo (p2 in Grisu) contains the least significants digits of scaled_upper.
|
||||
// lo = scaled_upper mod 1.
|
||||
uint64_t lo = scaled_upper.f & (one.f - 1);
|
||||
size = 0;
|
||||
auto exp = count_digits(hi); // kappa in Grisu.
|
||||
while (exp > 0) {
|
||||
uint32_t digit = 0;
|
||||
// This optimization by miloyip reduces the number of integer divisions by
|
||||
// one per iteration.
|
||||
switch (exp) {
|
||||
case 10: digit = hi / 1000000000; hi %= 1000000000; break;
|
||||
case 9: digit = hi / 100000000; hi %= 100000000; break;
|
||||
case 8: digit = hi / 10000000; hi %= 10000000; break;
|
||||
case 7: digit = hi / 1000000; hi %= 1000000; break;
|
||||
case 6: digit = hi / 100000; hi %= 100000; break;
|
||||
case 5: digit = hi / 10000; hi %= 10000; break;
|
||||
case 4: digit = hi / 1000; hi %= 1000; break;
|
||||
case 3: digit = hi / 100; hi %= 100; break;
|
||||
case 2: digit = hi / 10; hi %= 10; break;
|
||||
case 1: digit = hi; hi = 0; break;
|
||||
default:
|
||||
FMT_ASSERT(false, "invalid number of digits");
|
||||
}
|
||||
if (digit != 0 || size != 0)
|
||||
buffer[size++] = static_cast<char>('0' + digit);
|
||||
--exp;
|
||||
uint64_t remainder = (static_cast<uint64_t>(hi) << -one.e) + lo;
|
||||
if (remainder <= delta) {
|
||||
dec_exp += exp;
|
||||
// TODO: use scaled_value
|
||||
(void)scaled_value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (;;) {
|
||||
lo *= 10;
|
||||
delta *= 10;
|
||||
char digit = static_cast<char>(lo >> -one.e);
|
||||
if (digit != 0 || size != 0)
|
||||
buffer[size++] = static_cast<char>('0' + digit);
|
||||
lo &= one.f - 1;
|
||||
--exp;
|
||||
if (lo < delta) {
|
||||
dec_exp += exp;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FMT_FUNC void grisu2_format_positive(double value, char *buffer, size_t &size,
|
||||
int &dec_exp) {
|
||||
FMT_ASSERT(value > 0, "value is nonpositive");
|
||||
fp fp_value(value);
|
||||
fp lower, upper; // w^- and w^+ in the Grisu paper.
|
||||
fp_value.compute_boundaries(lower, upper);
|
||||
// Find a cached power of 10 close to 1 / upper.
|
||||
const int min_exp = -60; // alpha in Grisu.
|
||||
auto dec_pow = get_cached_power( // \tilde{c}_{-k} in Grisu.
|
||||
min_exp - (upper.e + fp::significand_size), dec_exp);
|
||||
dec_exp = -dec_exp;
|
||||
fp_value.normalize();
|
||||
fp scaled_value = fp_value * dec_pow;
|
||||
fp scaled_lower = lower * dec_pow; // \tilde{M}^- in Grisu.
|
||||
fp scaled_upper = upper * dec_pow; // \tilde{M}^+ in Grisu.
|
||||
++scaled_lower.f; // \tilde{M}^- + 1 ulp -> M^-_{\uparrow}.
|
||||
--scaled_upper.f; // \tilde{M}^+ - 1 ulp -> M^+_{\downarrow}.
|
||||
uint64_t delta = scaled_upper.f - scaled_lower.f;
|
||||
grisu2_gen_digits(scaled_value, scaled_upper, delta, buffer, size, dec_exp);
|
||||
}
|
||||
|
||||
FMT_FUNC void round(char *buffer, size_t &size, int &exp,
|
||||
int digits_to_remove) {
|
||||
size -= to_unsigned(digits_to_remove);
|
||||
exp += digits_to_remove;
|
||||
int digit = buffer[size] - '0';
|
||||
// TODO: proper rounding and carry
|
||||
if (digit > 5 || (digit == 5 && (digits_to_remove > 1 ||
|
||||
(buffer[size - 1] - '0') % 2) != 0)) {
|
||||
++buffer[size - 1];
|
||||
}
|
||||
}
|
||||
|
||||
// Writes the exponent exp in the form "[+-]d{1,3}" to buffer.
|
||||
FMT_FUNC char *write_exponent(char *buffer, int exp) {
|
||||
FMT_ASSERT(-1000 < exp && exp < 1000, "exponent out of range");
|
||||
if (exp < 0) {
|
||||
*buffer++ = '-';
|
||||
exp = -exp;
|
||||
} else {
|
||||
*buffer++ = '+';
|
||||
}
|
||||
if (exp >= 100) {
|
||||
*buffer++ = static_cast<char>('0' + exp / 100);
|
||||
exp %= 100;
|
||||
const char *d = data::DIGITS + exp * 2;
|
||||
*buffer++ = d[0];
|
||||
*buffer++ = d[1];
|
||||
} else {
|
||||
const char *d = data::DIGITS + exp * 2;
|
||||
*buffer++ = d[0];
|
||||
*buffer++ = d[1];
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
FMT_FUNC void format_exp_notation(
|
||||
char *buffer, size_t &size, int exp, int precision, bool upper) {
|
||||
// Insert a decimal point after the first digit and add an exponent.
|
||||
std::memmove(buffer + 2, buffer + 1, size - 1);
|
||||
buffer[1] = '.';
|
||||
exp += static_cast<int>(size) - 1;
|
||||
int num_digits = precision - static_cast<int>(size) + 1;
|
||||
if (num_digits > 0) {
|
||||
std::uninitialized_fill_n(buffer + size + 1, num_digits, '0');
|
||||
size += to_unsigned(num_digits);
|
||||
} else if (num_digits < 0) {
|
||||
round(buffer, size, exp, -num_digits);
|
||||
}
|
||||
char *p = buffer + size + 1;
|
||||
*p++ = upper ? 'E' : 'e';
|
||||
size = to_unsigned(write_exponent(p, exp) - buffer);
|
||||
}
|
||||
|
||||
// Prettifies the output of the Grisu2 algorithm.
|
||||
// The number is given as v = buffer * 10^exp.
|
||||
FMT_FUNC void grisu2_prettify(char *buffer, size_t &size, int exp,
|
||||
int precision, bool upper) {
|
||||
// pow(10, full_exp - 1) <= v <= pow(10, full_exp).
|
||||
int int_size = static_cast<int>(size);
|
||||
int full_exp = int_size + exp;
|
||||
const int exp_threshold = 21;
|
||||
if (int_size <= full_exp && full_exp <= exp_threshold) {
|
||||
// 1234e7 -> 12340000000[.0+]
|
||||
std::uninitialized_fill_n(buffer + int_size, full_exp - int_size, '0');
|
||||
char *p = buffer + full_exp;
|
||||
if (precision > 0) {
|
||||
*p++ = '.';
|
||||
std::uninitialized_fill_n(p, precision, '0');
|
||||
p += precision;
|
||||
}
|
||||
size = to_unsigned(p - buffer);
|
||||
} else if (0 < full_exp && full_exp <= exp_threshold) {
|
||||
// 1234e-2 -> 12.34[0+]
|
||||
int fractional_size = -exp;
|
||||
std::memmove(buffer + full_exp + 1, buffer + full_exp,
|
||||
to_unsigned(fractional_size));
|
||||
buffer[full_exp] = '.';
|
||||
int num_zeros = precision - fractional_size;
|
||||
if (num_zeros > 0) {
|
||||
std::uninitialized_fill_n(buffer + size + 1, num_zeros, '0');
|
||||
size += to_unsigned(num_zeros);
|
||||
}
|
||||
++size;
|
||||
} else if (-6 < full_exp && full_exp <= 0) {
|
||||
// 1234e-6 -> 0.001234
|
||||
int offset = 2 - full_exp;
|
||||
std::memmove(buffer + offset, buffer, size);
|
||||
buffer[0] = '0';
|
||||
buffer[1] = '.';
|
||||
std::uninitialized_fill_n(buffer + 2, -full_exp, '0');
|
||||
size = to_unsigned(int_size + offset);
|
||||
} else {
|
||||
format_exp_notation(buffer, size, exp, precision, upper);
|
||||
}
|
||||
}
|
||||
|
||||
#if FMT_CLANG_VERSION
|
||||
# define FMT_FALLTHROUGH [[clang::fallthrough]];
|
||||
#elif FMT_GCC_VERSION >= 700
|
||||
# define FMT_FALLTHROUGH [[gnu::fallthrough]];
|
||||
#else
|
||||
# define FMT_FALLTHROUGH
|
||||
#endif
|
||||
|
||||
// Formats a nonnegative value using Grisu2 algorithm. Grisu2 doesn't give any
|
||||
// guarantees on the shortness of the result.
|
||||
FMT_FUNC void grisu2_format(double value, char *buffer, size_t &size, char type,
|
||||
int precision, bool write_decimal_point) {
|
||||
FMT_ASSERT(value >= 0, "value is negative");
|
||||
int dec_exp = 0; // K in Grisu.
|
||||
if (value > 0) {
|
||||
grisu2_format_positive(value, buffer, size, dec_exp);
|
||||
} else {
|
||||
*buffer = '0';
|
||||
size = 1;
|
||||
}
|
||||
const int default_precision = 6;
|
||||
if (precision < 0)
|
||||
precision = default_precision;
|
||||
bool upper = false;
|
||||
switch (type) {
|
||||
case 'G':
|
||||
upper = true;
|
||||
FMT_FALLTHROUGH
|
||||
case '\0': case 'g': {
|
||||
int digits_to_remove = static_cast<int>(size) - precision;
|
||||
if (digits_to_remove > 0) {
|
||||
round(buffer, size, dec_exp, digits_to_remove);
|
||||
// Remove trailing zeros.
|
||||
while (size > 0 && buffer[size - 1] == '0') {
|
||||
--size;
|
||||
++dec_exp;
|
||||
}
|
||||
}
|
||||
precision = 0;
|
||||
break;
|
||||
}
|
||||
case 'F':
|
||||
upper = true;
|
||||
FMT_FALLTHROUGH
|
||||
case 'f': {
|
||||
int digits_to_remove = -dec_exp - precision;
|
||||
if (digits_to_remove > 0) {
|
||||
if (digits_to_remove >= static_cast<int>(size))
|
||||
digits_to_remove = static_cast<int>(size) - 1;
|
||||
round(buffer, size, dec_exp, digits_to_remove);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'e': case 'E':
|
||||
format_exp_notation(buffer, size, dec_exp, precision, type == 'E');
|
||||
return;
|
||||
}
|
||||
if (write_decimal_point && precision < 1)
|
||||
precision = 1;
|
||||
grisu2_prettify(buffer, size, dec_exp, precision, upper);
|
||||
}
|
||||
} // namespace internal
|
||||
|
||||
#if FMT_USE_WINDOWS_H
|
||||
|
||||
FMT_FUNC internal::utf8_to_utf16::utf8_to_utf16(string_view s) {
|
||||
static const char ERROR_MSG[] = "cannot convert string from UTF-8 to UTF-16";
|
||||
if (s.size() > INT_MAX)
|
||||
FMT_THROW(windows_error(ERROR_INVALID_PARAMETER, ERROR_MSG));
|
||||
int s_size = static_cast<int>(s.size());
|
||||
if (s_size == 0) {
|
||||
// MultiByteToWideChar does not support zero length, handle separately.
|
||||
buffer_.resize(1);
|
||||
buffer_[0] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
int length = MultiByteToWideChar(
|
||||
CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size, FMT_NULL, 0);
|
||||
if (length == 0)
|
||||
FMT_THROW(windows_error(GetLastError(), ERROR_MSG));
|
||||
buffer_.resize(length + 1);
|
||||
length = MultiByteToWideChar(
|
||||
CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size, &buffer_[0], length);
|
||||
if (length == 0)
|
||||
FMT_THROW(windows_error(GetLastError(), ERROR_MSG));
|
||||
buffer_[length] = 0;
|
||||
}
|
||||
|
||||
FMT_FUNC internal::utf16_to_utf8::utf16_to_utf8(wstring_view s) {
|
||||
if (int error_code = convert(s)) {
|
||||
FMT_THROW(windows_error(error_code,
|
||||
"cannot convert string from UTF-16 to UTF-8"));
|
||||
}
|
||||
}
|
||||
|
||||
FMT_FUNC int internal::utf16_to_utf8::convert(wstring_view s) {
|
||||
if (s.size() > INT_MAX)
|
||||
return ERROR_INVALID_PARAMETER;
|
||||
int s_size = static_cast<int>(s.size());
|
||||
if (s_size == 0) {
|
||||
// WideCharToMultiByte does not support zero length, handle separately.
|
||||
buffer_.resize(1);
|
||||
buffer_[0] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int length = WideCharToMultiByte(
|
||||
CP_UTF8, 0, s.data(), s_size, FMT_NULL, 0, FMT_NULL, FMT_NULL);
|
||||
if (length == 0)
|
||||
return GetLastError();
|
||||
buffer_.resize(length + 1);
|
||||
length = WideCharToMultiByte(
|
||||
CP_UTF8, 0, s.data(), s_size, &buffer_[0], length, FMT_NULL, FMT_NULL);
|
||||
if (length == 0)
|
||||
return GetLastError();
|
||||
buffer_[length] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
FMT_FUNC void windows_error::init(
|
||||
int err_code, string_view format_str, format_args args) {
|
||||
error_code_ = err_code;
|
||||
memory_buffer buffer;
|
||||
internal::format_windows_error(buffer, err_code, vformat(format_str, args));
|
||||
std::runtime_error &base = *this;
|
||||
base = std::runtime_error(to_string(buffer));
|
||||
}
|
||||
|
||||
FMT_FUNC void internal::format_windows_error(
|
||||
internal::buffer &out, int error_code, string_view message) FMT_NOEXCEPT {
|
||||
FMT_TRY {
|
||||
wmemory_buffer buf;
|
||||
buf.resize(inline_buffer_size);
|
||||
for (;;) {
|
||||
wchar_t *system_message = &buf[0];
|
||||
int result = FormatMessageW(
|
||||
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
FMT_NULL, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
system_message, static_cast<uint32_t>(buf.size()), FMT_NULL);
|
||||
if (result != 0) {
|
||||
utf16_to_utf8 utf8_message;
|
||||
if (utf8_message.convert(system_message) == ERROR_SUCCESS) {
|
||||
writer w(out);
|
||||
w.write(message);
|
||||
w.write(": ");
|
||||
w.write(utf8_message);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
|
||||
break; // Can't get error message, report error code instead.
|
||||
buf.resize(buf.size() * 2);
|
||||
}
|
||||
} FMT_CATCH(...) {}
|
||||
format_error_code(out, error_code, message);
|
||||
}
|
||||
|
||||
#endif // FMT_USE_WINDOWS_H
|
||||
|
||||
FMT_FUNC void format_system_error(
|
||||
internal::buffer &out, int error_code, string_view message) FMT_NOEXCEPT {
|
||||
FMT_TRY {
|
||||
memory_buffer buf;
|
||||
buf.resize(inline_buffer_size);
|
||||
for (;;) {
|
||||
char *system_message = &buf[0];
|
||||
int result = safe_strerror(error_code, system_message, buf.size());
|
||||
if (result == 0) {
|
||||
writer w(out);
|
||||
w.write(message);
|
||||
w.write(": ");
|
||||
w.write(system_message);
|
||||
return;
|
||||
}
|
||||
if (result != ERANGE)
|
||||
break; // Can't get error message, report error code instead.
|
||||
buf.resize(buf.size() * 2);
|
||||
}
|
||||
} FMT_CATCH(...) {}
|
||||
format_error_code(out, error_code, message);
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
void basic_fixed_buffer<Char>::grow(std::size_t) {
|
||||
FMT_THROW(std::runtime_error("buffer overflow"));
|
||||
}
|
||||
|
||||
FMT_FUNC void internal::error_handler::on_error(const char *message) {
|
||||
FMT_THROW(format_error(message));
|
||||
}
|
||||
|
||||
FMT_FUNC void report_system_error(
|
||||
int error_code, fmt::string_view message) FMT_NOEXCEPT {
|
||||
report_error(format_system_error, error_code, message);
|
||||
}
|
||||
|
||||
#if FMT_USE_WINDOWS_H
|
||||
FMT_FUNC void report_windows_error(
|
||||
int error_code, fmt::string_view message) FMT_NOEXCEPT {
|
||||
report_error(internal::format_windows_error, error_code, message);
|
||||
}
|
||||
#endif
|
||||
|
||||
FMT_FUNC void vprint(std::FILE *f, string_view format_str, format_args args) {
|
||||
memory_buffer buffer;
|
||||
vformat_to(buffer, format_str, args);
|
||||
std::fwrite(buffer.data(), 1, buffer.size(), f);
|
||||
}
|
||||
|
||||
FMT_FUNC void vprint(std::FILE *f, wstring_view format_str, wformat_args args) {
|
||||
wmemory_buffer buffer;
|
||||
vformat_to(buffer, format_str, args);
|
||||
std::fwrite(buffer.data(), sizeof(wchar_t), buffer.size(), f);
|
||||
}
|
||||
|
||||
FMT_FUNC void vprint(string_view format_str, format_args args) {
|
||||
vprint(stdout, format_str, args);
|
||||
}
|
||||
|
||||
FMT_FUNC void vprint(wstring_view format_str, wformat_args args) {
|
||||
vprint(stdout, format_str, args);
|
||||
}
|
||||
|
||||
#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR)
|
||||
FMT_FUNC locale locale_provider::locale() { return fmt::locale(); }
|
||||
#endif
|
||||
|
||||
FMT_END_NAMESPACE
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif // FMT_FORMAT_INL_H_
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,157 +0,0 @@
|
||||
// Formatting library for C++ - std::ostream support
|
||||
//
|
||||
// Copyright (c) 2012 - 2016, Victor Zverovich
|
||||
// All rights reserved.
|
||||
//
|
||||
// For the license information refer to format.h.
|
||||
|
||||
#ifndef FMT_OSTREAM_H_
|
||||
#define FMT_OSTREAM_H_
|
||||
|
||||
#include "format.h"
|
||||
#include <ostream>
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
namespace internal {
|
||||
|
||||
template <class Char>
|
||||
class formatbuf : public std::basic_streambuf<Char> {
|
||||
private:
|
||||
typedef typename std::basic_streambuf<Char>::int_type int_type;
|
||||
typedef typename std::basic_streambuf<Char>::traits_type traits_type;
|
||||
|
||||
basic_buffer<Char> &buffer_;
|
||||
|
||||
public:
|
||||
formatbuf(basic_buffer<Char> &buffer) : buffer_(buffer) {}
|
||||
|
||||
protected:
|
||||
// The put-area is actually always empty. This makes the implementation
|
||||
// simpler and has the advantage that the streambuf and the buffer are always
|
||||
// in sync and sputc never writes into uninitialized memory. The obvious
|
||||
// disadvantage is that each call to sputc always results in a (virtual) call
|
||||
// to overflow. There is no disadvantage here for sputn since this always
|
||||
// results in a call to xsputn.
|
||||
|
||||
int_type overflow(int_type ch = traits_type::eof()) FMT_OVERRIDE {
|
||||
if (!traits_type::eq_int_type(ch, traits_type::eof()))
|
||||
buffer_.push_back(static_cast<Char>(ch));
|
||||
return ch;
|
||||
}
|
||||
|
||||
std::streamsize xsputn(const Char *s, std::streamsize count) FMT_OVERRIDE {
|
||||
buffer_.append(s, s + count);
|
||||
return count;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Char>
|
||||
struct test_stream : std::basic_ostream<Char> {
|
||||
private:
|
||||
struct null;
|
||||
// Hide all operator<< from std::basic_ostream<Char>.
|
||||
void operator<<(null);
|
||||
};
|
||||
|
||||
// Checks if T has a user-defined operator<< (e.g. not a member of std::ostream).
|
||||
template <typename T, typename Char>
|
||||
class is_streamable {
|
||||
private:
|
||||
template <typename U>
|
||||
static decltype(
|
||||
internal::declval<test_stream<Char>&>()
|
||||
<< internal::declval<U>(), std::true_type()) test(int);
|
||||
|
||||
template <typename>
|
||||
static std::false_type test(...);
|
||||
|
||||
typedef decltype(test<T>(0)) result;
|
||||
|
||||
public:
|
||||
static const bool value = result::value;
|
||||
};
|
||||
|
||||
// Write the content of buf to os.
|
||||
template <typename Char>
|
||||
void write(std::basic_ostream<Char> &os, basic_buffer<Char> &buf) {
|
||||
const Char *data = buf.data();
|
||||
typedef std::make_unsigned<std::streamsize>::type UnsignedStreamSize;
|
||||
UnsignedStreamSize size = buf.size();
|
||||
UnsignedStreamSize max_size =
|
||||
internal::to_unsigned((std::numeric_limits<std::streamsize>::max)());
|
||||
do {
|
||||
UnsignedStreamSize n = size <= max_size ? size : max_size;
|
||||
os.write(data, static_cast<std::streamsize>(n));
|
||||
data += n;
|
||||
size -= n;
|
||||
} while (size != 0);
|
||||
}
|
||||
|
||||
template <typename Char, typename T>
|
||||
void format_value(basic_buffer<Char> &buffer, const T &value) {
|
||||
internal::formatbuf<Char> format_buf(buffer);
|
||||
std::basic_ostream<Char> output(&format_buf);
|
||||
output.exceptions(std::ios_base::failbit | std::ios_base::badbit);
|
||||
output << value;
|
||||
buffer.resize(buffer.size());
|
||||
}
|
||||
} // namespace internal
|
||||
|
||||
// Disable conversion to int if T has an overloaded operator<< which is a free
|
||||
// function (not a member of std::ostream).
|
||||
template <typename T, typename Char>
|
||||
struct convert_to_int<T, Char, void> {
|
||||
static const bool value =
|
||||
convert_to_int<T, Char, int>::value &&
|
||||
!internal::is_streamable<T, Char>::value;
|
||||
};
|
||||
|
||||
// Formats an object of type T that has an overloaded ostream operator<<.
|
||||
template <typename T, typename Char>
|
||||
struct formatter<T, Char,
|
||||
typename std::enable_if<
|
||||
internal::is_streamable<T, Char>::value &&
|
||||
!internal::format_type<
|
||||
typename buffer_context<Char>::type, T>::value>::type>
|
||||
: formatter<basic_string_view<Char>, Char> {
|
||||
|
||||
template <typename Context>
|
||||
auto format(const T &value, Context &ctx) -> decltype(ctx.out()) {
|
||||
basic_memory_buffer<Char> buffer;
|
||||
internal::format_value(buffer, value);
|
||||
basic_string_view<Char> str(buffer.data(), buffer.size());
|
||||
return formatter<basic_string_view<Char>, Char>::format(str, ctx);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Char>
|
||||
inline void vprint(std::basic_ostream<Char> &os,
|
||||
basic_string_view<Char> format_str,
|
||||
basic_format_args<typename buffer_context<Char>::type> args) {
|
||||
basic_memory_buffer<Char> buffer;
|
||||
vformat_to(buffer, format_str, args);
|
||||
internal::write(os, buffer);
|
||||
}
|
||||
/**
|
||||
\rst
|
||||
Prints formatted data to the stream *os*.
|
||||
|
||||
**Example**::
|
||||
|
||||
fmt::print(cerr, "Don't {}!", "panic");
|
||||
\endrst
|
||||
*/
|
||||
template <typename... Args>
|
||||
inline void print(std::ostream &os, string_view format_str,
|
||||
const Args & ... args) {
|
||||
vprint<char>(os, format_str, make_format_args<format_context>(args...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline void print(std::wostream &os, wstring_view format_str,
|
||||
const Args & ... args) {
|
||||
vprint<wchar_t>(os, format_str, make_format_args<wformat_context>(args...));
|
||||
}
|
||||
FMT_END_NAMESPACE
|
||||
|
||||
#endif // FMT_OSTREAM_H_
|
||||
@@ -1,324 +0,0 @@
|
||||
// A C++ interface to POSIX functions.
|
||||
//
|
||||
// Copyright (c) 2012 - 2016, Victor Zverovich
|
||||
// All rights reserved.
|
||||
//
|
||||
// For the license information refer to format.h.
|
||||
|
||||
#ifndef FMT_POSIX_H_
|
||||
#define FMT_POSIX_H_
|
||||
|
||||
#if defined(__MINGW32__) || defined(__CYGWIN__)
|
||||
// Workaround MinGW bug https://sourceforge.net/p/mingw/bugs/2024/.
|
||||
# undef __STRICT_ANSI__
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h> // for O_RDONLY
|
||||
#include <locale.h> // for locale_t
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> // for strtod_l
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#if defined __APPLE__ || defined(__FreeBSD__)
|
||||
# include <xlocale.h> // for LC_NUMERIC_MASK on OS X
|
||||
#endif
|
||||
|
||||
#include "format.h"
|
||||
|
||||
#ifndef FMT_POSIX
|
||||
# if defined(_WIN32) && !defined(__MINGW32__)
|
||||
// Fix warnings about deprecated symbols.
|
||||
# define FMT_POSIX(call) _##call
|
||||
# else
|
||||
# define FMT_POSIX(call) call
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// Calls to system functions are wrapped in FMT_SYSTEM for testability.
|
||||
#ifdef FMT_SYSTEM
|
||||
# define FMT_POSIX_CALL(call) FMT_SYSTEM(call)
|
||||
#else
|
||||
# define FMT_SYSTEM(call) call
|
||||
# ifdef _WIN32
|
||||
// Fix warnings about deprecated symbols.
|
||||
# define FMT_POSIX_CALL(call) ::_##call
|
||||
# else
|
||||
# define FMT_POSIX_CALL(call) ::call
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// Retries the expression while it evaluates to error_result and errno
|
||||
// equals to EINTR.
|
||||
#ifndef _WIN32
|
||||
# define FMT_RETRY_VAL(result, expression, error_result) \
|
||||
do { \
|
||||
result = (expression); \
|
||||
} while (result == error_result && errno == EINTR)
|
||||
#else
|
||||
# define FMT_RETRY_VAL(result, expression, error_result) result = (expression)
|
||||
#endif
|
||||
|
||||
#define FMT_RETRY(result, expression) FMT_RETRY_VAL(result, expression, -1)
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
|
||||
/**
|
||||
\rst
|
||||
A reference to a null-terminated string. It can be constructed from a C
|
||||
string or ``std::string``.
|
||||
|
||||
You can use one of the following typedefs for common character types:
|
||||
|
||||
+---------------+-----------------------------+
|
||||
| Type | Definition |
|
||||
+===============+=============================+
|
||||
| cstring_view | basic_cstring_view<char> |
|
||||
+---------------+-----------------------------+
|
||||
| wcstring_view | basic_cstring_view<wchar_t> |
|
||||
+---------------+-----------------------------+
|
||||
|
||||
This class is most useful as a parameter type to allow passing
|
||||
different types of strings to a function, for example::
|
||||
|
||||
template <typename... Args>
|
||||
std::string format(cstring_view format_str, const Args & ... args);
|
||||
|
||||
format("{}", 42);
|
||||
format(std::string("{}"), 42);
|
||||
\endrst
|
||||
*/
|
||||
template <typename Char>
|
||||
class basic_cstring_view {
|
||||
private:
|
||||
const Char *data_;
|
||||
|
||||
public:
|
||||
/** Constructs a string reference object from a C string. */
|
||||
basic_cstring_view(const Char *s) : data_(s) {}
|
||||
|
||||
/**
|
||||
\rst
|
||||
Constructs a string reference from an ``std::string`` object.
|
||||
\endrst
|
||||
*/
|
||||
basic_cstring_view(const std::basic_string<Char> &s) : data_(s.c_str()) {}
|
||||
|
||||
/** Returns the pointer to a C string. */
|
||||
const Char *c_str() const { return data_; }
|
||||
};
|
||||
|
||||
typedef basic_cstring_view<char> cstring_view;
|
||||
typedef basic_cstring_view<wchar_t> wcstring_view;
|
||||
|
||||
// An error code.
|
||||
class error_code {
|
||||
private:
|
||||
int value_;
|
||||
|
||||
public:
|
||||
explicit error_code(int value = 0) FMT_NOEXCEPT : value_(value) {}
|
||||
|
||||
int get() const FMT_NOEXCEPT { return value_; }
|
||||
};
|
||||
|
||||
// A buffered file.
|
||||
class buffered_file {
|
||||
private:
|
||||
FILE *file_;
|
||||
|
||||
friend class file;
|
||||
|
||||
explicit buffered_file(FILE *f) : file_(f) {}
|
||||
|
||||
public:
|
||||
// Constructs a buffered_file object which doesn't represent any file.
|
||||
buffered_file() FMT_NOEXCEPT : file_(FMT_NULL) {}
|
||||
|
||||
// Destroys the object closing the file it represents if any.
|
||||
FMT_API ~buffered_file() FMT_DTOR_NOEXCEPT;
|
||||
|
||||
private:
|
||||
buffered_file(const buffered_file &) = delete;
|
||||
void operator=(const buffered_file &) = delete;
|
||||
|
||||
|
||||
public:
|
||||
buffered_file(buffered_file &&other) FMT_NOEXCEPT : file_(other.file_) {
|
||||
other.file_ = FMT_NULL;
|
||||
}
|
||||
|
||||
buffered_file& operator=(buffered_file &&other) {
|
||||
close();
|
||||
file_ = other.file_;
|
||||
other.file_ = FMT_NULL;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Opens a file.
|
||||
FMT_API buffered_file(cstring_view filename, cstring_view mode);
|
||||
|
||||
// Closes the file.
|
||||
FMT_API void close();
|
||||
|
||||
// Returns the pointer to a FILE object representing this file.
|
||||
FILE *get() const FMT_NOEXCEPT { return file_; }
|
||||
|
||||
// We place parentheses around fileno to workaround a bug in some versions
|
||||
// of MinGW that define fileno as a macro.
|
||||
FMT_API int (fileno)() const;
|
||||
|
||||
void vprint(string_view format_str, format_args args) {
|
||||
fmt::vprint(file_, format_str, args);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline void print(string_view format_str, const Args & ... args) {
|
||||
vprint(format_str, make_format_args(args...));
|
||||
}
|
||||
};
|
||||
|
||||
// A file. Closed file is represented by a file object with descriptor -1.
|
||||
// Methods that are not declared with FMT_NOEXCEPT may throw
|
||||
// fmt::system_error in case of failure. Note that some errors such as
|
||||
// closing the file multiple times will cause a crash on Windows rather
|
||||
// than an exception. You can get standard behavior by overriding the
|
||||
// invalid parameter handler with _set_invalid_parameter_handler.
|
||||
class file {
|
||||
private:
|
||||
int fd_; // File descriptor.
|
||||
|
||||
// Constructs a file object with a given descriptor.
|
||||
explicit file(int fd) : fd_(fd) {}
|
||||
|
||||
public:
|
||||
// Possible values for the oflag argument to the constructor.
|
||||
enum {
|
||||
RDONLY = FMT_POSIX(O_RDONLY), // Open for reading only.
|
||||
WRONLY = FMT_POSIX(O_WRONLY), // Open for writing only.
|
||||
RDWR = FMT_POSIX(O_RDWR) // Open for reading and writing.
|
||||
};
|
||||
|
||||
// Constructs a file object which doesn't represent any file.
|
||||
file() FMT_NOEXCEPT : fd_(-1) {}
|
||||
|
||||
// Opens a file and constructs a file object representing this file.
|
||||
FMT_API file(cstring_view path, int oflag);
|
||||
|
||||
private:
|
||||
file(const file &) = delete;
|
||||
void operator=(const file &) = delete;
|
||||
|
||||
public:
|
||||
file(file &&other) FMT_NOEXCEPT : fd_(other.fd_) {
|
||||
other.fd_ = -1;
|
||||
}
|
||||
|
||||
file& operator=(file &&other) {
|
||||
close();
|
||||
fd_ = other.fd_;
|
||||
other.fd_ = -1;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Destroys the object closing the file it represents if any.
|
||||
FMT_API ~file() FMT_DTOR_NOEXCEPT;
|
||||
|
||||
// Returns the file descriptor.
|
||||
int descriptor() const FMT_NOEXCEPT { return fd_; }
|
||||
|
||||
// Closes the file.
|
||||
FMT_API void close();
|
||||
|
||||
// Returns the file size. The size has signed type for consistency with
|
||||
// stat::st_size.
|
||||
FMT_API long long size() const;
|
||||
|
||||
// Attempts to read count bytes from the file into the specified buffer.
|
||||
FMT_API std::size_t read(void *buffer, std::size_t count);
|
||||
|
||||
// Attempts to write count bytes from the specified buffer to the file.
|
||||
FMT_API std::size_t write(const void *buffer, std::size_t count);
|
||||
|
||||
// Duplicates a file descriptor with the dup function and returns
|
||||
// the duplicate as a file object.
|
||||
FMT_API static file dup(int fd);
|
||||
|
||||
// Makes fd be the copy of this file descriptor, closing fd first if
|
||||
// necessary.
|
||||
FMT_API void dup2(int fd);
|
||||
|
||||
// Makes fd be the copy of this file descriptor, closing fd first if
|
||||
// necessary.
|
||||
FMT_API void dup2(int fd, error_code &ec) FMT_NOEXCEPT;
|
||||
|
||||
// Creates a pipe setting up read_end and write_end file objects for reading
|
||||
// and writing respectively.
|
||||
FMT_API static void pipe(file &read_end, file &write_end);
|
||||
|
||||
// Creates a buffered_file object associated with this file and detaches
|
||||
// this file object from the file.
|
||||
FMT_API buffered_file fdopen(const char *mode);
|
||||
};
|
||||
|
||||
// Returns the memory page size.
|
||||
long getpagesize();
|
||||
|
||||
#if (defined(LC_NUMERIC_MASK) || defined(_MSC_VER)) && \
|
||||
!defined(__ANDROID__) && !defined(__CYGWIN__) && !defined(__OpenBSD__) && \
|
||||
!defined(__NEWLIB_H__)
|
||||
# define FMT_LOCALE
|
||||
#endif
|
||||
|
||||
#ifdef FMT_LOCALE
|
||||
// A "C" numeric locale.
|
||||
class Locale {
|
||||
private:
|
||||
# ifdef _MSC_VER
|
||||
typedef _locale_t locale_t;
|
||||
|
||||
enum { LC_NUMERIC_MASK = LC_NUMERIC };
|
||||
|
||||
static locale_t newlocale(int category_mask, const char *locale, locale_t) {
|
||||
return _create_locale(category_mask, locale);
|
||||
}
|
||||
|
||||
static void freelocale(locale_t locale) {
|
||||
_free_locale(locale);
|
||||
}
|
||||
|
||||
static double strtod_l(const char *nptr, char **endptr, _locale_t locale) {
|
||||
return _strtod_l(nptr, endptr, locale);
|
||||
}
|
||||
# endif
|
||||
|
||||
locale_t locale_;
|
||||
|
||||
Locale(const Locale &) = delete;
|
||||
void operator=(const Locale &) = delete;
|
||||
|
||||
public:
|
||||
typedef locale_t Type;
|
||||
|
||||
Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", FMT_NULL)) {
|
||||
if (!locale_)
|
||||
FMT_THROW(system_error(errno, "cannot create locale"));
|
||||
}
|
||||
~Locale() { freelocale(locale_); }
|
||||
|
||||
Type get() const { return locale_; }
|
||||
|
||||
// Converts string to floating-point number and advances str past the end
|
||||
// of the parsed input.
|
||||
double strtod(const char *&str) const {
|
||||
char *end = FMT_NULL;
|
||||
double result = strtod_l(str, &end, locale_);
|
||||
str = end;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
#endif // FMT_LOCALE
|
||||
FMT_END_NAMESPACE
|
||||
|
||||
#endif // FMT_POSIX_H_
|
||||
@@ -1,726 +0,0 @@
|
||||
// Formatting library for C++
|
||||
//
|
||||
// Copyright (c) 2012 - 2016, Victor Zverovich
|
||||
// All rights reserved.
|
||||
//
|
||||
// For the license information refer to format.h.
|
||||
|
||||
#ifndef FMT_PRINTF_H_
|
||||
#define FMT_PRINTF_H_
|
||||
|
||||
#include <algorithm> // std::fill_n
|
||||
#include <limits> // std::numeric_limits
|
||||
|
||||
#include "ostream.h"
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
namespace internal {
|
||||
|
||||
// Checks if a value fits in int - used to avoid warnings about comparing
|
||||
// signed and unsigned integers.
|
||||
template <bool IsSigned>
|
||||
struct int_checker {
|
||||
template <typename T>
|
||||
static bool fits_in_int(T value) {
|
||||
unsigned max = std::numeric_limits<int>::max();
|
||||
return value <= max;
|
||||
}
|
||||
static bool fits_in_int(bool) { return true; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct int_checker<true> {
|
||||
template <typename T>
|
||||
static bool fits_in_int(T value) {
|
||||
return value >= std::numeric_limits<int>::min() &&
|
||||
value <= std::numeric_limits<int>::max();
|
||||
}
|
||||
static bool fits_in_int(int) { return true; }
|
||||
};
|
||||
|
||||
class printf_precision_handler: public function<int> {
|
||||
public:
|
||||
template <typename T>
|
||||
typename std::enable_if<std::is_integral<T>::value, int>::type
|
||||
operator()(T value) {
|
||||
if (!int_checker<std::numeric_limits<T>::is_signed>::fits_in_int(value))
|
||||
FMT_THROW(format_error("number is too big"));
|
||||
return static_cast<int>(value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<!std::is_integral<T>::value, int>::type operator()(T) {
|
||||
FMT_THROW(format_error("precision is not integer"));
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
// An argument visitor that returns true iff arg is a zero integer.
|
||||
class is_zero_int: public function<bool> {
|
||||
public:
|
||||
template <typename T>
|
||||
typename std::enable_if<std::is_integral<T>::value, bool>::type
|
||||
operator()(T value) { return value == 0; }
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<!std::is_integral<T>::value, bool>::type
|
||||
operator()(T) { return false; }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct make_unsigned_or_bool : std::make_unsigned<T> {};
|
||||
|
||||
template <>
|
||||
struct make_unsigned_or_bool<bool> {
|
||||
typedef bool type;
|
||||
};
|
||||
|
||||
template <typename T, typename Context>
|
||||
class arg_converter: public function<void> {
|
||||
private:
|
||||
typedef typename Context::char_type Char;
|
||||
|
||||
basic_format_arg<Context> &arg_;
|
||||
typename Context::char_type type_;
|
||||
|
||||
public:
|
||||
arg_converter(basic_format_arg<Context> &arg, Char type)
|
||||
: arg_(arg), type_(type) {}
|
||||
|
||||
void operator()(bool value) {
|
||||
if (type_ != 's')
|
||||
operator()<bool>(value);
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
typename std::enable_if<std::is_integral<U>::value>::type
|
||||
operator()(U value) {
|
||||
bool is_signed = type_ == 'd' || type_ == 'i';
|
||||
typedef typename std::conditional<
|
||||
std::is_same<T, void>::value, U, T>::type TargetType;
|
||||
if (const_check(sizeof(TargetType) <= sizeof(int))) {
|
||||
// Extra casts are used to silence warnings.
|
||||
if (is_signed) {
|
||||
arg_ = internal::make_arg<Context>(
|
||||
static_cast<int>(static_cast<TargetType>(value)));
|
||||
} else {
|
||||
typedef typename make_unsigned_or_bool<TargetType>::type Unsigned;
|
||||
arg_ = internal::make_arg<Context>(
|
||||
static_cast<unsigned>(static_cast<Unsigned>(value)));
|
||||
}
|
||||
} else {
|
||||
if (is_signed) {
|
||||
// glibc's printf doesn't sign extend arguments of smaller types:
|
||||
// std::printf("%lld", -42); // prints "4294967254"
|
||||
// but we don't have to do the same because it's a UB.
|
||||
arg_ = internal::make_arg<Context>(static_cast<long long>(value));
|
||||
} else {
|
||||
arg_ = internal::make_arg<Context>(
|
||||
static_cast<typename make_unsigned_or_bool<U>::type>(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
typename std::enable_if<!std::is_integral<U>::value>::type operator()(U) {
|
||||
// No coversion needed for non-integral types.
|
||||
}
|
||||
};
|
||||
|
||||
// Converts an integer argument to T for printf, if T is an integral type.
|
||||
// If T is void, the argument is converted to corresponding signed or unsigned
|
||||
// type depending on the type specifier: 'd' and 'i' - signed, other -
|
||||
// unsigned).
|
||||
template <typename T, typename Context, typename Char>
|
||||
void convert_arg(basic_format_arg<Context> &arg, Char type) {
|
||||
fmt::visit(arg_converter<T, Context>(arg, type), arg);
|
||||
}
|
||||
|
||||
// Converts an integer argument to char for printf.
|
||||
template <typename Context>
|
||||
class char_converter: public function<void> {
|
||||
private:
|
||||
basic_format_arg<Context> &arg_;
|
||||
|
||||
public:
|
||||
explicit char_converter(basic_format_arg<Context> &arg) : arg_(arg) {}
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<std::is_integral<T>::value>::type
|
||||
operator()(T value) {
|
||||
typedef typename Context::char_type Char;
|
||||
arg_ = internal::make_arg<Context>(static_cast<Char>(value));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<!std::is_integral<T>::value>::type operator()(T) {
|
||||
// No coversion needed for non-integral types.
|
||||
}
|
||||
};
|
||||
|
||||
// Checks if an argument is a valid printf width specifier and sets
|
||||
// left alignment if it is negative.
|
||||
template <typename Char>
|
||||
class printf_width_handler: public function<unsigned> {
|
||||
private:
|
||||
typedef basic_format_specs<Char> format_specs;
|
||||
|
||||
format_specs &spec_;
|
||||
|
||||
public:
|
||||
explicit printf_width_handler(format_specs &spec) : spec_(spec) {}
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<std::is_integral<T>::value, unsigned>::type
|
||||
operator()(T value) {
|
||||
typedef typename internal::int_traits<T>::main_type UnsignedType;
|
||||
UnsignedType width = static_cast<UnsignedType>(value);
|
||||
if (internal::is_negative(value)) {
|
||||
spec_.align_ = ALIGN_LEFT;
|
||||
width = 0 - width;
|
||||
}
|
||||
unsigned int_max = std::numeric_limits<int>::max();
|
||||
if (width > int_max)
|
||||
FMT_THROW(format_error("number is too big"));
|
||||
return static_cast<unsigned>(width);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<!std::is_integral<T>::value, unsigned>::type
|
||||
operator()(T) {
|
||||
FMT_THROW(format_error("width is not integer"));
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
} // namespace internal
|
||||
|
||||
template <typename Range>
|
||||
class printf_arg_formatter;
|
||||
|
||||
template <
|
||||
typename OutputIt, typename Char,
|
||||
typename ArgFormatter =
|
||||
printf_arg_formatter<back_insert_range<internal::basic_buffer<Char>>>>
|
||||
class basic_printf_context;
|
||||
|
||||
/**
|
||||
\rst
|
||||
The ``printf`` argument formatter.
|
||||
\endrst
|
||||
*/
|
||||
template <typename Range>
|
||||
class printf_arg_formatter:
|
||||
public internal::function<
|
||||
typename internal::arg_formatter_base<Range>::iterator>,
|
||||
public internal::arg_formatter_base<Range> {
|
||||
private:
|
||||
typedef typename Range::value_type char_type;
|
||||
typedef decltype(internal::declval<Range>().begin()) iterator;
|
||||
typedef internal::arg_formatter_base<Range> base;
|
||||
typedef basic_printf_context<iterator, char_type> context_type;
|
||||
|
||||
context_type &context_;
|
||||
|
||||
void write_null_pointer(char) {
|
||||
this->spec()->type_ = 0;
|
||||
this->write("(nil)");
|
||||
}
|
||||
|
||||
void write_null_pointer(wchar_t) {
|
||||
this->spec()->type_ = 0;
|
||||
this->write(L"(nil)");
|
||||
}
|
||||
|
||||
public:
|
||||
typedef typename base::format_specs format_specs;
|
||||
|
||||
/**
|
||||
\rst
|
||||
Constructs an argument formatter object.
|
||||
*buffer* is a reference to the output buffer and *spec* contains format
|
||||
specifier information for standard argument types.
|
||||
\endrst
|
||||
*/
|
||||
printf_arg_formatter(internal::basic_buffer<char_type> &buffer,
|
||||
format_specs &spec, context_type &ctx)
|
||||
: base(back_insert_range<internal::basic_buffer<char_type>>(buffer), &spec),
|
||||
context_(ctx) {}
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<std::is_integral<T>::value, iterator>::type
|
||||
operator()(T value) {
|
||||
// MSVC2013 fails to compile separate overloads for bool and char_type so
|
||||
// use std::is_same instead.
|
||||
if (std::is_same<T, bool>::value) {
|
||||
format_specs &fmt_spec = *this->spec();
|
||||
if (fmt_spec.type_ != 's')
|
||||
return base::operator()(value ? 1 : 0);
|
||||
fmt_spec.type_ = 0;
|
||||
this->write(value != 0);
|
||||
} else if (std::is_same<T, char_type>::value) {
|
||||
format_specs &fmt_spec = *this->spec();
|
||||
if (fmt_spec.type_ && fmt_spec.type_ != 'c')
|
||||
return (*this)(static_cast<int>(value));
|
||||
fmt_spec.flags_ = 0;
|
||||
fmt_spec.align_ = ALIGN_RIGHT;
|
||||
return base::operator()(value);
|
||||
} else {
|
||||
return base::operator()(value);
|
||||
}
|
||||
return this->out();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<std::is_floating_point<T>::value, iterator>::type
|
||||
operator()(T value) {
|
||||
return base::operator()(value);
|
||||
}
|
||||
|
||||
/** Formats a null-terminated C string. */
|
||||
iterator operator()(const char *value) {
|
||||
if (value)
|
||||
base::operator()(value);
|
||||
else if (this->spec()->type_ == 'p')
|
||||
write_null_pointer(char_type());
|
||||
else
|
||||
this->write("(null)");
|
||||
return this->out();
|
||||
}
|
||||
|
||||
/** Formats a null-terminated wide C string. */
|
||||
iterator operator()(const wchar_t *value) {
|
||||
if (value)
|
||||
base::operator()(value);
|
||||
else if (this->spec()->type_ == 'p')
|
||||
write_null_pointer(char_type());
|
||||
else
|
||||
this->write(L"(null)");
|
||||
return this->out();
|
||||
}
|
||||
|
||||
iterator operator()(basic_string_view<char_type> value) {
|
||||
return base::operator()(value);
|
||||
}
|
||||
|
||||
iterator operator()(monostate value) {
|
||||
return base::operator()(value);
|
||||
}
|
||||
|
||||
/** Formats a pointer. */
|
||||
iterator operator()(const void *value) {
|
||||
if (value)
|
||||
return base::operator()(value);
|
||||
this->spec()->type_ = 0;
|
||||
write_null_pointer(char_type());
|
||||
return this->out();
|
||||
}
|
||||
|
||||
/** Formats an argument of a custom (user-defined) type. */
|
||||
iterator operator()(typename basic_format_arg<context_type>::handle handle) {
|
||||
handle.format(context_);
|
||||
return this->out();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct printf_formatter {
|
||||
template <typename ParseContext>
|
||||
auto parse(ParseContext &ctx) -> decltype(ctx.begin()) { return ctx.begin(); }
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(const T &value, FormatContext &ctx) -> decltype(ctx.out()) {
|
||||
internal::format_value(internal::get_container(ctx.out()), value);
|
||||
return ctx.out();
|
||||
}
|
||||
};
|
||||
|
||||
/** This template formats data and writes the output to a writer. */
|
||||
template <typename OutputIt, typename Char, typename ArgFormatter>
|
||||
class basic_printf_context :
|
||||
// Inherit publicly as a workaround for the icc bug
|
||||
// https://software.intel.com/en-us/forums/intel-c-compiler/topic/783476.
|
||||
public internal::context_base<
|
||||
OutputIt, basic_printf_context<OutputIt, Char, ArgFormatter>, Char> {
|
||||
public:
|
||||
/** The character type for the output. */
|
||||
typedef Char char_type;
|
||||
|
||||
template <typename T>
|
||||
struct formatter_type { typedef printf_formatter<T> type; };
|
||||
|
||||
private:
|
||||
typedef internal::context_base<OutputIt, basic_printf_context, Char> base;
|
||||
typedef typename base::format_arg format_arg;
|
||||
typedef basic_format_specs<char_type> format_specs;
|
||||
typedef internal::null_terminating_iterator<char_type> iterator;
|
||||
|
||||
void parse_flags(format_specs &spec, iterator &it);
|
||||
|
||||
// Returns the argument with specified index or, if arg_index is equal
|
||||
// to the maximum unsigned value, the next argument.
|
||||
format_arg get_arg(
|
||||
iterator it,
|
||||
unsigned arg_index = (std::numeric_limits<unsigned>::max)());
|
||||
|
||||
// Parses argument index, flags and width and returns the argument index.
|
||||
unsigned parse_header(iterator &it, format_specs &spec);
|
||||
|
||||
public:
|
||||
/**
|
||||
\rst
|
||||
Constructs a ``printf_context`` object. References to the arguments and
|
||||
the writer are stored in the context object so make sure they have
|
||||
appropriate lifetimes.
|
||||
\endrst
|
||||
*/
|
||||
basic_printf_context(OutputIt out, basic_string_view<char_type> format_str,
|
||||
basic_format_args<basic_printf_context> args)
|
||||
: base(out, format_str, args) {}
|
||||
|
||||
using base::parse_context;
|
||||
using base::out;
|
||||
using base::advance_to;
|
||||
|
||||
/** Formats stored arguments and writes the output to the range. */
|
||||
void format();
|
||||
};
|
||||
|
||||
template <typename OutputIt, typename Char, typename AF>
|
||||
void basic_printf_context<OutputIt, Char, AF>::parse_flags(
|
||||
format_specs &spec, iterator &it) {
|
||||
for (;;) {
|
||||
switch (*it++) {
|
||||
case '-':
|
||||
spec.align_ = ALIGN_LEFT;
|
||||
break;
|
||||
case '+':
|
||||
spec.flags_ |= SIGN_FLAG | PLUS_FLAG;
|
||||
break;
|
||||
case '0':
|
||||
spec.fill_ = '0';
|
||||
break;
|
||||
case ' ':
|
||||
spec.flags_ |= SIGN_FLAG;
|
||||
break;
|
||||
case '#':
|
||||
spec.flags_ |= HASH_FLAG;
|
||||
break;
|
||||
default:
|
||||
--it;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename OutputIt, typename Char, typename AF>
|
||||
typename basic_printf_context<OutputIt, Char, AF>::format_arg
|
||||
basic_printf_context<OutputIt, Char, AF>::get_arg(
|
||||
iterator it, unsigned arg_index) {
|
||||
(void)it;
|
||||
if (arg_index == std::numeric_limits<unsigned>::max())
|
||||
return this->do_get_arg(this->parse_context().next_arg_id());
|
||||
return base::get_arg(arg_index - 1);
|
||||
}
|
||||
|
||||
template <typename OutputIt, typename Char, typename AF>
|
||||
unsigned basic_printf_context<OutputIt, Char, AF>::parse_header(
|
||||
iterator &it, format_specs &spec) {
|
||||
unsigned arg_index = std::numeric_limits<unsigned>::max();
|
||||
char_type c = *it;
|
||||
if (c >= '0' && c <= '9') {
|
||||
// Parse an argument index (if followed by '$') or a width possibly
|
||||
// preceded with '0' flag(s).
|
||||
internal::error_handler eh;
|
||||
unsigned value = parse_nonnegative_int(it, eh);
|
||||
if (*it == '$') { // value is an argument index
|
||||
++it;
|
||||
arg_index = value;
|
||||
} else {
|
||||
if (c == '0')
|
||||
spec.fill_ = '0';
|
||||
if (value != 0) {
|
||||
// Nonzero value means that we parsed width and don't need to
|
||||
// parse it or flags again, so return now.
|
||||
spec.width_ = value;
|
||||
return arg_index;
|
||||
}
|
||||
}
|
||||
}
|
||||
parse_flags(spec, it);
|
||||
// Parse width.
|
||||
if (*it >= '0' && *it <= '9') {
|
||||
internal::error_handler eh;
|
||||
spec.width_ = parse_nonnegative_int(it, eh);
|
||||
} else if (*it == '*') {
|
||||
++it;
|
||||
spec.width_ =
|
||||
fmt::visit(internal::printf_width_handler<char_type>(spec), get_arg(it));
|
||||
}
|
||||
return arg_index;
|
||||
}
|
||||
|
||||
template <typename OutputIt, typename Char, typename AF>
|
||||
void basic_printf_context<OutputIt, Char, AF>::format() {
|
||||
auto &buffer = internal::get_container(this->out());
|
||||
auto start = iterator(this->parse_context());
|
||||
auto it = start;
|
||||
using internal::pointer_from;
|
||||
while (*it) {
|
||||
char_type c = *it++;
|
||||
if (c != '%') continue;
|
||||
if (*it == c) {
|
||||
buffer.append(pointer_from(start), pointer_from(it));
|
||||
start = ++it;
|
||||
continue;
|
||||
}
|
||||
buffer.append(pointer_from(start), pointer_from(it) - 1);
|
||||
|
||||
format_specs spec;
|
||||
spec.align_ = ALIGN_RIGHT;
|
||||
|
||||
// Parse argument index, flags and width.
|
||||
unsigned arg_index = parse_header(it, spec);
|
||||
|
||||
// Parse precision.
|
||||
if (*it == '.') {
|
||||
++it;
|
||||
if ('0' <= *it && *it <= '9') {
|
||||
internal::error_handler eh;
|
||||
spec.precision_ = static_cast<int>(parse_nonnegative_int(it, eh));
|
||||
} else if (*it == '*') {
|
||||
++it;
|
||||
spec.precision_ =
|
||||
fmt::visit(internal::printf_precision_handler(), get_arg(it));
|
||||
} else {
|
||||
spec.precision_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
format_arg arg = get_arg(it, arg_index);
|
||||
if (spec.flag(HASH_FLAG) && fmt::visit(internal::is_zero_int(), arg))
|
||||
spec.flags_ &= ~internal::to_unsigned<int>(HASH_FLAG);
|
||||
if (spec.fill_ == '0') {
|
||||
if (arg.is_arithmetic())
|
||||
spec.align_ = ALIGN_NUMERIC;
|
||||
else
|
||||
spec.fill_ = ' '; // Ignore '0' flag for non-numeric types.
|
||||
}
|
||||
|
||||
// Parse length and convert the argument to the required type.
|
||||
using internal::convert_arg;
|
||||
switch (*it++) {
|
||||
case 'h':
|
||||
if (*it == 'h')
|
||||
convert_arg<signed char>(arg, *++it);
|
||||
else
|
||||
convert_arg<short>(arg, *it);
|
||||
break;
|
||||
case 'l':
|
||||
if (*it == 'l')
|
||||
convert_arg<long long>(arg, *++it);
|
||||
else
|
||||
convert_arg<long>(arg, *it);
|
||||
break;
|
||||
case 'j':
|
||||
convert_arg<intmax_t>(arg, *it);
|
||||
break;
|
||||
case 'z':
|
||||
convert_arg<std::size_t>(arg, *it);
|
||||
break;
|
||||
case 't':
|
||||
convert_arg<std::ptrdiff_t>(arg, *it);
|
||||
break;
|
||||
case 'L':
|
||||
// printf produces garbage when 'L' is omitted for long double, no
|
||||
// need to do the same.
|
||||
break;
|
||||
default:
|
||||
--it;
|
||||
convert_arg<void>(arg, *it);
|
||||
}
|
||||
|
||||
// Parse type.
|
||||
if (!*it)
|
||||
FMT_THROW(format_error("invalid format string"));
|
||||
spec.type_ = static_cast<char>(*it++);
|
||||
if (arg.is_integral()) {
|
||||
// Normalize type.
|
||||
switch (spec.type_) {
|
||||
case 'i': case 'u':
|
||||
spec.type_ = 'd';
|
||||
break;
|
||||
case 'c':
|
||||
// TODO: handle wchar_t better?
|
||||
fmt::visit(internal::char_converter<basic_printf_context>(arg), arg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
start = it;
|
||||
|
||||
// Format argument.
|
||||
fmt::visit(AF(buffer, spec, *this), arg);
|
||||
}
|
||||
buffer.append(pointer_from(start), pointer_from(it));
|
||||
}
|
||||
|
||||
template <typename Char, typename Context>
|
||||
void printf(internal::basic_buffer<Char> &buf, basic_string_view<Char> format,
|
||||
basic_format_args<Context> args) {
|
||||
Context(std::back_inserter(buf), format, args).format();
|
||||
}
|
||||
|
||||
template <typename Buffer>
|
||||
struct printf_context {
|
||||
typedef basic_printf_context<
|
||||
std::back_insert_iterator<Buffer>, typename Buffer::value_type> type;
|
||||
};
|
||||
|
||||
template <typename ...Args>
|
||||
inline format_arg_store<printf_context<internal::buffer>::type, Args...>
|
||||
make_printf_args(const Args & ... args) {
|
||||
return format_arg_store<printf_context<internal::buffer>::type, Args...>(
|
||||
args...);
|
||||
}
|
||||
typedef basic_format_args<printf_context<internal::buffer>::type> printf_args;
|
||||
typedef basic_format_args<printf_context<internal::wbuffer>::type> wprintf_args;
|
||||
|
||||
inline std::string vsprintf(string_view format, printf_args args) {
|
||||
memory_buffer buffer;
|
||||
printf(buffer, format, args);
|
||||
return to_string(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
\rst
|
||||
Formats arguments and returns the result as a string.
|
||||
|
||||
**Example**::
|
||||
|
||||
std::string message = fmt::sprintf("The answer is %d", 42);
|
||||
\endrst
|
||||
*/
|
||||
template <typename... Args>
|
||||
inline std::string sprintf(string_view format_str, const Args & ... args) {
|
||||
return vsprintf(format_str,
|
||||
make_format_args<typename printf_context<internal::buffer>::type>(args...));
|
||||
}
|
||||
|
||||
inline std::wstring vsprintf(wstring_view format, wprintf_args args) {
|
||||
wmemory_buffer buffer;
|
||||
printf(buffer, format, args);
|
||||
return to_string(buffer);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline std::wstring sprintf(wstring_view format_str, const Args & ... args) {
|
||||
return vsprintf(format_str,
|
||||
make_format_args<typename printf_context<internal::wbuffer>::type>(args...));
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
inline int vfprintf(std::FILE *f, basic_string_view<Char> format,
|
||||
basic_format_args<typename printf_context<
|
||||
internal::basic_buffer<Char>>::type> args) {
|
||||
basic_memory_buffer<Char> buffer;
|
||||
printf(buffer, format, args);
|
||||
std::size_t size = buffer.size();
|
||||
return std::fwrite(
|
||||
buffer.data(), sizeof(Char), size, f) < size ? -1 : static_cast<int>(size);
|
||||
}
|
||||
|
||||
/**
|
||||
\rst
|
||||
Prints formatted data to the file *f*.
|
||||
|
||||
**Example**::
|
||||
|
||||
fmt::fprintf(stderr, "Don't %s!", "panic");
|
||||
\endrst
|
||||
*/
|
||||
template <typename... Args>
|
||||
inline int fprintf(std::FILE *f, string_view format_str, const Args & ... args) {
|
||||
auto vargs = make_format_args<
|
||||
typename printf_context<internal::buffer>::type>(args...);
|
||||
return vfprintf<char>(f, format_str, vargs);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline int fprintf(std::FILE *f, wstring_view format_str,
|
||||
const Args & ... args) {
|
||||
return vfprintf(f, format_str,
|
||||
make_format_args<typename printf_context<internal::wbuffer>::type>(args...));
|
||||
}
|
||||
|
||||
inline int vprintf(string_view format, printf_args args) {
|
||||
return vfprintf(stdout, format, args);
|
||||
}
|
||||
|
||||
inline int vprintf(wstring_view format, wprintf_args args) {
|
||||
return vfprintf(stdout, format, args);
|
||||
}
|
||||
|
||||
/**
|
||||
\rst
|
||||
Prints formatted data to ``stdout``.
|
||||
|
||||
**Example**::
|
||||
|
||||
fmt::printf("Elapsed time: %.2f seconds", 1.23);
|
||||
\endrst
|
||||
*/
|
||||
template <typename... Args>
|
||||
inline int printf(string_view format_str, const Args & ... args) {
|
||||
return vprintf(format_str,
|
||||
make_format_args<typename printf_context<internal::buffer>::type>(args...));
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline int printf(wstring_view format_str, const Args & ... args) {
|
||||
return vprintf(format_str,
|
||||
make_format_args<typename printf_context<internal::wbuffer>::type>(args...));
|
||||
}
|
||||
|
||||
inline int vfprintf(std::ostream &os, string_view format_str,
|
||||
printf_args args) {
|
||||
memory_buffer buffer;
|
||||
printf(buffer, format_str, args);
|
||||
internal::write(os, buffer);
|
||||
return static_cast<int>(buffer.size());
|
||||
}
|
||||
|
||||
inline int vfprintf(std::wostream &os, wstring_view format_str,
|
||||
wprintf_args args) {
|
||||
wmemory_buffer buffer;
|
||||
printf(buffer, format_str, args);
|
||||
internal::write(os, buffer);
|
||||
return static_cast<int>(buffer.size());
|
||||
}
|
||||
|
||||
/**
|
||||
\rst
|
||||
Prints formatted data to the stream *os*.
|
||||
|
||||
**Example**::
|
||||
|
||||
fmt::fprintf(cerr, "Don't %s!", "panic");
|
||||
\endrst
|
||||
*/
|
||||
template <typename... Args>
|
||||
inline int fprintf(std::ostream &os, string_view format_str,
|
||||
const Args & ... args) {
|
||||
auto vargs = make_format_args<
|
||||
typename printf_context<internal::buffer>::type>(args...);
|
||||
return vfprintf(os, format_str, vargs);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline int fprintf(std::wostream &os, wstring_view format_str,
|
||||
const Args & ... args) {
|
||||
auto vargs = make_format_args<
|
||||
typename printf_context<internal::buffer>::type>(args...);
|
||||
return vfprintf(os, format_str, vargs);
|
||||
}
|
||||
FMT_END_NAMESPACE
|
||||
|
||||
#endif // FMT_PRINTF_H_
|
||||
@@ -1,308 +0,0 @@
|
||||
// Formatting library for C++ - the core API
|
||||
//
|
||||
// Copyright (c) 2012 - present, Victor Zverovich
|
||||
// All rights reserved.
|
||||
//
|
||||
// For the license information refer to format.h.
|
||||
//
|
||||
// Copyright (c) 2018 - present, Remotion (Igor Schulz)
|
||||
// All Rights Reserved
|
||||
// {fmt} support for ranges, containers and types tuple interface.
|
||||
|
||||
#ifndef FMT_RANGES_H_
|
||||
#define FMT_RANGES_H_
|
||||
|
||||
#include "format.h"
|
||||
#include <type_traits>
|
||||
|
||||
// output only up to N items from the range.
|
||||
#ifndef FMT_RANGE_OUTPUT_LENGTH_LIMIT
|
||||
# define FMT_RANGE_OUTPUT_LENGTH_LIMIT 256
|
||||
#endif
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
|
||||
template <typename Char>
|
||||
struct formatting_base {
|
||||
template <typename ParseContext>
|
||||
FMT_CONSTEXPR auto parse(ParseContext &ctx) -> decltype(ctx.begin()) {
|
||||
return ctx.begin();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Char, typename Enable = void>
|
||||
struct formatting_range : formatting_base<Char> {
|
||||
static FMT_CONSTEXPR_DECL const std::size_t range_length_limit =
|
||||
FMT_RANGE_OUTPUT_LENGTH_LIMIT; // output only up to N items from the range.
|
||||
Char prefix;
|
||||
Char delimiter;
|
||||
Char postfix;
|
||||
formatting_range() : prefix('{'), delimiter(','), postfix('}') {}
|
||||
static FMT_CONSTEXPR_DECL const bool add_delimiter_spaces = true;
|
||||
static FMT_CONSTEXPR_DECL const bool add_prepostfix_space = false;
|
||||
};
|
||||
|
||||
template <typename Char, typename Enable = void>
|
||||
struct formatting_tuple : formatting_base<Char> {
|
||||
Char prefix;
|
||||
Char delimiter;
|
||||
Char postfix;
|
||||
formatting_tuple() : prefix('('), delimiter(','), postfix(')') {}
|
||||
static FMT_CONSTEXPR_DECL const bool add_delimiter_spaces = true;
|
||||
static FMT_CONSTEXPR_DECL const bool add_prepostfix_space = false;
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
|
||||
template <typename RangeT, typename OutputIterator>
|
||||
void copy(const RangeT &range, OutputIterator out) {
|
||||
for (auto it = range.begin(), end = range.end(); it != end; ++it)
|
||||
*out++ = *it;
|
||||
}
|
||||
|
||||
template <typename OutputIterator>
|
||||
void copy(const char *str, OutputIterator out) {
|
||||
const char *p_curr = str;
|
||||
while (*p_curr) {
|
||||
*out++ = *p_curr++;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename OutputIterator>
|
||||
void copy(char ch, OutputIterator out) {
|
||||
*out++ = ch;
|
||||
}
|
||||
|
||||
/// Return true value if T has std::string interface, like std::string_view.
|
||||
template <typename T>
|
||||
class is_like_std_string {
|
||||
template <typename U>
|
||||
static auto check(U *p) ->
|
||||
decltype(p->find('a'), p->length(), p->data(), int());
|
||||
template <typename>
|
||||
static void check(...);
|
||||
|
||||
public:
|
||||
static FMT_CONSTEXPR_DECL const bool value =
|
||||
!std::is_void<decltype(check<T>(FMT_NULL))>::value;
|
||||
};
|
||||
|
||||
template <typename Char>
|
||||
struct is_like_std_string<fmt::basic_string_view<Char>> : std::true_type {};
|
||||
|
||||
template <typename... Ts>
|
||||
struct conditional_helper {};
|
||||
|
||||
template <typename T, typename _ = void>
|
||||
struct is_range_ : std::false_type {};
|
||||
|
||||
#if !FMT_MSC_VER || FMT_MSC_VER > 1800
|
||||
template <typename T>
|
||||
struct is_range_<T, typename std::conditional<
|
||||
false,
|
||||
conditional_helper<decltype(internal::declval<T>().begin()),
|
||||
decltype(internal::declval<T>().end())>,
|
||||
void>::type> : std::true_type {};
|
||||
#endif
|
||||
|
||||
/// tuple_size and tuple_element check.
|
||||
template <typename T>
|
||||
class is_tuple_like_ {
|
||||
template <typename U>
|
||||
static auto check(U *p) ->
|
||||
decltype(std::tuple_size<U>::value,
|
||||
internal::declval<typename std::tuple_element<0, U>::type>(), int());
|
||||
template <typename>
|
||||
static void check(...);
|
||||
|
||||
public:
|
||||
static FMT_CONSTEXPR_DECL const bool value =
|
||||
!std::is_void<decltype(check<T>(FMT_NULL))>::value;
|
||||
};
|
||||
|
||||
// Check for integer_sequence
|
||||
#if defined(__cpp_lib_integer_sequence) || FMT_MSC_VER >= 1900
|
||||
template <typename T, T... N>
|
||||
using integer_sequence = std::integer_sequence<T, N...>;
|
||||
template <std::size_t... N>
|
||||
using index_sequence = std::index_sequence<N...>;
|
||||
template <std::size_t N>
|
||||
using make_index_sequence = std::make_index_sequence<N>;
|
||||
#else
|
||||
template <typename T, T... N>
|
||||
struct integer_sequence {
|
||||
typedef T value_type;
|
||||
|
||||
static FMT_CONSTEXPR std::size_t size() {
|
||||
return sizeof...(N);
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t... N>
|
||||
using index_sequence = integer_sequence<std::size_t, N...>;
|
||||
|
||||
template <typename T, std::size_t N, T... Ns>
|
||||
struct make_integer_sequence : make_integer_sequence<T, N - 1, N - 1, Ns...> {};
|
||||
template <typename T, T... Ns>
|
||||
struct make_integer_sequence<T, 0, Ns...> : integer_sequence<T, Ns...> {};
|
||||
|
||||
template <std::size_t N>
|
||||
using make_index_sequence = make_integer_sequence<std::size_t, N>;
|
||||
#endif
|
||||
|
||||
template <class Tuple, class F, size_t... Is>
|
||||
void for_each(index_sequence<Is...>, Tuple &&tup, F &&f) FMT_NOEXCEPT {
|
||||
using std::get;
|
||||
// using free function get<I>(T) now.
|
||||
const int _[] = {0, ((void)f(get<Is>(tup)), 0)...};
|
||||
(void)_; // blocks warnings
|
||||
}
|
||||
|
||||
template <class T>
|
||||
FMT_CONSTEXPR make_index_sequence<std::tuple_size<T>::value>
|
||||
get_indexes(T const &) { return {}; }
|
||||
|
||||
template <class Tuple, class F>
|
||||
void for_each(Tuple &&tup, F &&f) {
|
||||
const auto indexes = get_indexes(tup);
|
||||
for_each(indexes, std::forward<Tuple>(tup), std::forward<F>(f));
|
||||
}
|
||||
|
||||
template<typename Arg>
|
||||
FMT_CONSTEXPR const char* format_str_quoted(bool add_space, const Arg&,
|
||||
typename std::enable_if<
|
||||
!is_like_std_string<typename std::decay<Arg>::type>::value>::type* = nullptr) {
|
||||
return add_space ? " {}" : "{}";
|
||||
}
|
||||
|
||||
template<typename Arg>
|
||||
FMT_CONSTEXPR const char* format_str_quoted(bool add_space, const Arg&,
|
||||
typename std::enable_if<
|
||||
is_like_std_string<typename std::decay<Arg>::type>::value>::type* = nullptr) {
|
||||
return add_space ? " \"{}\"" : "\"{}\"";
|
||||
}
|
||||
|
||||
FMT_CONSTEXPR const char* format_str_quoted(bool add_space, const char*) {
|
||||
return add_space ? " \"{}\"" : "\"{}\"";
|
||||
}
|
||||
FMT_CONSTEXPR const wchar_t* format_str_quoted(bool add_space, const wchar_t*) {
|
||||
return add_space ? L" \"{}\"" : L"\"{}\"";
|
||||
}
|
||||
|
||||
FMT_CONSTEXPR const char* format_str_quoted(bool add_space, const char) {
|
||||
return add_space ? " '{}'" : "'{}'";
|
||||
}
|
||||
FMT_CONSTEXPR const wchar_t* format_str_quoted(bool add_space, const wchar_t) {
|
||||
return add_space ? L" '{}'" : L"'{}'";
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
template <typename T>
|
||||
struct is_tuple_like {
|
||||
static FMT_CONSTEXPR_DECL const bool value =
|
||||
internal::is_tuple_like_<T>::value && !internal::is_range_<T>::value;
|
||||
};
|
||||
|
||||
template <typename TupleT, typename Char>
|
||||
struct formatter<TupleT, Char,
|
||||
typename std::enable_if<fmt::is_tuple_like<TupleT>::value>::type> {
|
||||
private:
|
||||
// C++11 generic lambda for format()
|
||||
template <typename FormatContext>
|
||||
struct format_each {
|
||||
template <typename T>
|
||||
void operator()(const T& v) {
|
||||
if (i > 0) {
|
||||
if (formatting.add_prepostfix_space) {
|
||||
*out++ = ' ';
|
||||
}
|
||||
internal::copy(formatting.delimiter, out);
|
||||
}
|
||||
format_to(out,
|
||||
internal::format_str_quoted(
|
||||
(formatting.add_delimiter_spaces && i > 0), v),
|
||||
v);
|
||||
++i;
|
||||
}
|
||||
|
||||
formatting_tuple<Char>& formatting;
|
||||
std::size_t& i;
|
||||
typename std::add_lvalue_reference<decltype(std::declval<FormatContext>().out())>::type out;
|
||||
};
|
||||
|
||||
public:
|
||||
formatting_tuple<Char> formatting;
|
||||
|
||||
template <typename ParseContext>
|
||||
FMT_CONSTEXPR auto parse(ParseContext &ctx) -> decltype(ctx.begin()) {
|
||||
return formatting.parse(ctx);
|
||||
}
|
||||
|
||||
template <typename FormatContext = format_context>
|
||||
auto format(const TupleT &values, FormatContext &ctx) -> decltype(ctx.out()) {
|
||||
auto out = ctx.out();
|
||||
std::size_t i = 0;
|
||||
internal::copy(formatting.prefix, out);
|
||||
|
||||
internal::for_each(values, format_each<FormatContext>{formatting, i, out});
|
||||
if (formatting.add_prepostfix_space) {
|
||||
*out++ = ' ';
|
||||
}
|
||||
internal::copy(formatting.postfix, out);
|
||||
|
||||
return ctx.out();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct is_range {
|
||||
static FMT_CONSTEXPR_DECL const bool value =
|
||||
internal::is_range_<T>::value && !internal::is_like_std_string<T>::value;
|
||||
};
|
||||
|
||||
template <typename RangeT, typename Char>
|
||||
struct formatter<RangeT, Char,
|
||||
typename std::enable_if<fmt::is_range<RangeT>::value>::type> {
|
||||
|
||||
formatting_range<Char> formatting;
|
||||
|
||||
template <typename ParseContext>
|
||||
FMT_CONSTEXPR auto parse(ParseContext &ctx) -> decltype(ctx.begin()) {
|
||||
return formatting.parse(ctx);
|
||||
}
|
||||
|
||||
template <typename FormatContext>
|
||||
typename FormatContext::iterator format(
|
||||
const RangeT &values, FormatContext &ctx) {
|
||||
auto out = ctx.out();
|
||||
internal::copy(formatting.prefix, out);
|
||||
std::size_t i = 0;
|
||||
for (auto it = values.begin(), end = values.end(); it != end; ++it) {
|
||||
if (i > 0) {
|
||||
if (formatting.add_prepostfix_space) {
|
||||
*out++ = ' ';
|
||||
}
|
||||
internal::copy(formatting.delimiter, out);
|
||||
}
|
||||
format_to(out,
|
||||
internal::format_str_quoted(
|
||||
(formatting.add_delimiter_spaces && i > 0), *it),
|
||||
*it);
|
||||
if (++i > formatting.range_length_limit) {
|
||||
format_to(out, " ... <other elements>");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (formatting.add_prepostfix_space) {
|
||||
*out++ = ' ';
|
||||
}
|
||||
internal::copy(formatting.postfix, out);
|
||||
return ctx.out();
|
||||
}
|
||||
};
|
||||
|
||||
FMT_END_NAMESPACE
|
||||
|
||||
#endif // FMT_RANGES_H_
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
// Formatting library for C++ - time formatting
|
||||
//
|
||||
// Copyright (c) 2012 - 2016, Victor Zverovich
|
||||
// All rights reserved.
|
||||
//
|
||||
// For the license information refer to format.h.
|
||||
|
||||
#ifndef FMT_TIME_H_
|
||||
#define FMT_TIME_H_
|
||||
|
||||
#include "format.h"
|
||||
#include <ctime>
|
||||
|
||||
FMT_BEGIN_NAMESPACE
|
||||
|
||||
// Prevents expansion of a preceding token as a function-style macro.
|
||||
// Usage: f FMT_NOMACRO()
|
||||
#define FMT_NOMACRO
|
||||
|
||||
namespace internal{
|
||||
inline null<> localtime_r FMT_NOMACRO(...) { return null<>(); }
|
||||
inline null<> localtime_s(...) { return null<>(); }
|
||||
inline null<> gmtime_r(...) { return null<>(); }
|
||||
inline null<> gmtime_s(...) { return null<>(); }
|
||||
}
|
||||
|
||||
// Thread-safe replacement for std::localtime
|
||||
inline std::tm localtime(std::time_t time) {
|
||||
struct dispatcher {
|
||||
std::time_t time_;
|
||||
std::tm tm_;
|
||||
|
||||
dispatcher(std::time_t t): time_(t) {}
|
||||
|
||||
bool run() {
|
||||
using namespace fmt::internal;
|
||||
return handle(localtime_r(&time_, &tm_));
|
||||
}
|
||||
|
||||
bool handle(std::tm *tm) { return tm != FMT_NULL; }
|
||||
|
||||
bool handle(internal::null<>) {
|
||||
using namespace fmt::internal;
|
||||
return fallback(localtime_s(&tm_, &time_));
|
||||
}
|
||||
|
||||
bool fallback(int res) { return res == 0; }
|
||||
|
||||
bool fallback(internal::null<>) {
|
||||
using namespace fmt::internal;
|
||||
std::tm *tm = std::localtime(&time_);
|
||||
if (tm) tm_ = *tm;
|
||||
return tm != FMT_NULL;
|
||||
}
|
||||
};
|
||||
dispatcher lt(time);
|
||||
if (lt.run())
|
||||
return lt.tm_;
|
||||
// Too big time values may be unsupported.
|
||||
FMT_THROW(format_error("time_t value out of range"));
|
||||
}
|
||||
|
||||
// Thread-safe replacement for std::gmtime
|
||||
inline std::tm gmtime(std::time_t time) {
|
||||
struct dispatcher {
|
||||
std::time_t time_;
|
||||
std::tm tm_;
|
||||
|
||||
dispatcher(std::time_t t): time_(t) {}
|
||||
|
||||
bool run() {
|
||||
using namespace fmt::internal;
|
||||
return handle(gmtime_r(&time_, &tm_));
|
||||
}
|
||||
|
||||
bool handle(std::tm *tm) { return tm != FMT_NULL; }
|
||||
|
||||
bool handle(internal::null<>) {
|
||||
using namespace fmt::internal;
|
||||
return fallback(gmtime_s(&tm_, &time_));
|
||||
}
|
||||
|
||||
bool fallback(int res) { return res == 0; }
|
||||
|
||||
bool fallback(internal::null<>) {
|
||||
std::tm *tm = std::gmtime(&time_);
|
||||
if (tm) tm_ = *tm;
|
||||
return tm != FMT_NULL;
|
||||
}
|
||||
};
|
||||
dispatcher gt(time);
|
||||
if (gt.run())
|
||||
return gt.tm_;
|
||||
// Too big time values may be unsupported.
|
||||
FMT_THROW(format_error("time_t value out of range"));
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
inline std::size_t strftime(char *str, std::size_t count, const char *format,
|
||||
const std::tm *time) {
|
||||
return std::strftime(str, count, format, time);
|
||||
}
|
||||
|
||||
inline std::size_t strftime(wchar_t *str, std::size_t count,
|
||||
const wchar_t *format, const std::tm *time) {
|
||||
return std::wcsftime(str, count, format, time);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
struct formatter<std::tm, Char> {
|
||||
template <typename ParseContext>
|
||||
auto parse(ParseContext &ctx) -> decltype(ctx.begin()) {
|
||||
auto it = internal::null_terminating_iterator<Char>(ctx);
|
||||
if (*it == ':')
|
||||
++it;
|
||||
auto end = it;
|
||||
while (*end && *end != '}')
|
||||
++end;
|
||||
tm_format.reserve(end - it + 1);
|
||||
using internal::pointer_from;
|
||||
tm_format.append(pointer_from(it), pointer_from(end));
|
||||
tm_format.push_back('\0');
|
||||
return pointer_from(end);
|
||||
}
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(const std::tm &tm, FormatContext &ctx) -> decltype(ctx.out()) {
|
||||
internal::basic_buffer<Char> &buf = internal::get_container(ctx.out());
|
||||
std::size_t start = buf.size();
|
||||
for (;;) {
|
||||
std::size_t size = buf.capacity() - start;
|
||||
std::size_t count =
|
||||
internal::strftime(&buf[start], size, &tm_format[0], &tm);
|
||||
if (count != 0) {
|
||||
buf.resize(start + count);
|
||||
break;
|
||||
}
|
||||
if (size >= tm_format.size() * 256) {
|
||||
// If the buffer is 256 times larger than the format string, assume
|
||||
// that `strftime` gives an empty result. There doesn't seem to be a
|
||||
// better way to distinguish the two cases:
|
||||
// https://github.com/fmtlib/fmt/issues/367
|
||||
break;
|
||||
}
|
||||
const std::size_t MIN_GROWTH = 10;
|
||||
buf.reserve(buf.capacity() + (size > MIN_GROWTH ? size : MIN_GROWTH));
|
||||
}
|
||||
return ctx.out();
|
||||
}
|
||||
|
||||
basic_memory_buffer<Char> tm_format;
|
||||
};
|
||||
FMT_END_NAMESPACE
|
||||
|
||||
#endif // FMT_TIME_H_
|
||||
@@ -1,25 +0,0 @@
|
||||
//
|
||||
// Copyright(c) 2016-2018 Gabi Melman.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// Include a bundled header-only copy of fmtlib or an external one.
|
||||
// By default spdlog include its own copy.
|
||||
//
|
||||
|
||||
#if !defined(SPDLOG_FMT_EXTERNAL)
|
||||
#ifndef FMT_HEADER_ONLY
|
||||
#define FMT_HEADER_ONLY
|
||||
#endif
|
||||
#ifndef FMT_USE_WINDOWS_H
|
||||
#define FMT_USE_WINDOWS_H 0
|
||||
#endif
|
||||
#include "bundled/core.h"
|
||||
#include "bundled/format.h"
|
||||
#else // external fmtlib
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/format.h>
|
||||
#endif
|
||||
@@ -1,18 +0,0 @@
|
||||
//
|
||||
// Copyright(c) 2016 Gabi Melman.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
//
|
||||
// include bundled or external copy of fmtlib's ostream support
|
||||
//
|
||||
#if !defined(SPDLOG_FMT_EXTERNAL)
|
||||
#ifndef FMT_HEADER_ONLY
|
||||
#define FMT_HEADER_ONLY
|
||||
#endif
|
||||
#include "bundled/ostream.h"
|
||||
#include "fmt.h"
|
||||
#else
|
||||
#include <fmt/ostream.h>
|
||||
#endif
|
||||
@@ -1,20 +1,16 @@
|
||||
//
|
||||
// Copyright(c) 2015 Gabi Melman.
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "fmt/fmt.h"
|
||||
#include "spdlog/details/log_msg.h"
|
||||
#include "./details/log_msg.h"
|
||||
|
||||
namespace spdlog {
|
||||
|
||||
class formatter
|
||||
{
|
||||
class formatter {
|
||||
public:
|
||||
virtual ~formatter() = default;
|
||||
virtual void format(const details::log_msg &msg, fmt::memory_buffer &dest) = 0;
|
||||
virtual void format(const details::log_msg &msg, memory_buf_t &dest) = 0;
|
||||
virtual std::unique_ptr<formatter> clone() const = 0;
|
||||
};
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
||||
15
include/spdlog/fwd.h
Normal file
15
include/spdlog/fwd.h
Normal file
@@ -0,0 +1,15 @@
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace spdlog {
|
||||
class logger;
|
||||
class formatter;
|
||||
enum class level;
|
||||
|
||||
namespace sinks {
|
||||
class sink;
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
@@ -1,167 +1,211 @@
|
||||
//
|
||||
// Copyright(c) 2015-2108 Gabi Melman.
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
// Thread safe logger (except for set_pattern(..), set_formatter(..) and
|
||||
// set_error_handler())
|
||||
// Has name, log level, vector of std::shared sink pointers and formatter
|
||||
// Upon each log write the logger:
|
||||
// 1. Checks if its log level is enough to log the message and if yes:
|
||||
// 2. Call the underlying sinks to do the job.
|
||||
// 3. Each sink use its own private copy of a formatter to format the message
|
||||
// and send to its destination.
|
||||
//
|
||||
// The use of private formatter per sink provides the opportunity to cache some
|
||||
// formatted data,
|
||||
// and support customize format per each sink.
|
||||
// Thread-safe logger, with exceptions for these non-thread-safe methods:
|
||||
// set_pattern() - Modifies the log pattern.
|
||||
// set_formatter() - Sets a new formatter.
|
||||
// set_error_handler() - Assigns a new error handler.
|
||||
// sinks() (non-const) - Accesses and potentially modifies the sinks directly.
|
||||
// By default, the logger does not throw exceptions during logging.
|
||||
// To enable exception throwing for logging errors, set a custom error handler.
|
||||
|
||||
#include "spdlog/common.h"
|
||||
#include "spdlog/formatter.h"
|
||||
#include "spdlog/sinks/sink.h"
|
||||
|
||||
#include <locale>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
|
||||
#include "common.h"
|
||||
#include "details/err_helper.h"
|
||||
#include "details/log_msg.h"
|
||||
#include "sinks/sink.h"
|
||||
|
||||
namespace spdlog {
|
||||
|
||||
class logger
|
||||
{
|
||||
class SPDLOG_API logger {
|
||||
public:
|
||||
logger(std::string name, sink_ptr single_sink);
|
||||
logger(std::string name, sinks_init_list sinks);
|
||||
// Empty logger
|
||||
explicit logger(std::string name)
|
||||
: name_(std::move(name)) {}
|
||||
|
||||
template<typename It>
|
||||
logger(std::string name, It begin, It end);
|
||||
// Logger with range on sinks
|
||||
template <typename It>
|
||||
logger(std::string name, It begin, It end)
|
||||
: name_(std::move(name)),
|
||||
sinks_(begin, end) {}
|
||||
|
||||
virtual ~logger();
|
||||
// Logger with single sink
|
||||
logger(std::string name, sink_ptr single_sink)
|
||||
: logger(std::move(name), {std::move(single_sink)}) {}
|
||||
|
||||
logger(const logger &) = delete;
|
||||
logger &operator=(const logger &) = delete;
|
||||
// Logger with sinks init list
|
||||
logger(std::string name, sinks_init_list sinks)
|
||||
: logger(std::move(name), sinks.begin(), sinks.end()) {}
|
||||
|
||||
template<typename... Args>
|
||||
void log(level::level_enum lvl, const char *fmt, const Args &... args);
|
||||
logger(const logger &other) ;
|
||||
logger(logger &&other) noexcept;
|
||||
|
||||
template<typename... Args>
|
||||
void log(level::level_enum lvl, const char *msg);
|
||||
~logger() = default;
|
||||
|
||||
template<typename... Args>
|
||||
void trace(const char *fmt, const Args &... args);
|
||||
template <typename... Args>
|
||||
void log(const source_loc &loc, level lvl, format_string_t<Args...> fmt, Args &&...args) noexcept {
|
||||
if (should_log(lvl)) {
|
||||
log_with_format_(loc, lvl, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void debug(const char *fmt, const Args &... args);
|
||||
template <typename... Args>
|
||||
void log(level lvl, format_string_t<Args...> fmt, Args &&...args) noexcept {
|
||||
if (should_log(lvl)) {
|
||||
log_with_format_(source_loc{}, lvl, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
// log with no format string, just string message
|
||||
void log(const source_loc &loc, level lvl, string_view_t msg) noexcept {
|
||||
if (should_log(lvl)) {
|
||||
sink_it_(details::log_msg(loc, name_, lvl, msg));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void info(const char *fmt, const Args &... args);
|
||||
void log(level lvl, string_view_t msg) noexcept {
|
||||
if (should_log(lvl)) {
|
||||
sink_it_(details::log_msg(source_loc{}, name_, lvl, msg));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void warn(const char *fmt, const Args &... args);
|
||||
// support for custom time
|
||||
void log(log_clock::time_point log_time, const source_loc &loc, level lvl, string_view_t msg) noexcept {
|
||||
if (should_log(lvl)) {
|
||||
sink_it_(details::log_msg(log_time, loc, name_, lvl, msg));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void error(const char *fmt, const Args &... args);
|
||||
template <typename... Args>
|
||||
void trace(format_string_t<Args...> fmt, Args &&...args) noexcept {
|
||||
log(level::trace, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void critical(const char *fmt, const Args &... args);
|
||||
template <typename... Args>
|
||||
void debug(format_string_t<Args...> fmt, Args &&...args) noexcept {
|
||||
log(level::debug, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
#ifndef _WIN32
|
||||
#error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows
|
||||
#else
|
||||
template<typename... Args>
|
||||
void log(level::level_enum lvl, const wchar_t *fmt, const Args &... args);
|
||||
template <typename... Args>
|
||||
void info(format_string_t<Args...> fmt, Args &&...args) noexcept {
|
||||
log(level::info, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void trace(const wchar_t *fmt, const Args &... args);
|
||||
template <typename... Args>
|
||||
void warn(format_string_t<Args...> fmt, Args &&...args) noexcept {
|
||||
log(level::warn, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void debug(const wchar_t *fmt, const Args &... args);
|
||||
template <typename... Args>
|
||||
void error(format_string_t<Args...> fmt, Args &&...args) noexcept {
|
||||
log(level::err, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void info(const wchar_t *fmt, const Args &... args);
|
||||
template <typename... Args>
|
||||
void critical(format_string_t<Args...> fmt, Args &&...args) noexcept {
|
||||
log(level::critical, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void warn(const wchar_t *fmt, const Args &... args);
|
||||
// log functions with no format string, just string
|
||||
void trace(string_view_t msg) noexcept { log(level::trace, msg); }
|
||||
void debug(string_view_t msg) noexcept { log(level::debug, msg); }
|
||||
void info(string_view_t msg) noexcept { log(level::info, msg); }
|
||||
void warn(string_view_t msg) noexcept { log(level::warn, msg); }
|
||||
void error(string_view_t msg) noexcept { log(level::err, msg); }
|
||||
void critical(string_view_t msg) noexcept { log(level::critical, msg); }
|
||||
|
||||
template<typename... Args>
|
||||
void error(const wchar_t *fmt, const Args &... args);
|
||||
// return true if logging is enabled for the given level.
|
||||
[[nodiscard]] bool should_log(level msg_level) const noexcept { return msg_level >= level_.load(std::memory_order_relaxed); }
|
||||
|
||||
template<typename... Args>
|
||||
void critical(const wchar_t *fmt, const Args &... args);
|
||||
#endif // _WIN32
|
||||
#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT
|
||||
// return true if the given message should be flushed
|
||||
[[nodiscard]] bool should_flush(const details::log_msg &msg) const noexcept {
|
||||
return (msg.log_level >= flush_level_.load(std::memory_order_relaxed)) && (msg.log_level != level::off);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void log(level::level_enum lvl, const T &);
|
||||
// set the level of logging
|
||||
void set_level(level level);
|
||||
|
||||
template<typename T>
|
||||
void trace(const T &msg);
|
||||
// return the active log level
|
||||
[[nodiscard]] level log_level() const noexcept;
|
||||
|
||||
template<typename T>
|
||||
void debug(const T &msg);
|
||||
|
||||
template<typename T>
|
||||
void info(const T &msg);
|
||||
|
||||
template<typename T>
|
||||
void warn(const T &msg);
|
||||
|
||||
template<typename T>
|
||||
void error(const T &msg);
|
||||
|
||||
template<typename T>
|
||||
void critical(const T &msg);
|
||||
|
||||
bool should_log(level::level_enum msg_level) const;
|
||||
void set_level(level::level_enum log_level);
|
||||
level::level_enum level() const;
|
||||
const std::string &name() const;
|
||||
// return the name of the logger
|
||||
[[nodiscard]] const std::string &name() const noexcept;
|
||||
|
||||
// set formatting for the sinks in this logger.
|
||||
// each sink will get a seperate instance of the formatter object.
|
||||
void set_formatter(std::unique_ptr<formatter> formatter);
|
||||
// each sink will get a separate instance of the formatter object.
|
||||
void set_formatter(std::unique_ptr<formatter> f);
|
||||
|
||||
// set formatting for the sinks in this logger.
|
||||
// equivalent to
|
||||
// set_formatter(make_unique<pattern_formatter>(pattern, time_type))
|
||||
// Note: each sink will get a new instance of a formatter object, replacing the old one.
|
||||
void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local);
|
||||
|
||||
// flush functions
|
||||
void flush();
|
||||
void flush_on(level::level_enum log_level);
|
||||
level::level_enum flush_level() const;
|
||||
void flush() noexcept;
|
||||
void flush_on(level level) noexcept;
|
||||
[[nodiscard]] level flush_level() const noexcept;
|
||||
|
||||
// sinks
|
||||
const std::vector<sink_ptr> &sinks() const;
|
||||
std::vector<sink_ptr> &sinks();
|
||||
[[nodiscard]] const std::vector<sink_ptr> &sinks() const noexcept;
|
||||
[[nodiscard]] std::vector<sink_ptr> &sinks() noexcept;
|
||||
|
||||
// error handler
|
||||
void set_error_handler(log_err_handler err_handler);
|
||||
log_err_handler error_handler();
|
||||
// error handler. default is err_handler that prints the error to stderr.
|
||||
void set_error_handler(err_handler);
|
||||
|
||||
// create new logger with same sinks and configuration.
|
||||
virtual std::shared_ptr<logger> clone(std::string logger_name);
|
||||
std::shared_ptr<logger> clone(std::string logger_name);
|
||||
|
||||
protected:
|
||||
virtual void sink_it_(details::log_msg &msg);
|
||||
virtual void flush_();
|
||||
|
||||
bool should_flush_(const details::log_msg &msg);
|
||||
|
||||
// default error handler: print the error to stderr with the max rate of 1
|
||||
// message/minute
|
||||
void default_err_handler_(const std::string &msg);
|
||||
|
||||
// increment the message count (only if defined(SPDLOG_ENABLE_MESSAGE_COUNTER))
|
||||
void incr_msg_counter_(details::log_msg &msg);
|
||||
|
||||
const std::string name_;
|
||||
private:
|
||||
std::string name_;
|
||||
std::vector<sink_ptr> sinks_;
|
||||
spdlog::level_t level_;
|
||||
spdlog::level_t flush_level_;
|
||||
log_err_handler err_handler_;
|
||||
std::atomic<time_t> last_err_time_;
|
||||
std::atomic<size_t> msg_counter_;
|
||||
};
|
||||
} // namespace spdlog
|
||||
atomic_level_t level_{level::info};
|
||||
atomic_level_t flush_level_{level::off};
|
||||
details::err_helper err_helper_;
|
||||
|
||||
#include "details/logger_impl.h"
|
||||
// common implementation for after templated public api has been resolved to format string and
|
||||
// args
|
||||
template <typename... Args>
|
||||
void log_with_format_(const source_loc &loc,
|
||||
const level lvl,
|
||||
const format_string_t<Args...> &format_string,
|
||||
Args &&...args) noexcept {
|
||||
assert(should_log(lvl));
|
||||
try {
|
||||
memory_buf_t buf;
|
||||
fmt::vformat_to(std::back_inserter(buf), format_string, fmt::make_format_args(args...));
|
||||
sink_it_(details::log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size())));
|
||||
} catch (const std::exception &ex) {
|
||||
err_helper_.handle_ex(name_, loc, ex);
|
||||
} catch (...) {
|
||||
err_helper_.handle_unknown_ex(name_, loc);
|
||||
}
|
||||
}
|
||||
|
||||
// log the given message (if the given log level is high enough)
|
||||
void sink_it_(const details::log_msg &msg) noexcept {
|
||||
assert(should_log(msg.log_level));
|
||||
for (auto &sink : sinks_) {
|
||||
if (sink->should_log(msg.log_level)) {
|
||||
try {
|
||||
sink->log(msg);
|
||||
} catch (const std::exception &ex) {
|
||||
err_helper_.handle_ex(name_, msg.source, ex);
|
||||
} catch (...) {
|
||||
err_helper_.handle_unknown_ex(name_, msg.source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (should_flush(msg)) {
|
||||
flush_();
|
||||
}
|
||||
}
|
||||
void flush_() noexcept;
|
||||
};
|
||||
|
||||
} // namespace spdlog
|
||||
|
||||
108
include/spdlog/pattern_formatter.h
Normal file
108
include/spdlog/pattern_formatter.h
Normal file
@@ -0,0 +1,108 @@
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "./common.h"
|
||||
#include "./details/log_msg.h"
|
||||
#include "./details/os.h"
|
||||
#include "./formatter.h"
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
// padding information.
|
||||
struct padding_info {
|
||||
enum class pad_side { left, right, center };
|
||||
|
||||
padding_info() = default;
|
||||
padding_info(size_t width, padding_info::pad_side side, bool truncate)
|
||||
: width_(width),
|
||||
side_(side),
|
||||
truncate_(truncate),
|
||||
enabled_(true) {}
|
||||
|
||||
bool enabled() const { return enabled_; }
|
||||
size_t width_ = 0;
|
||||
pad_side side_ = pad_side::left;
|
||||
bool truncate_ = false;
|
||||
bool enabled_ = false;
|
||||
};
|
||||
|
||||
class SPDLOG_API flag_formatter {
|
||||
public:
|
||||
explicit flag_formatter(padding_info padinfo)
|
||||
: padinfo_(padinfo) {}
|
||||
flag_formatter() = default;
|
||||
virtual ~flag_formatter() = default;
|
||||
virtual void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) = 0;
|
||||
|
||||
protected:
|
||||
padding_info padinfo_;
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
|
||||
class SPDLOG_API custom_flag_formatter : public details::flag_formatter {
|
||||
public:
|
||||
virtual std::unique_ptr<custom_flag_formatter> clone() const = 0;
|
||||
|
||||
void set_padding_info(const details::padding_info &padding) { flag_formatter::padinfo_ = padding; }
|
||||
};
|
||||
|
||||
class SPDLOG_API pattern_formatter final : public formatter {
|
||||
public:
|
||||
using custom_flags = std::unordered_map<char, std::unique_ptr<custom_flag_formatter>>;
|
||||
|
||||
explicit pattern_formatter(std::string pattern,
|
||||
pattern_time_type time_type = pattern_time_type::local,
|
||||
std::string eol = spdlog::details::os::default_eol,
|
||||
custom_flags custom_user_flags = custom_flags());
|
||||
|
||||
// use default pattern is not given
|
||||
explicit pattern_formatter(pattern_time_type time_type = pattern_time_type::local,
|
||||
std::string eol = spdlog::details::os::default_eol);
|
||||
|
||||
pattern_formatter(const pattern_formatter &other) = delete;
|
||||
pattern_formatter &operator=(const pattern_formatter &other) = delete;
|
||||
|
||||
std::unique_ptr<formatter> clone() const override;
|
||||
void format(const details::log_msg &msg, memory_buf_t &dest) override;
|
||||
|
||||
template <typename T, typename... Args>
|
||||
pattern_formatter &add_flag(char flag, Args &&...args) {
|
||||
custom_handlers_[flag] = std::make_unique<T>(std::forward<Args>(args)...);
|
||||
return *this;
|
||||
}
|
||||
void set_pattern(std::string pattern);
|
||||
void need_localtime(bool need = true);
|
||||
|
||||
private:
|
||||
std::string pattern_;
|
||||
std::string eol_;
|
||||
pattern_time_type pattern_time_type_;
|
||||
bool need_localtime_;
|
||||
std::tm cached_tm_;
|
||||
std::chrono::seconds last_log_secs_;
|
||||
std::vector<std::unique_ptr<details::flag_formatter>> formatters_;
|
||||
custom_flags custom_handlers_;
|
||||
|
||||
std::tm get_time_(const details::log_msg &msg) const;
|
||||
template <typename Padder>
|
||||
void handle_flag_(char flag, details::padding_info padding);
|
||||
|
||||
// Extract given pad spec (e.g. %8X)
|
||||
// Advance the given it pass the end of the padding spec found (if any)
|
||||
// Return padding.
|
||||
static details::padding_info handle_padspec_(std::string::const_iterator &it, std::string::const_iterator end);
|
||||
|
||||
void compile_pattern_(const std::string &pattern);
|
||||
};
|
||||
} // namespace spdlog
|
||||
@@ -1,94 +1,108 @@
|
||||
//
|
||||
// Copyright(c) 2015 Gabi Melman.
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "spdlog/details/fmt_helper.h"
|
||||
#include "spdlog/details/null_mutex.h"
|
||||
#include "spdlog/details/os.h"
|
||||
#include "spdlog/sinks/base_sink.h"
|
||||
#ifdef __ANDROID__
|
||||
|
||||
#include <android/log.h>
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <android/log.h>
|
||||
|
||||
#if !defined(SPDLOG_ANDROID_RETRIES)
|
||||
#define SPDLOG_ANDROID_RETRIES 2
|
||||
#endif
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <type_traits>
|
||||
|
||||
#include "../details/fmt_helper.h"
|
||||
#include "../details/null_mutex.h"
|
||||
#include "../details/os.h"
|
||||
#include "./base_sink.h"
|
||||
|
||||
#if !defined(SPDLOG_ANDROID_RETRIES)
|
||||
#define SPDLOG_ANDROID_RETRIES 2
|
||||
#endif
|
||||
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
|
||||
/*
|
||||
* Android sink (logging using __android_log_write)
|
||||
* Android sink
|
||||
* (logging using __android_log_write or __android_log_buf_write depending on the specified
|
||||
* BufferID)
|
||||
*/
|
||||
template<typename Mutex>
|
||||
class android_sink final : public base_sink<Mutex>
|
||||
{
|
||||
template <typename Mutex, int BufferID = log_id::LOG_ID_MAIN>
|
||||
class android_sink final : public base_sink<Mutex> {
|
||||
public:
|
||||
explicit android_sink(std::string tag = "spdlog", bool use_raw_msg = false)
|
||||
: tag_(std::move(tag))
|
||||
, use_raw_msg_(use_raw_msg)
|
||||
{
|
||||
}
|
||||
: tag_(std::move(tag)),
|
||||
use_raw_msg_(use_raw_msg) {}
|
||||
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
const android_LogPriority priority = convert_to_android_(msg.level);
|
||||
fmt::memory_buffer formatted;
|
||||
if (use_raw_msg_)
|
||||
{
|
||||
details::fmt_helper::append_buf(msg.raw, formatted);
|
||||
}
|
||||
else
|
||||
{
|
||||
sink::formatter_->format(msg, formatted);
|
||||
void sink_it_(const details::log_msg &msg) override {
|
||||
const android_LogPriority priority = convert_to_android_(msg.log_level);
|
||||
memory_buf_t formatted;
|
||||
if (use_raw_msg_) {
|
||||
details::fmt_helper::append_string_view(msg.payload, formatted);
|
||||
} else {
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
}
|
||||
formatted.push_back('\0');
|
||||
const char *msg_output = formatted.data();
|
||||
|
||||
// See system/core/liblog/logger_write.c for explanation of return value
|
||||
int ret = __android_log_write(priority, tag_.c_str(), msg_output);
|
||||
int ret = android_log(priority, tag_.c_str(), msg_output);
|
||||
if (ret == -EPERM) {
|
||||
return; // !__android_log_is_loggable
|
||||
}
|
||||
int retry_count = 0;
|
||||
while ((ret == -11 /*EAGAIN*/) && (retry_count < SPDLOG_ANDROID_RETRIES))
|
||||
{
|
||||
while ((ret == -11 /*EAGAIN*/) && (retry_count < SPDLOG_ANDROID_RETRIES)) {
|
||||
details::os::sleep_for_millis(5);
|
||||
ret = __android_log_write(priority, tag_.c_str(), msg_output);
|
||||
ret = android_log(priority, tag_.c_str(), msg_output);
|
||||
retry_count++;
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
throw spdlog_ex("__android_log_write() failed", ret);
|
||||
if (ret < 0) {
|
||||
throw_spdlog_ex("logging to Android failed", ret);
|
||||
}
|
||||
}
|
||||
|
||||
void flush_() override {}
|
||||
|
||||
private:
|
||||
static android_LogPriority convert_to_android_(spdlog::level::level_enum level)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case spdlog::level::trace:
|
||||
return ANDROID_LOG_VERBOSE;
|
||||
case spdlog::level::debug:
|
||||
return ANDROID_LOG_DEBUG;
|
||||
case spdlog::level::info:
|
||||
return ANDROID_LOG_INFO;
|
||||
case spdlog::level::warn:
|
||||
return ANDROID_LOG_WARN;
|
||||
case spdlog::level::err:
|
||||
return ANDROID_LOG_ERROR;
|
||||
case spdlog::level::critical:
|
||||
return ANDROID_LOG_FATAL;
|
||||
default:
|
||||
return ANDROID_LOG_DEFAULT;
|
||||
// There might be liblog versions used, that do not support __android_log_buf_write. So we only
|
||||
// compile and link against
|
||||
// __android_log_buf_write, if user explicitly provides a non-default log buffer. Otherwise,
|
||||
// when using the default log buffer, always log via __android_log_write.
|
||||
template <int ID = BufferID>
|
||||
typename std::enable_if<ID == static_cast<int>(log_id::LOG_ID_MAIN), int>::type android_log(int prio,
|
||||
const char *tag,
|
||||
const char *text) {
|
||||
return __android_log_write(prio, tag, text);
|
||||
}
|
||||
|
||||
template <int ID = BufferID>
|
||||
typename std::enable_if<ID != static_cast<int>(log_id::LOG_ID_MAIN), int>::type android_log(int prio,
|
||||
const char *tag,
|
||||
const char *text) {
|
||||
return __android_log_buf_write(ID, prio, tag, text);
|
||||
}
|
||||
|
||||
static android_LogPriority convert_to_android_(spdlog::level level) {
|
||||
switch (level) {
|
||||
case spdlog::level::trace:
|
||||
return ANDROID_LOG_VERBOSE;
|
||||
case spdlog::level::debug:
|
||||
return ANDROID_LOG_DEBUG;
|
||||
case spdlog::level::info:
|
||||
return ANDROID_LOG_INFO;
|
||||
case spdlog::level::warn:
|
||||
return ANDROID_LOG_WARN;
|
||||
case spdlog::level::err:
|
||||
return ANDROID_LOG_ERROR;
|
||||
case spdlog::level::critical:
|
||||
return ANDROID_LOG_FATAL;
|
||||
default:
|
||||
return ANDROID_LOG_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,20 +112,13 @@ private:
|
||||
|
||||
using android_sink_mt = android_sink<std::mutex>;
|
||||
using android_sink_st = android_sink<details::null_mutex>;
|
||||
} // namespace sinks
|
||||
|
||||
// Create and register android syslog logger
|
||||
template <int BufferId = log_id::LOG_ID_MAIN>
|
||||
using android_sink_buf_mt = android_sink<std::mutex, BufferId>;
|
||||
template <int BufferId = log_id::LOG_ID_MAIN>
|
||||
using android_sink_buf_st = android_sink<details::null_mutex, BufferId>;
|
||||
|
||||
template<typename Factory = default_factory>
|
||||
inline std::shared_ptr<logger> android_logger_mt(const std::string &logger_name, const std::string &tag = "spdlog")
|
||||
{
|
||||
return Factory::template create<sinks::android_sink_mt>(logger_name, tag);
|
||||
}
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
||||
template<typename Factory = default_factory>
|
||||
inline std::shared_ptr<logger> android_logger_st(const std::string &logger_name, const std::string &tag = "spdlog")
|
||||
{
|
||||
return Factory::template create<sinks::android_sink_st>(logger_name, tag);
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
#endif // __ANDROID__
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
//
|
||||
// Copyright(c) 2017 spdlog authors.
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "spdlog/details/console_globals.h"
|
||||
#include "spdlog/details/null_mutex.h"
|
||||
#include "spdlog/details/os.h"
|
||||
#include "spdlog/sinks/sink.h"
|
||||
|
||||
#include <memory>
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "../details/null_mutex.h"
|
||||
#include "./base_sink.h"
|
||||
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
@@ -24,134 +19,83 @@ namespace sinks {
|
||||
* of the message.
|
||||
* If no color terminal detected, omit the escape codes.
|
||||
*/
|
||||
template<typename TargetStream, class ConsoleMutex>
|
||||
class ansicolor_sink final : public sink
|
||||
{
|
||||
|
||||
template <typename Mutex>
|
||||
class ansicolor_sink : public base_sink<Mutex> {
|
||||
public:
|
||||
using mutex_t = typename ConsoleMutex::mutex_t;
|
||||
ansicolor_sink()
|
||||
: target_file_(TargetStream::stream())
|
||||
, mutex_(ConsoleMutex::mutex())
|
||||
|
||||
{
|
||||
should_do_colors_ = details::os::in_terminal(target_file_) && details::os::is_color_terminal();
|
||||
colors_[level::trace] = white;
|
||||
colors_[level::debug] = cyan;
|
||||
colors_[level::info] = green;
|
||||
colors_[level::warn] = yellow + bold;
|
||||
colors_[level::err] = red + bold;
|
||||
colors_[level::critical] = bold + on_red;
|
||||
colors_[level::off] = reset;
|
||||
}
|
||||
|
||||
ansicolor_sink(FILE *target_file, color_mode mode);
|
||||
ansicolor_sink(const ansicolor_sink &other) = delete;
|
||||
ansicolor_sink(ansicolor_sink &&other) = delete;
|
||||
ansicolor_sink &operator=(const ansicolor_sink &other) = delete;
|
||||
ansicolor_sink &operator=(ansicolor_sink &&other) = delete;
|
||||
~ansicolor_sink() override = default;
|
||||
|
||||
ansicolor_sink(const ansicolor_sink &other) = delete;
|
||||
ansicolor_sink &operator=(const ansicolor_sink &other) = delete;
|
||||
void set_color(level color_level, string_view_t color);
|
||||
void set_color_mode(color_mode mode);
|
||||
bool should_color() const;
|
||||
|
||||
void set_color(level::level_enum color_level, const std::string &color)
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
colors_[color_level] = color;
|
||||
}
|
||||
|
||||
/// Formatting codes
|
||||
const std::string reset = "\033[m";
|
||||
const std::string bold = "\033[1m";
|
||||
const std::string dark = "\033[2m";
|
||||
const std::string underline = "\033[4m";
|
||||
const std::string blink = "\033[5m";
|
||||
const std::string reverse = "\033[7m";
|
||||
const std::string concealed = "\033[8m";
|
||||
const std::string clear_line = "\033[K";
|
||||
// Formatting codes
|
||||
static constexpr std::string_view reset = "\033[m";
|
||||
static constexpr std::string_view bold = "\033[1m";
|
||||
static constexpr std::string_view dark = "\033[2m";
|
||||
static constexpr std::string_view underline = "\033[4m";
|
||||
static constexpr std::string_view blink = "\033[5m";
|
||||
static constexpr std::string_view reverse = "\033[7m";
|
||||
static constexpr std::string_view concealed = "\033[8m";
|
||||
static constexpr std::string_view clear_line = "\033[K";
|
||||
|
||||
// Foreground colors
|
||||
const std::string black = "\033[30m";
|
||||
const std::string red = "\033[31m";
|
||||
const std::string green = "\033[32m";
|
||||
const std::string yellow = "\033[33m";
|
||||
const std::string blue = "\033[34m";
|
||||
const std::string magenta = "\033[35m";
|
||||
const std::string cyan = "\033[36m";
|
||||
const std::string white = "\033[37m";
|
||||
static constexpr std::string_view black = "\033[30m";
|
||||
static constexpr std::string_view red = "\033[31m";
|
||||
static constexpr std::string_view green = "\033[32m";
|
||||
static constexpr std::string_view yellow = "\033[33m";
|
||||
static constexpr std::string_view blue = "\033[34m";
|
||||
static constexpr std::string_view magenta = "\033[35m";
|
||||
static constexpr std::string_view cyan = "\033[36m";
|
||||
static constexpr std::string_view white = "\033[37m";
|
||||
|
||||
/// Background colors
|
||||
const std::string on_black = "\033[40m";
|
||||
const std::string on_red = "\033[41m";
|
||||
const std::string on_green = "\033[42m";
|
||||
const std::string on_yellow = "\033[43m";
|
||||
const std::string on_blue = "\033[44m";
|
||||
const std::string on_magenta = "\033[45m";
|
||||
const std::string on_cyan = "\033[46m";
|
||||
const std::string on_white = "\033[47m";
|
||||
// Background colors
|
||||
static constexpr std::string_view on_black = "\033[40m";
|
||||
static constexpr std::string_view on_red = "\033[41m";
|
||||
static constexpr std::string_view on_green = "\033[42m";
|
||||
static constexpr std::string_view on_yellow = "\033[43m";
|
||||
static constexpr std::string_view on_blue = "\033[44m";
|
||||
static constexpr std::string_view on_magenta = "\033[45m";
|
||||
static constexpr std::string_view on_cyan = "\033[46m";
|
||||
static constexpr std::string_view on_white = "\033[47m";
|
||||
|
||||
void log(const details::log_msg &msg) override
|
||||
{
|
||||
// Wrap the originally formatted message in color codes.
|
||||
// If color is not supported in the terminal, log as is instead.
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
|
||||
fmt::memory_buffer formatted;
|
||||
formatter_->format(msg, formatted);
|
||||
if (should_do_colors_ && msg.color_range_end > msg.color_range_start)
|
||||
{
|
||||
// before color range
|
||||
print_range_(formatted, 0, msg.color_range_start);
|
||||
// in color range
|
||||
print_ccode_(colors_[msg.level]);
|
||||
print_range_(formatted, msg.color_range_start, msg.color_range_end);
|
||||
print_ccode_(reset);
|
||||
// after color range
|
||||
print_range_(formatted, msg.color_range_end, formatted.size());
|
||||
}
|
||||
else // no color
|
||||
{
|
||||
print_range_(formatted, 0, formatted.size());
|
||||
}
|
||||
fflush(target_file_);
|
||||
}
|
||||
|
||||
void flush() override
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
fflush(target_file_);
|
||||
}
|
||||
|
||||
void set_pattern(const std::string &pattern) final
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
formatter_ = std::unique_ptr<spdlog::formatter>(new pattern_formatter(pattern));
|
||||
}
|
||||
|
||||
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) override
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
formatter_ = std::move(sink_formatter);
|
||||
}
|
||||
// Bold colors
|
||||
static constexpr std::string_view yellow_bold = "\033[33m\033[1m";
|
||||
static constexpr std::string_view red_bold = "\033[31m\033[1m";
|
||||
static constexpr std::string_view bold_on_red = "\033[1m\033[41m";
|
||||
|
||||
private:
|
||||
void print_ccode_(const std::string &color_code)
|
||||
{
|
||||
fwrite(color_code.data(), sizeof(char), color_code.size(), target_file_);
|
||||
}
|
||||
void print_range_(const fmt::memory_buffer &formatted, size_t start, size_t end)
|
||||
{
|
||||
fwrite(formatted.data() + start, sizeof(char), end - start, target_file_);
|
||||
}
|
||||
|
||||
void sink_it_(const details::log_msg &msg) override;
|
||||
void flush_() override;
|
||||
FILE *target_file_;
|
||||
mutex_t &mutex_;
|
||||
|
||||
bool should_do_colors_;
|
||||
std::unordered_map<level::level_enum, std::string, level::level_hasher> colors_;
|
||||
std::array<std::string, levels_count> colors_;
|
||||
void print_ccode_(const string_view_t color_code);
|
||||
void print_range_(const memory_buf_t &formatted, size_t start, size_t end);
|
||||
static std::string to_string_(const string_view_t sv);
|
||||
};
|
||||
|
||||
using ansicolor_stdout_sink_mt = ansicolor_sink<details::console_stdout, details::console_mutex>;
|
||||
using ansicolor_stdout_sink_st = ansicolor_sink<details::console_stdout, details::console_nullmutex>;
|
||||
template <typename Mutex>
|
||||
class ansicolor_stdout_sink final : public ansicolor_sink<Mutex> {
|
||||
public:
|
||||
explicit ansicolor_stdout_sink(color_mode mode = color_mode::automatic);
|
||||
};
|
||||
|
||||
using ansicolor_stderr_sink_mt = ansicolor_sink<details::console_stderr, details::console_mutex>;
|
||||
using ansicolor_stderr_sink_st = ansicolor_sink<details::console_stderr, details::console_nullmutex>;
|
||||
template <typename Mutex>
|
||||
class ansicolor_stderr_sink final : public ansicolor_sink<Mutex> {
|
||||
public:
|
||||
explicit ansicolor_stderr_sink(color_mode mode = color_mode::automatic);
|
||||
};
|
||||
|
||||
} // namespace sinks
|
||||
using ansicolor_stdout_sink_mt = ansicolor_stdout_sink<std::mutex>;
|
||||
using ansicolor_stdout_sink_st = ansicolor_stdout_sink<details::null_mutex>;
|
||||
using ansicolor_stderr_sink_mt = ansicolor_stderr_sink<std::mutex>;
|
||||
using ansicolor_stderr_sink_st = ansicolor_stderr_sink<details::null_mutex>;
|
||||
|
||||
} // namespace spdlog
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
||||
86
include/spdlog/sinks/async_sink.h
Normal file
86
include/spdlog/sinks/async_sink.h
Normal file
@@ -0,0 +1,86 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "../details/async_log_msg.h"
|
||||
#include "../details/err_helper.h"
|
||||
#include "sink.h"
|
||||
|
||||
// async_sink is a sink that sends log messages to a dist_sink in a separate thread using a queue.
|
||||
// The worker thread dequeues the messages and sends them to the dist_sink to perform the actual logging.
|
||||
// Once the sink is destroyed, the worker thread empties the queue and exits.
|
||||
|
||||
namespace spdlog::details { // forward declaration
|
||||
template <typename T>
|
||||
class mpmc_blocking_queue;
|
||||
}
|
||||
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
|
||||
class SPDLOG_API async_sink final : public sink {
|
||||
public:
|
||||
enum class overflow_policy : std::uint8_t {
|
||||
block, // Block until the log message can be enqueued (default).
|
||||
overrun_oldest, // Overrun the oldest message in the queue if full.
|
||||
discard_new // Discard the log message if the queue is full
|
||||
};
|
||||
|
||||
enum { default_queue_size = 8192, max_queue_size = 10 * 1024 * 1024 };
|
||||
|
||||
struct config {
|
||||
size_t queue_size = default_queue_size;
|
||||
overflow_policy policy = overflow_policy::block;
|
||||
std::vector<std::shared_ptr<sink>> sinks;
|
||||
std::function<void()> on_thread_start = nullptr;
|
||||
std::function<void()> on_thread_stop = nullptr;
|
||||
err_handler custom_err_handler = nullptr;
|
||||
};
|
||||
|
||||
explicit async_sink(config async_config);
|
||||
|
||||
// create an async_sink with one backend sink
|
||||
template <typename Sink, typename... SinkArgs>
|
||||
static std::shared_ptr<async_sink> with(SinkArgs &&...sink_args) {
|
||||
config cfg{};
|
||||
cfg.sinks.emplace_back(std::make_shared<Sink>(std::forward<SinkArgs>(sink_args)...));
|
||||
return std::make_shared<async_sink>(cfg);
|
||||
}
|
||||
|
||||
~async_sink() override;
|
||||
|
||||
// sink interface implementation
|
||||
void log(const details::log_msg &msg) override;
|
||||
void flush() override;
|
||||
void set_pattern(const std::string &pattern) override;
|
||||
void set_formatter(std::unique_ptr<formatter> sink_formatter) override;
|
||||
|
||||
// async sink specific methods
|
||||
[[nodiscard]] size_t get_overrun_counter() const;
|
||||
void reset_overrun_counter() const;
|
||||
[[nodiscard]] size_t get_discard_counter() const;
|
||||
void reset_discard_counter() const;
|
||||
[[nodiscard]] const config &get_config() const;
|
||||
|
||||
private:
|
||||
using async_log_msg = details::async_log_msg;
|
||||
using queue_t = details::mpmc_blocking_queue<async_log_msg>;
|
||||
|
||||
void send_message_(async_log_msg::type msg_type, const details::log_msg &msg) const;
|
||||
void backend_loop_();
|
||||
void backend_log_(const details::log_msg &msg) ;
|
||||
void backend_flush_();
|
||||
|
||||
config config_;
|
||||
std::unique_ptr<queue_t> q_;
|
||||
std::thread worker_thread_;
|
||||
details::err_helper err_helper_;
|
||||
};
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
@@ -1,69 +1,48 @@
|
||||
//
|
||||
// Copyright(c) 2015 Gabi Melman.
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
//
|
||||
// base sink templated over a mutex (either dummy or real)
|
||||
// concrete implementation should override the sink_it_() and flush_() methods.
|
||||
// locking is taken care of in this class - no locking needed by the
|
||||
// implementers..
|
||||
// implementers
|
||||
//
|
||||
|
||||
#include "spdlog/common.h"
|
||||
#include "spdlog/details/log_msg.h"
|
||||
#include "spdlog/formatter.h"
|
||||
#include "spdlog/sinks/sink.h"
|
||||
#include "../common.h"
|
||||
#include "../details/log_msg.h"
|
||||
#include "./sink.h"
|
||||
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
template<typename Mutex>
|
||||
class base_sink : public sink
|
||||
{
|
||||
template <typename Mutex>
|
||||
class SPDLOG_API base_sink : public sink {
|
||||
public:
|
||||
base_sink() = default;
|
||||
base_sink();
|
||||
explicit base_sink(std::unique_ptr<spdlog::formatter> formatter);
|
||||
~base_sink() override = default;
|
||||
|
||||
base_sink(const base_sink &) = delete;
|
||||
base_sink(base_sink &&) = delete;
|
||||
|
||||
base_sink &operator=(const base_sink &) = delete;
|
||||
base_sink &operator=(base_sink &&) = delete;
|
||||
|
||||
void log(const details::log_msg &msg) final
|
||||
{
|
||||
std::lock_guard<Mutex> lock(mutex_);
|
||||
sink_it_(msg);
|
||||
}
|
||||
|
||||
void flush() final
|
||||
{
|
||||
std::lock_guard<Mutex> lock(mutex_);
|
||||
flush_();
|
||||
}
|
||||
|
||||
void set_pattern(const std::string &pattern) final
|
||||
{
|
||||
std::lock_guard<Mutex> lock(mutex_);
|
||||
set_pattern_(pattern);
|
||||
}
|
||||
|
||||
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) final
|
||||
{
|
||||
std::lock_guard<Mutex> lock(mutex_);
|
||||
set_formatter_(std::move(sink_formatter));
|
||||
}
|
||||
void log(const details::log_msg &msg) final override;
|
||||
void flush() final override;
|
||||
void set_pattern(const std::string &pattern) final override;
|
||||
void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) final override;
|
||||
|
||||
protected:
|
||||
// sink formatter
|
||||
std::unique_ptr<spdlog::formatter> formatter_;
|
||||
Mutex mutex_;
|
||||
|
||||
virtual void sink_it_(const details::log_msg &msg) = 0;
|
||||
virtual void flush_() = 0;
|
||||
|
||||
virtual void set_pattern_(const std::string &pattern)
|
||||
{
|
||||
set_formatter_(details::make_unique<spdlog::pattern_formatter>(pattern));
|
||||
}
|
||||
|
||||
virtual void set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter)
|
||||
{
|
||||
formatter_ = std::move(sink_formatter);
|
||||
}
|
||||
Mutex mutex_;
|
||||
virtual void set_pattern_(const std::string &pattern);
|
||||
virtual void set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter);
|
||||
};
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -1,43 +1,29 @@
|
||||
//
|
||||
// Copyright(c) 2015-2018 Gabi Melman.
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "spdlog/details/file_helper.h"
|
||||
#include "spdlog/details/null_mutex.h"
|
||||
#include "spdlog/sinks/base_sink.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include "../details/file_helper.h"
|
||||
#include "../details/null_mutex.h"
|
||||
#include "./base_sink.h"
|
||||
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
/*
|
||||
* Trivial file sink with single file as target
|
||||
*/
|
||||
template<typename Mutex>
|
||||
class basic_file_sink final : public base_sink<Mutex>
|
||||
{
|
||||
template <typename Mutex>
|
||||
class basic_file_sink final : public base_sink<Mutex> {
|
||||
public:
|
||||
explicit basic_file_sink(const filename_t &filename, bool truncate = false)
|
||||
{
|
||||
file_helper_.open(filename, truncate);
|
||||
}
|
||||
explicit basic_file_sink(const filename_t &filename, bool truncate = false, const file_event_handlers &event_handlers = {});
|
||||
const filename_t &filename() const;
|
||||
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override
|
||||
{
|
||||
fmt::memory_buffer formatted;
|
||||
sink::formatter_->format(msg, formatted);
|
||||
file_helper_.write(formatted);
|
||||
}
|
||||
|
||||
void flush_() override
|
||||
{
|
||||
file_helper_.flush();
|
||||
}
|
||||
void sink_it_(const details::log_msg &msg) override;
|
||||
void flush_() override;
|
||||
|
||||
private:
|
||||
details::file_helper file_helper_;
|
||||
@@ -46,21 +32,5 @@ private:
|
||||
using basic_file_sink_mt = basic_file_sink<std::mutex>;
|
||||
using basic_file_sink_st = basic_file_sink<details::null_mutex>;
|
||||
|
||||
} // namespace sinks
|
||||
|
||||
//
|
||||
// factory functions
|
||||
//
|
||||
template<typename Factory = default_factory>
|
||||
inline std::shared_ptr<logger> basic_logger_mt(const std::string &logger_name, const filename_t &filename, bool truncate = false)
|
||||
{
|
||||
return Factory::template create<sinks::basic_file_sink_mt>(logger_name, filename, truncate);
|
||||
}
|
||||
|
||||
template<typename Factory = default_factory>
|
||||
inline std::shared_ptr<logger> basic_logger_st(const std::string &logger_name, const filename_t &filename, bool truncate = false)
|
||||
{
|
||||
return Factory::template create<sinks::basic_file_sink_st>(logger_name, filename, truncate);
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user