From e7ce0ee62d17e0f226606e69809b5d59f568f9e3 Mon Sep 17 00:00:00 2001 From: Chris Wegrzyn Date: Fri, 7 Jun 2024 06:08:00 -0400 Subject: [PATCH] Make logging controllable for devs Fixes #144 --- package.json | 1 + pnpm-lock.yaml | 211 +++++++++++++++++++-- src/api.ts | 9 + src/characters/character-block.ts | 9 +- src/clocks/commands.ts | 5 - src/datastore.ts | 16 +- src/datastore/data-indexer.ts | 6 +- src/datastore/parsers/datasworn/oracles.ts | 25 +-- src/entity/modal.ts | 1 - src/index.ts | 2 + src/indexer/indexer.ts | 14 +- src/indexer/manager.ts | 32 ++-- src/logger.ts | 41 ++++ src/moves/action/adds-modal.ts | 2 - src/moves/action/index.ts | 13 +- src/moves/block.ts | 5 +- src/oracles/command.ts | 9 +- src/sidebar/oracles.ts | 6 +- src/tracks/commands.ts | 4 - src/utils/obsidian.ts | 6 +- src/utils/suggest.ts | 2 - src/utils/ui/prompt.ts | 2 - 22 files changed, 331 insertions(+), 90 deletions(-) create mode 100644 src/logger.ts diff --git a/package.json b/package.json index cac374e2..95b44131 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "tslib": "^2.6.2", "typescript": "^5.4.5", "typescript-eslint": "^7.10.0", + "winston": "^3.13.0", "zod": "^3.23.8" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 89dee59c..428a8f8d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -116,6 +116,9 @@ importers: typescript-eslint: specifier: ^7.10.0 version: 7.10.0(eslint@8.57.0)(typescript@5.4.5) + winston: + specifier: ^3.13.0 + version: 3.13.0 zod: specifier: ^3.23.8 version: 3.23.8 @@ -313,6 +316,13 @@ packages: '@codemirror/view@6.26.3': resolution: {integrity: sha512-gmqxkPALZjkgSxIeeweY/wGQXBfwTUaLs8h7OKtSwfbj9Ct3L11lD+u1sS7XHppxFQoMDiMDp07P9f3I2jWOHw==} + '@colors/colors@1.6.0': + resolution: {integrity: sha512-Ir+AOibqzrIsL6ajt3Rz3LskB7OiMVHqltZmspbW/TJuTVuyOMirVqAkjfY6JISiLHgyNqicAC8AyHHGzNd/dA==} + engines: {node: '>=0.1.90'} + + '@dabh/diagnostics@2.0.3': + resolution: {integrity: sha512-hrlQOIi7hAfzsMqlGSFyVucrx38O+j6wiGOf//H2ecvIEqYN4ADBSS2iLMh5UFyDunCNniUIPk/q3riFv45xRA==} + '@datasworn/core@0.0.10': resolution: {integrity: sha512-MpZHQ87haKJVJlzyo6mhHgfkLUgrwIW+Rj4Pu4k66oEchlg+vmHVTkVSF9oRBitq//eTqx5jZLesmo43Nhnq+w==} @@ -775,6 +785,9 @@ packages: '@types/tough-cookie@4.0.5': resolution: {integrity: sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA==} + '@types/triple-beam@1.3.5': + resolution: {integrity: sha512-6WaYesThRMCl19iryMYP7/x2OVgCtbIVflDGFpWnb9irXI3UjYE4AzmYuiUKY1AJstGijoY+MgUszMgRxIYTYw==} + '@types/trusted-types@2.0.7': resolution: {integrity: sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==} @@ -905,6 +918,9 @@ packages: resolution: {integrity: sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==} engines: {node: '>=8'} + async@3.2.5: + resolution: {integrity: sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg==} + asynckit@0.4.0: resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} @@ -1029,6 +1045,15 @@ packages: color-name@1.1.4: resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} + color-string@1.9.1: + resolution: {integrity: sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg==} + + color@3.2.1: + resolution: {integrity: sha512-aBl7dZI9ENN6fUGC7mWpMTPNHmWUSNan9tuWN6ahh5ZLNk9baLJOnSMlrQkHcrfFgz2/RigjUVAjdx36VcemKA==} + + colorspace@1.1.4: + resolution: {integrity: sha512-BgvKJiuVu1igBUF2kEjRCZXol6wiiGbY5ipL/oVPwm0BL9sIpMIzM8IK7vwuxIIzOXMV3Ey5w+vxhm0rR/TN8w==} + combined-stream@1.0.8: resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} engines: {node: '>= 0.8'} @@ -1061,8 +1086,8 @@ packages: resolution: {integrity: sha512-Jy/tj3ldjZJo63sVAvg6LHt2mHvl4V6AgRAmNDtLdm7faqtsx+aJG42rsyCo9JCoRVKwPFzKlIPx3DIibwSIaQ==} engines: {node: '>=12'} - debug@4.3.4: - resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} + debug@4.3.5: + resolution: {integrity: sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==} engines: {node: '>=6.0'} peerDependencies: supports-color: '*' @@ -1126,6 +1151,9 @@ packages: emoji-regex@8.0.0: resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} + enabled@2.0.0: + resolution: {integrity: sha512-AKrN98kuwOzMIdAizXGI86UFBoo26CL21UM763y1h/GMSJ4/OHU9k2YlsmBpyScFo/wbLzWQJBMCW4+IO3/+OQ==} + entities@4.5.0: resolution: {integrity: sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==} engines: {node: '>=0.12'} @@ -1253,6 +1281,9 @@ packages: fb-watchman@2.0.2: resolution: {integrity: sha512-p5161BqbuCaSnB8jIbzQHOlpgsPmK5rJVDfDKO91Axs5NC1uu3HRQm6wt9cd9/+GtQQIO53JdGXXoyDpTAsgYA==} + fecha@4.2.3: + resolution: {integrity: sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==} + file-entry-cache@6.0.1: resolution: {integrity: sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==} engines: {node: ^10.12.0 || >=12.0.0} @@ -1276,6 +1307,9 @@ packages: flatted@3.3.1: resolution: {integrity: sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==} + fn.name@1.1.0: + resolution: {integrity: sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==} + form-data@4.0.0: resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==} engines: {node: '>= 6'} @@ -1407,6 +1441,9 @@ packages: is-arrayish@0.2.1: resolution: {integrity: sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==} + is-arrayish@0.3.2: + resolution: {integrity: sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==} + is-binary-path@2.1.0: resolution: {integrity: sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==} engines: {node: '>=8'} @@ -1665,6 +1702,9 @@ packages: resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} engines: {node: '>=6'} + kuler@2.0.0: + resolution: {integrity: sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A==} + leven@3.1.0: resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} engines: {node: '>=6'} @@ -1693,6 +1733,10 @@ packages: lodash@4.17.21: resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} + logform@2.6.0: + resolution: {integrity: sha512-1ulHeNPp6k/LD8H91o7VYFBng5i1BDE7HoKxVbZiGFidS1Rj65qcywLxX+pVfAPoQJEjRdvKcusKwOupHCVOVQ==} + engines: {node: '>= 12.0.0'} + lru-cache@5.1.1: resolution: {integrity: sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==} @@ -1788,6 +1832,9 @@ packages: once@1.4.0: resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} + one-time@1.0.0: + resolution: {integrity: sha512-5DXOiRKwuSEcQ/l0kGCF6Q3jcADFv5tSmRaJck/OqkVFcOzutB134KRSfF0xDrL39MNnqxbHBbUUcjZIhTgb2g==} + onetime@5.1.2: resolution: {integrity: sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==} engines: {node: '>=6'} @@ -1900,6 +1947,10 @@ packages: react-is@18.2.0: resolution: {integrity: sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==} + readable-stream@3.6.2: + resolution: {integrity: sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==} + engines: {node: '>= 6'} + readdirp@3.6.0: resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==} engines: {node: '>=8.10.0'} @@ -1944,6 +1995,13 @@ packages: run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} + safe-buffer@5.2.1: + resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} + + safe-stable-stringify@2.4.3: + resolution: {integrity: sha512-e2bDA2WJT0wxseVd4lsDP4+3ONX6HpMXQa1ZhFQ7SU+GjvORCmShbCMltrtIDfkYhVHrOcPtj+KhmDBdPdZD1g==} + engines: {node: '>=10'} + safer-buffer@2.1.2: resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} @@ -1973,6 +2031,9 @@ packages: signal-exit@3.0.7: resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} + simple-swizzle@0.2.2: + resolution: {integrity: sha512-JA//kQgZtbuY83m+xT+tXJkmJncGMTFT+C+g2h2R9uxkYIrE2yy9sgmcLhCnw57/WSD+Eh3J97FPEDFnbXnDUg==} + sisteransi@1.0.5: resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} @@ -1993,6 +2054,9 @@ packages: sprintf-js@1.0.3: resolution: {integrity: sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==} + stack-trace@0.0.10: + resolution: {integrity: sha512-KGzahc7puUKkzyMt+IqAep+TVNbKP+k2Lmwhub39m1AsTSkaDutx56aDCo+HLDzf/D26BIHTJWNiTG1KAJiQCg==} + stack-utils@2.0.6: resolution: {integrity: sha512-XlkWvfIm6RmsWtNJx+uqtKLS8eqFbxUg0ZzLXqY0caEy9l7hruX8IpiDnjsLavoBgqCCR71TqWO8MaXYheJ3RQ==} engines: {node: '>=10'} @@ -2005,6 +2069,9 @@ packages: resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} engines: {node: '>=8'} + string_decoder@1.3.0: + resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==} + strip-ansi@6.0.1: resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==} engines: {node: '>=8'} @@ -2051,6 +2118,9 @@ packages: resolution: {integrity: sha512-cAGWPIyOHU6zlmg88jwm7VRyXnMN7iV68OGAbYDk/Mh/xC/pzVPlQtY6ngoIH/5/tciuhGfvESU8GrHrcxD56w==} engines: {node: '>=8'} + text-hex@1.0.0: + resolution: {integrity: sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg==} + text-table@0.2.0: resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==} @@ -2073,6 +2143,10 @@ packages: resolution: {integrity: sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==} engines: {node: '>=12'} + triple-beam@1.4.1: + resolution: {integrity: sha512-aZbgViZrg1QNcG+LULa7nhZpJTZSLm/mXnHXnbAbjmN5aSa0y7V+wvv6+4WaBtpISJzThKy+PIPxc1Nq1EJ9mg==} + engines: {node: '>= 14.0.0'} + ts-api-utils@1.3.0: resolution: {integrity: sha512-UQMIo7pb8WRomKR1/+MFVLTroIvDVtMX3K6OUir8ynLyzB8Jeriont2bTAtmNPa1ekAgN7YPDyf6V+ygrdU+eQ==} engines: {node: '>=16'} @@ -2140,6 +2214,9 @@ packages: url-parse@1.5.10: resolution: {integrity: sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==} + util-deprecate@1.0.2: + resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} + v8-to-istanbul@9.2.0: resolution: {integrity: sha512-/EH/sDgxU2eGxajKdwLCDmQ4FWq+kpi3uCmBGpw1xJtnAxEjlD8j8PEiGWpCIMIs3ciNAgH0d3TTJiUkYzyZjA==} engines: {node: '>=10.12.0'} @@ -2175,6 +2252,14 @@ packages: engines: {node: '>= 8'} hasBin: true + winston-transport@4.7.0: + resolution: {integrity: sha512-ajBj65K5I7denzer2IYW6+2bNIVqLGDHqDw3Ow8Ohh+vdW+rv4MZ6eiDvHoKhfJFZ2auyN8byXieDDJ96ViONg==} + engines: {node: '>= 12.0.0'} + + winston@3.13.0: + resolution: {integrity: sha512-rwidmA1w3SE4j0E5MuIufFhyJPBDG7Nu71RkZor1p2+qHvJSZ9GYDA81AyleQcZbh/+V6HjeBdfnTZJm9rSeQQ==} + engines: {node: '>= 12.0.0'} + word-wrap@1.2.5: resolution: {integrity: sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==} engines: {node: '>=0.10.0'} @@ -2264,7 +2349,7 @@ snapshots: '@babel/traverse': 7.23.7 '@babel/types': 7.23.6 convert-source-map: 2.0.0 - debug: 4.3.4 + debug: 4.3.5 gensync: 1.0.0-beta.2 json5: 2.2.3 semver: 6.3.1 @@ -2430,7 +2515,7 @@ snapshots: '@babel/helper-split-export-declaration': 7.22.6 '@babel/parser': 7.23.6 '@babel/types': 7.23.6 - debug: 4.3.4 + debug: 4.3.5 globals: 11.12.0 transitivePeerDependencies: - supports-color @@ -2475,6 +2560,14 @@ snapshots: style-mod: 4.1.2 w3c-keyname: 2.2.8 + '@colors/colors@1.6.0': {} + + '@dabh/diagnostics@2.0.3': + dependencies: + colorspace: 1.1.4 + enabled: 2.0.0 + kuler: 2.0.0 + '@datasworn/core@0.0.10': {} '@datasworn/starforged@0.0.10': @@ -2560,7 +2653,7 @@ snapshots: '@eslint/eslintrc@2.1.4': dependencies: ajv: 6.12.6 - debug: 4.3.4 + debug: 4.3.5 espree: 9.6.1 globals: 13.24.0 ignore: 5.3.1 @@ -2576,7 +2669,7 @@ snapshots: '@humanwhocodes/config-array@0.11.14': dependencies: '@humanwhocodes/object-schema': 2.0.3 - debug: 4.3.4 + debug: 4.3.5 minimatch: 3.1.2 transitivePeerDependencies: - supports-color @@ -2952,6 +3045,8 @@ snapshots: '@types/tough-cookie@4.0.5': {} + '@types/triple-beam@1.3.5': {} + '@types/trusted-types@2.0.7': {} '@types/yargs-parser@21.0.3': {} @@ -2984,7 +3079,7 @@ snapshots: '@typescript-eslint/types': 7.10.0 '@typescript-eslint/typescript-estree': 7.10.0(typescript@5.4.5) '@typescript-eslint/visitor-keys': 7.10.0 - debug: 4.3.4 + debug: 4.3.5 eslint: 8.57.0 optionalDependencies: typescript: 5.4.5 @@ -3000,7 +3095,7 @@ snapshots: dependencies: '@typescript-eslint/typescript-estree': 7.10.0(typescript@5.4.5) '@typescript-eslint/utils': 7.10.0(eslint@8.57.0)(typescript@5.4.5) - debug: 4.3.4 + debug: 4.3.5 eslint: 8.57.0 ts-api-utils: 1.3.0(typescript@5.4.5) optionalDependencies: @@ -3014,7 +3109,7 @@ snapshots: dependencies: '@typescript-eslint/types': 7.10.0 '@typescript-eslint/visitor-keys': 7.10.0 - debug: 4.3.4 + debug: 4.3.5 globby: 11.1.0 is-glob: 4.0.3 minimatch: 9.0.4 @@ -3060,7 +3155,7 @@ snapshots: agent-base@6.0.2: dependencies: - debug: 4.3.4 + debug: 4.3.5 transitivePeerDependencies: - supports-color @@ -3100,6 +3195,8 @@ snapshots: array-union@2.1.0: {} + async@3.2.5: {} + asynckit@0.4.0: {} babel-jest@29.7.0(@babel/core@7.23.7): @@ -3254,6 +3351,21 @@ snapshots: color-name@1.1.4: {} + color-string@1.9.1: + dependencies: + color-name: 1.1.4 + simple-swizzle: 0.2.2 + + color@3.2.1: + dependencies: + color-convert: 1.9.3 + color-string: 1.9.1 + + colorspace@1.1.4: + dependencies: + color: 3.2.1 + text-hex: 1.0.0 + combined-stream@1.0.8: dependencies: delayed-stream: 1.0.0 @@ -3297,7 +3409,7 @@ snapshots: whatwg-mimetype: 3.0.0 whatwg-url: 11.0.0 - debug@4.3.4: + debug@4.3.5: dependencies: ms: 2.1.2 @@ -3335,6 +3447,8 @@ snapshots: emoji-regex@8.0.0: {} + enabled@2.0.0: {} + entities@4.5.0: {} error-ex@1.3.2: @@ -3424,7 +3538,7 @@ snapshots: ajv: 6.12.6 chalk: 4.1.2 cross-spawn: 7.0.3 - debug: 4.3.4 + debug: 4.3.5 doctrine: 3.0.0 escape-string-regexp: 4.0.0 eslint-scope: 7.2.2 @@ -3520,6 +3634,8 @@ snapshots: dependencies: bser: 2.1.1 + fecha@4.2.3: {} + file-entry-cache@6.0.1: dependencies: flat-cache: 3.2.0 @@ -3546,6 +3662,8 @@ snapshots: flatted@3.3.1: {} + fn.name@1.1.0: {} + form-data@4.0.0: dependencies: asynckit: 0.4.0 @@ -3636,14 +3754,14 @@ snapshots: dependencies: '@tootallnate/once': 2.0.0 agent-base: 6.0.2 - debug: 4.3.4 + debug: 4.3.5 transitivePeerDependencies: - supports-color https-proxy-agent@5.0.1: dependencies: agent-base: 6.0.2 - debug: 4.3.4 + debug: 4.3.5 transitivePeerDependencies: - supports-color @@ -3678,6 +3796,8 @@ snapshots: is-arrayish@0.2.1: {} + is-arrayish@0.3.2: {} + is-binary-path@2.1.0: dependencies: binary-extensions: 2.3.0 @@ -3736,7 +3856,7 @@ snapshots: istanbul-lib-source-maps@4.0.1: dependencies: - debug: 4.3.4 + debug: 4.3.5 istanbul-lib-coverage: 3.2.2 source-map: 0.6.1 transitivePeerDependencies: @@ -4144,6 +4264,8 @@ snapshots: kleur@3.0.3: {} + kuler@2.0.0: {} + leven@3.1.0: {} levn@0.4.1: @@ -4169,6 +4291,15 @@ snapshots: lodash@4.17.21: {} + logform@2.6.0: + dependencies: + '@colors/colors': 1.6.0 + '@types/triple-beam': 1.3.5 + fecha: 4.2.3 + ms: 2.1.2 + safe-stable-stringify: 2.4.3 + triple-beam: 1.4.1 + lru-cache@5.1.1: dependencies: yallist: 3.1.1 @@ -4251,6 +4382,10 @@ snapshots: dependencies: wrappy: 1.0.2 + one-time@1.0.0: + dependencies: + fn.name: 1.1.0 + onetime@5.1.2: dependencies: mimic-fn: 2.1.0 @@ -4348,6 +4483,12 @@ snapshots: react-is@18.2.0: {} + readable-stream@3.6.2: + dependencies: + inherits: 2.0.4 + string_decoder: 1.3.0 + util-deprecate: 1.0.2 + readdirp@3.6.0: dependencies: picomatch: 2.3.1 @@ -4384,6 +4525,10 @@ snapshots: dependencies: queue-microtask: 1.2.3 + safe-buffer@5.2.1: {} + + safe-stable-stringify@2.4.3: {} + safer-buffer@2.1.2: {} saxes@6.0.0: @@ -4406,6 +4551,10 @@ snapshots: signal-exit@3.0.7: {} + simple-swizzle@0.2.2: + dependencies: + is-arrayish: 0.3.2 + sisteransi@1.0.5: {} slash@3.0.0: {} @@ -4421,6 +4570,8 @@ snapshots: sprintf-js@1.0.3: {} + stack-trace@0.0.10: {} + stack-utils@2.0.6: dependencies: escape-string-regexp: 2.0.0 @@ -4436,6 +4587,10 @@ snapshots: is-fullwidth-code-point: 3.0.0 strip-ansi: 6.0.1 + string_decoder@1.3.0: + dependencies: + safe-buffer: 5.2.1 + strip-ansi@6.0.1: dependencies: ansi-regex: 5.0.1 @@ -4475,6 +4630,8 @@ snapshots: glob: 7.2.3 minimatch: 3.1.2 + text-hex@1.0.0: {} + text-table@0.2.0: {} tmpl@1.0.5: {} @@ -4496,6 +4653,8 @@ snapshots: dependencies: punycode: 2.3.1 + triple-beam@1.4.1: {} + ts-api-utils@1.3.0(typescript@5.4.5): dependencies: typescript: 5.4.5 @@ -4549,6 +4708,8 @@ snapshots: querystringify: 2.2.0 requires-port: 1.0.0 + util-deprecate@1.0.2: {} + v8-to-istanbul@9.2.0: dependencies: '@jridgewell/trace-mapping': 0.3.22 @@ -4582,6 +4743,26 @@ snapshots: dependencies: isexe: 2.0.0 + winston-transport@4.7.0: + dependencies: + logform: 2.6.0 + readable-stream: 3.6.2 + triple-beam: 1.4.1 + + winston@3.13.0: + dependencies: + '@colors/colors': 1.6.0 + '@dabh/diagnostics': 2.0.3 + async: 3.2.5 + is-stream: 2.0.1 + logform: 2.6.0 + one-time: 1.0.0 + readable-stream: 3.6.2 + safe-stable-stringify: 2.4.3 + stack-trace: 0.0.10 + triple-beam: 1.4.1 + winston-transport: 4.7.0 + word-wrap@1.2.5: {} wordwrap@1.0.0: {} diff --git a/src/api.ts b/src/api.ts index c504fada..17c3fdac 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,4 +1,5 @@ import { syntaxTree } from "@codemirror/language"; +import { rootLogger, setLogLevel } from "logger"; import { App } from "obsidian"; import { ProgressIndex } from "tracks/indexer"; import { CharacterTracker } from "./character-tracker"; @@ -37,6 +38,14 @@ export class IronVaultAPI { const state = this.plugin.app.workspace.activeEditor?.editor?.cm.state; return state && syntaxTree(state); } + + get logLevel(): string { + return rootLogger.level; + } + + set logLevel(level: string) { + setLogLevel(level); + } } export const getAPI = (app?: App): IronVaultAPI | undefined => { diff --git a/src/characters/character-block.ts b/src/characters/character-block.ts index ac0c570d..f111580a 100644 --- a/src/characters/character-block.ts +++ b/src/characters/character-block.ts @@ -6,6 +6,7 @@ import Sortable from "sortablejs"; import { Asset } from "@datasworn/core/dist/Datasworn"; import IronVaultPlugin from "index"; +import { rootLogger } from "logger"; import { EventRef, MarkdownRenderChild } from "obsidian"; import { ProgressTrack, legacyTrackXpEarned } from "tracks/progress"; import { renderTrack } from "tracks/track-block"; @@ -19,6 +20,8 @@ import { addOrUpdateViaDataswornAsset } from "./assets"; import { addAssetToCharacter } from "./commands"; import { ValidatedCharacter, momentumOps } from "./lens"; +const logger = rootLogger.child({ module: "blocks" }); + export default function registerCharacterBlocks(plugin: IronVaultPlugin): void { registerBlock(); registerBlock("info", CharacterSheetSection.INFO); @@ -82,7 +85,7 @@ class CharacterRenderer extends MarkdownRenderChild { } onload() { - console.log("CharacterRenderer[%s] onload", this.sections.join(", ")); + logger.debug("CharacterRenderer[%s] onload", this.sections.join(", ")); if (this.fileWatcher) { this.plugin.characters.offref(this.fileWatcher); } @@ -103,10 +106,10 @@ class CharacterRenderer extends MarkdownRenderChild { const result = this.plugin.characters.get(this.sourcePath) ?? Left.create(new Error("character not indexed")); - console.log( + logger.silly( "CharacterRenderer[%s] render started for %o", this.sections.join(", "), - result, + result.map((ctx) => ctx.character.raw), ); if (result.isLeft()) { render( diff --git a/src/clocks/commands.ts b/src/clocks/commands.ts index 2f4e9818..067544c1 100644 --- a/src/clocks/commands.ts +++ b/src/clocks/commands.ts @@ -25,11 +25,6 @@ export async function advanceClock( view: MarkdownView, clockIndex: ClockIndex, ) { - // TODO: clearly we should have something like this checking the indexer - // if (!datastore.ready) { - // console.warn("data not ready"); - // return; - // } const [clockPath, clockInfo] = await selectClock( clockIndex, app, diff --git a/src/datastore.ts b/src/datastore.ts index 81172c4d..c2cde675 100644 --- a/src/datastore.ts +++ b/src/datastore.ts @@ -70,7 +70,7 @@ export class Datastore extends Component implements IDataContext { // oraclesFolderFile == null || // !(oraclesFolderFile instanceof TFolder) // ) { - // console.error( + // logger.error( // "oracle folders: expected '%s' to be folder", // oraclesFolderFile, // ); @@ -80,7 +80,7 @@ export class Datastore extends Component implements IDataContext { // } this._ready = true; - console.log( + console.info( "iron-vault: init complete. loaded: %d oracles, %d moves, %d assets", this.moves.size, this.oracles.size, @@ -103,7 +103,7 @@ export class Datastore extends Component implements IDataContext { } // async indexOraclesFolder(folder: TFolder): Promise { - // console.log("indexing folder %s", folder.path); + // logger.info("indexing folder %s", folder.path); // const filesToIndex = new Map( // breadthFirstTraversal( // folder, @@ -126,7 +126,7 @@ export class Datastore extends Component implements IDataContext { // ); // for (const pathToRemove of pathsToRemove) { - // console.log( + // logger.debug( // "index: previously indexed data file %s (part of %s) no longer indexable, removing...", // pathToRemove, // folder.path, @@ -135,7 +135,7 @@ export class Datastore extends Component implements IDataContext { // } // async indexOracleFile(file: TFile): Promise { - // console.log("indexing %s", file.path); + // logger.info("indexing %s", file.path); // const cache = this.app.metadataCache.getFileCache(file); // const parser = parserForFrontmatter(file, cache); // if (parser == null) { @@ -157,7 +157,7 @@ export class Datastore extends Component implements IDataContext { // } // if (!result.success) { - // console.error(`[file: ${file.path}] error parsing file`, result.error); + // logger.error(`[file: ${file.path}] error parsing file`, result.error); // return false; // } @@ -171,7 +171,7 @@ export class Datastore extends Component implements IDataContext { // ); // return true; // } catch (e) { - // console.error(`[file: ${file.path}] error indexing file`, e); + // logger.error(`[file: ${file.path}] error indexing file`, e); // return false; // } // } @@ -181,7 +181,7 @@ export class Datastore extends Component implements IDataContext { // priority: number, // format: string = "json", // ): Promise { - // console.log( + // logger.info( // "iron-vault: datastore: indexing plugin file %s (format: %s priority: %d)", // normalizedPath, // format, diff --git a/src/datastore/data-indexer.ts b/src/datastore/data-indexer.ts index e651a17a..47fe9f87 100644 --- a/src/datastore/data-indexer.ts +++ b/src/datastore/data-indexer.ts @@ -1,3 +1,7 @@ +import { rootLogger } from "logger"; + +const logger = rootLogger.child({ module: "data-indexer" }); + export enum SourceTag { RulesetId = "ruleset-id", ExpansionId = "expansion-id", @@ -319,7 +323,7 @@ export class DataIndexer> this.dataMap.set(id, entries); } } catch (err) { - console.warn( + logger.warn( "caught error while indexing path %s. removing from index...", path, ); diff --git a/src/datastore/parsers/datasworn/oracles.ts b/src/datastore/parsers/datasworn/oracles.ts index 3542ccbe..19c3b366 100644 --- a/src/datastore/parsers/datasworn/oracles.ts +++ b/src/datastore/parsers/datasworn/oracles.ts @@ -1,4 +1,5 @@ import { type Datasworn } from "@datasworn/core"; +import { rootLogger } from "logger"; import { NoSuchOracleError } from "../../../model/errors"; import { Oracle, @@ -10,6 +11,8 @@ import { import { Roll, RollResultKind, Subroll, sameRoll } from "../../../model/rolls"; import { Dice } from "../../../utils/dice"; +const logger = rootLogger.child({ module: "datasworn/oracles" }); + function asOracleRow(rawRow: Datasworn.OracleTableRow): OracleRow { return Object.freeze({ result: rawRow.text, @@ -105,16 +108,16 @@ export class DataswornOracle implements Oracle { for (const subOracle of row.oracle_rolls) { const subOracleId = subOracle.oracle ?? this.id; if (subOracleId in subrolls) { - console.warn( - "[oracles] [table: %s] already generated subrolls for %s. skipping...", + logger.warn( + "[table: %s] already generated subrolls for %s. skipping...", this.id, subOracleId, ); throw new Error("unexpected duplicate subroll"); } if (!subOracle.auto) { - console.warn( - "[oracles] [table: %s] ignoring auto=false oracle_rolls entry %s", + logger.warn( + "[table: %s] ignoring auto=false oracle_rolls entry %s", this.id, subOracle.oracle, ); @@ -124,8 +127,8 @@ export class DataswornOracle implements Oracle { if (kind == null) { kind = RollResultKind.Multi; } else { - console.warn( - "[oracles] [table: %s] table has both template and self rolls", + logger.warn( + "[table: %s] table has both template and self rolls", this.id, subOracleId, ); @@ -146,8 +149,8 @@ export class DataswornOracle implements Oracle { let iterations = 0; while (results.length < subOracle.number_of_rolls) { if (iterations++ >= 10) { - console.warn( - "[oracles] [table: %s] too many iterations for subroll %s", + logger.warn( + "[table: %s] too many iterations for subroll %s", this.id, subOracle.oracle, ); @@ -159,14 +162,14 @@ export class DataswornOracle implements Oracle { if ( results.find((otherRoll) => sameRoll(roll, otherRoll)) != null ) { - console.log("duplicate roll skipped", results, roll); + logger.warn("duplicate roll skipped", results, roll); } else { results.push(roll); } break; case "make_it_worse": - console.warn( - "[oracles] [table: %s] found `make_it_worse` in subroll %s", + logger.warn( + "[table: %s] found `make_it_worse` in subroll %s", this.id, subOracle.oracle, ); diff --git a/src/entity/modal.ts b/src/entity/modal.ts index abec7370..dfb3485e 100644 --- a/src/entity/modal.ts +++ b/src/entity/modal.ts @@ -98,7 +98,6 @@ export class EntityModal extends Modal { ]), ) as Record, }; - console.log("init results: %o", this.results); } onOpen(): void { diff --git a/src/index.ts b/src/index.ts index cffd82c8..4ef972d3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,7 @@ import registerClockBlock from "clocks/clock-block"; import { advanceClock, createClock } from "clocks/commands"; import { generateEntityCommand } from "entity/command"; import { IndexManager } from "indexer/manager"; +import { loadLogLevel } from "logger"; import { runMoveCommand } from "moves/action"; import installMoveLinkHandler from "moves/link-override"; import { MoveModal } from "moves/move-modal"; @@ -74,6 +75,7 @@ export default class IronVaultPlugin extends Plugin { } async onload(): Promise { + loadLogLevel(); await this.loadSettings(); this.datastore = this.addChild(new Datastore(this)); diff --git a/src/indexer/indexer.ts b/src/indexer/indexer.ts index 959b74ad..6a7ecaa1 100644 --- a/src/indexer/indexer.ts +++ b/src/indexer/indexer.ts @@ -1,6 +1,8 @@ import { Index } from "indexer/index-interface"; +import { rootLogger } from "logger"; import { type CachedMetadata } from "obsidian"; import { Either, Left } from "utils/either"; +import { Logger } from "winston"; import { IronVaultKind } from "../constants"; import { IndexImpl } from "./index-impl"; @@ -57,8 +59,18 @@ export abstract class BaseIndexer implements Indexer { abstract readonly id: IronVaultKind; public readonly index: Index = new IndexImpl(); + #_logger?: Logger; + constructor() {} + get #logger(): Logger { + // NOTE: this is because the id field isn't available in the constructor :grimace: + if (!this.#_logger) { + this.#_logger = rootLogger.child({ module: `indexer.${this.id}` }); + } + return this.#_logger; + } + onChanged( path: string, cache: CachedMetadata, @@ -78,7 +90,7 @@ export abstract class BaseIndexer implements Indexer { // "Won't index" is intended for a situation where this indexer decides it doesn't // apply to this file. We remove it from the index entirely. if (this.index.delete(path)) { - console.log( + this.#logger.verbose( "[indexer:%s] [file:%s] removing because no longer indexable", this.id, path, diff --git a/src/indexer/manager.ts b/src/indexer/manager.ts index 4660c519..09d99687 100644 --- a/src/indexer/manager.ts +++ b/src/indexer/manager.ts @@ -1,3 +1,4 @@ +import { rootLogger } from "logger"; import { Component, TFile, @@ -20,6 +21,8 @@ import { Indexer, IndexerId } from "./indexer"; // } // } +const logger = rootLogger.child({ module: "index-manager" }); + export class IndexManager extends Component { protected readonly metadataCache: MetadataCache; protected readonly vault: Vault; @@ -39,14 +42,13 @@ export class IndexManager extends Component { if (this.handlers.has(indexer.id)) { throw new Error(`attempt to re-register handler for ${indexer.id}`); } - console.log("[index-manager] registered indexer %s", indexer.id); + logger.verbose("registered indexer %s", indexer.id); this.handlers.set(indexer.id, indexer); } public initialize(): void { this.registerEvent( this.metadataCache.on("changed", (file, data, cache) => { - // console.log("changed: ", file); this.indexFile(file, cache); }), ); @@ -69,14 +71,14 @@ export class IndexManager extends Component { }), ); - console.log("[index-manager] starting initial index..."); + logger.verbose("Starting initial index..."); for (const file of this.vault.getMarkdownFiles()) { const cache = this.metadataCache.getFileCache(file); if (cache != null) { this.indexFile(file, cache); } else { - console.warn("no cache for ", file.path); + logger.warn("no cache for %s", file.path); } } } @@ -104,14 +106,14 @@ export class IndexManager extends Component { private unindex(fileKey: string): void { const indexer = this.currentIndexerForFile(fileKey); if (indexer != null) { - console.log( + logger.debug( "[indexer:%s] [file: %s] removing indexed file for deleted file", indexer.id, fileKey, ); const result = indexer.onDeleted(fileKey); if (result.type == "not_found") { - console.warn( + logger.warn( "[indexer:%s] [file:%s] requested file not found in index", indexer.id, fileKey, @@ -138,11 +140,7 @@ export class IndexManager extends Component { if (indexer) { return indexer; } else { - console.warn( - '[indexer] [file:%s] unknown iron-vault-kind "%s"', - file.path, - kind, - ); + logger.warn('[file:%s] unknown iron-vault-kind "%s"', file.path, kind); } } return undefined; @@ -160,8 +158,8 @@ export class IndexManager extends Component { } if (newIndexer) { - console.log( - "[index-manager] [file:%s] using indexer %s for file", + logger.debug( + "[file:%s] using indexer %s for file", indexKey, newIndexer.id, ); @@ -171,7 +169,7 @@ export class IndexManager extends Component { result = newIndexer.onChanged(file.path, cache); } catch (error) { result = "error"; - console.error( + logger.error( "[indexer:%s] [file:%s] unexpected error or result while indexing %o", newIndexer.id, indexKey, @@ -180,7 +178,7 @@ export class IndexManager extends Component { } switch (result) { case "indexed": - console.log( + logger.verbose( "[indexer:%s] [file:%s] indexed", newIndexer.id, indexKey, @@ -188,7 +186,7 @@ export class IndexManager extends Component { this.indexedFiles.set(indexKey, newIndexer.id); break; case "wont_index": - console.log( + logger.debug( "[indexer:%s] [file:%s] not indexable", newIndexer.id, indexKey, @@ -196,7 +194,7 @@ export class IndexManager extends Component { break; case "error": default: - console.error( + logger.error( "[indexer:%s] [file:%s] error while indexing", newIndexer.id, indexKey, diff --git a/src/logger.ts b/src/logger.ts new file mode 100644 index 00000000..5e9c03e0 --- /dev/null +++ b/src/logger.ts @@ -0,0 +1,41 @@ +import * as winston from "winston"; + +export const DEFAULT_LOG_LEVEL = "info"; +export const LOG_LEVEL_STORAGE_KEY = "iron-vault-log-level"; + +export const rootLogger = winston.createLogger({ + level: DEFAULT_LOG_LEVEL, + format: winston.format.json(), + exitOnError: false, + transports: [ + new winston.transports.Console({ + format: winston.format.combine( + winston.format.splat(), + winston.format.colorize(), + winston.format.printf( + ({ level, message, module }) => `${level} [${module}] ${message}`, + ), + ), + }), + ], +}); + +export function setLogLevel(level: string) { + rootLogger.level = level; + try { + localStorage.setItem(LOG_LEVEL_STORAGE_KEY, level); + } catch (e) { + // sad face + } +} + +export function loadLogLevel() { + let logLevel: string | null = null; + try { + logLevel = localStorage.getItem(LOG_LEVEL_STORAGE_KEY); + } catch (e) { + // sad face + } + + if (logLevel) rootLogger.level = logLevel; +} diff --git a/src/moves/action/adds-modal.ts b/src/moves/action/adds-modal.ts index 62605e6b..057ed666 100644 --- a/src/moves/action/adds-modal.ts +++ b/src/moves/action/adds-modal.ts @@ -156,13 +156,11 @@ export class AddsModal extends SuggestModal> { _evt: MouseEvent | KeyboardEvent, ): void { console.assert(this.resolved, "expected to already have been resolved"); - // console.log(item); this.onSelect(item.item); } onClose(): void { super.onClose(); - // console.log("closed"); if (!this.resolved) { this.onCancel(); } diff --git a/src/moves/action/index.ts b/src/moves/action/index.ts index b9cbb251..bfd68d67 100644 --- a/src/moves/action/index.ts +++ b/src/moves/action/index.ts @@ -5,6 +5,7 @@ import { determineCharacterActionContext, } from "characters/action-context"; import IronVaultPlugin from "index"; +import { rootLogger } from "logger"; import { type App, type Editor, @@ -36,6 +37,8 @@ import { checkForMomentumBurn } from "./action-modal"; import { AddsModal } from "./adds-modal"; import { renderMechanics } from "./format"; +const logger = rootLogger.child({ module: "moves" }); + enum MoveKind { Progress = "Progress", Action = "Action", @@ -233,7 +236,7 @@ export async function runMoveCommand( chosenMove?: Datasworn.Move, ): Promise { if (view.file?.path == null) { - console.error("No file for view. Why?"); + logger.error("No file for view. Why?"); return; } @@ -270,7 +273,7 @@ export async function runMoveCommand( case "special_track": default: // TODO: this probably makes sense with new mechanics format? - console.warn( + logger.warn( "Teach me how to handle a move with roll type %s: %o", move.roll_type, move, @@ -361,11 +364,7 @@ function suggestedRollablesForMove( rollableToAdd = rollable.condition_meter; break; default: - console.warn( - "unhandled rollable scenario %o %o", - condition, - rollable, - ); + logger.warn("unhandled rollable scenario %o %o", condition, rollable); } if (!rollableToAdd) continue; if (!(rollableToAdd in suggestedRollables)) { diff --git a/src/moves/block.ts b/src/moves/block.ts index 54415cd8..de21c225 100644 --- a/src/moves/block.ts +++ b/src/moves/block.ts @@ -1,5 +1,6 @@ import { type Datasworn } from "@datasworn/core"; import { Datastore } from "datastore"; +import { rootLogger } from "logger"; import { MarkdownRenderChild, MarkdownRenderer, type App } from "obsidian"; import IronVaultPlugin from "../index"; import { @@ -20,6 +21,8 @@ import { lookupOutcome, } from "./wrapper"; +const logger = rootLogger.child({ module: "moves/block" }); + export function registerMoveBlock(plugin: IronVaultPlugin): void { plugin.registerMarkdownCodeBlockProcessor("move", async (source, el, ctx) => { await plugin.datastore.waitForReady; @@ -68,7 +71,7 @@ class MoveMarkdownRenderChild extends MarkdownRenderChild { (move) => move.name === doc.name, ); if (moves.length != 1) { - console.warn( + logger.warn( "Expected only one move named %s, found %d: %o", doc.name, moves.length, diff --git a/src/oracles/command.ts b/src/oracles/command.ts index 0b6b8215..f3f8d219 100644 --- a/src/oracles/command.ts +++ b/src/oracles/command.ts @@ -1,4 +1,5 @@ import IronVaultPlugin from "index"; +import { rootLogger } from "logger"; import { createOrAppendMechanics } from "mechanics/editor"; import { createOracleNode } from "mechanics/node-builders"; import { EditorSelection, type Editor, type MarkdownView } from "obsidian"; @@ -9,6 +10,8 @@ import { CustomSuggestModal } from "../utils/suggest"; import { OracleRollerModal } from "./modal"; import { OracleRoller } from "./roller"; +const logger = rootLogger.child({ module: "oracles" }); + export function formatOraclePath(oracle: Oracle): string { let current = oracle.parent; const path = []; @@ -41,7 +44,7 @@ export async function runOracleCommand( chosenOracle?: Oracle, ): Promise { if (!plugin.datastore.ready) { - console.warn("data not ready"); + logger.warn("data not ready"); return; } @@ -53,7 +56,7 @@ export async function runOracleCommand( prompt = editor.getRange(selection.anchor, selection.head); if (!prompt && selection.anchor.line == selection.head.line) { prompt = editor.getLine(selection.anchor.line); - console.log("prompt: '%s'", prompt); + logger.debug("prompt: '%s'", prompt); // TODO: if I wanted to split the line around the cursor, this is how I can do it! // const rightMost = Math.max(selection.anchor.ch, selection.head.ch); @@ -74,7 +77,7 @@ export async function runOracleCommand( prompt = undefined; } } else { - console.error( + logger.error( "Canceling oracle: Expected exactly one selection; found %d: %o", ); return; diff --git a/src/sidebar/oracles.ts b/src/sidebar/oracles.ts index 2c6dc9de..43e483d5 100644 --- a/src/sidebar/oracles.ts +++ b/src/sidebar/oracles.ts @@ -193,14 +193,10 @@ function renderOracle(plugin: IronVaultPlugin, oracle: Oracle) { } function rollOracleBatch(plugin: IronVaultPlugin, group: CollectionGrouping) { - console.log("Rolling all these oracles:", group); let entityDefn = Object.values(ENTITIES).find( (desc) => desc.collectionId === group.id, ); - if (entityDefn) { - console.log("Found existing entity defintion", entityDefn); - } else { - console.log("No existing entity defn."); + if (!entityDefn) { entityDefn = { label: group.name, spec: Object.fromEntries( diff --git a/src/tracks/commands.ts b/src/tracks/commands.ts index c54705b2..ffe38016 100644 --- a/src/tracks/commands.ts +++ b/src/tracks/commands.ts @@ -21,10 +21,6 @@ export async function advanceProgressTrack( view: MarkdownView, progressContext: ProgressContext, ) { - // if (!datastore.ready) { - // console.warn("data not ready"); - // return; - // } const trackContext = await selectProgressTrack( progressContext, app, diff --git a/src/utils/obsidian.ts b/src/utils/obsidian.ts index d161d3d2..0cc6d473 100644 --- a/src/utils/obsidian.ts +++ b/src/utils/obsidian.ts @@ -1,3 +1,4 @@ +import { rootLogger } from "logger"; import { App, TFile, @@ -8,6 +9,8 @@ import { } from "obsidian"; import { IronVaultKind, PLUGIN_KIND_FIELD } from "../constants"; +const logger = rootLogger.child({ module: "utils" }); + export function pluginAsset(plug: Plugin, assetPath: string): string { return normalizePath( [plug.app.vault.configDir, "plugins", plug.manifest.id, assetPath].join( @@ -93,7 +96,6 @@ export async function createNewIronVaultEntityFile( ): Promise { const targetFolder = await getExistingOrNewFolder(app, targetFolderPath); - console.log("Creating in folder: %o", targetFolder); const file = await app.fileManager.createNewMarkdownFile( targetFolder, fileName, @@ -124,7 +126,7 @@ export async function createNewIronVaultEntityFile( ); } else if (templateFile) { if (enableTemplaterPlugin && !shouldSetFocus) { - console.log( + logger.warn( "Can only use templater plugin when setting focus. Falling back on ordinary template mode...", ); } diff --git a/src/utils/suggest.ts b/src/utils/suggest.ts index c4da2b10..c2f97089 100644 --- a/src/utils/suggest.ts +++ b/src/utils/suggest.ts @@ -232,13 +232,11 @@ export class CustomSuggestModal extends SuggestModal> { _evt: MouseEvent | KeyboardEvent, ): void { console.assert(this.resolved, "expected to already have been resolved"); - // console.log(item); this.onSelect(item.item); } onClose(): void { super.onClose(); - // console.log("closed"); if (!this.resolved) { this.onCancel(); } diff --git a/src/utils/ui/prompt.ts b/src/utils/ui/prompt.ts index e369f18f..ab29304d 100644 --- a/src/utils/ui/prompt.ts +++ b/src/utils/ui/prompt.ts @@ -89,13 +89,11 @@ export class PromptModal extends SuggestModal> { _evt: MouseEvent | KeyboardEvent, ): void { console.assert(this.resolved, "expected to already have been resolved"); - // console.log(item); this.onSelect(item.item); } onClose(): void { super.onClose(); - // console.log("closed"); if (!this.resolved) { this.onCancel(); }