{"id":1070,"date":"2024-02-25T22:17:49","date_gmt":"2024-02-25T13:17:49","guid":{"rendered":"https:\/\/shinke1987.net\/?p=1070"},"modified":"2024-06-06T10:33:19","modified_gmt":"2024-06-06T01:33:19","slug":"queryexception%e3%81%ae%e5%86%85%e5%ae%b9%e3%81%ae%e3%81%bf%e7%89%b9%e5%ae%9a%e3%81%ae%e3%83%ad%e3%82%b0%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%81%ab%e8%a8%98%e9%8c%b2","status":"publish","type":"post","link":"https:\/\/shinke1987.net\/?p=1070","title":{"rendered":"QueryException\u306e\u5185\u5bb9\u306e\u307f\u7279\u5b9a\u306e\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306b\u8a18\u9332"},"content":{"rendered":"\n<h2 id=\"toc0\" class=\"wp-block-heading\">\u76ee\u7684<\/h2>\n\n\n\n<p>SQL\u95a2\u9023\u306e\u30a8\u30e9\u30fc\u3060\u3051\u7279\u5b9a\u306e\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306b\u8a18\u9332\u3055\u308c\u308b\u3088\u3046\u306b\u3057\u305f\u3044\u3002<\/p>\n\n\n\n<h2 id=\"toc1\" class=\"wp-block-heading\">\u624b\u9806<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>config\/logging.php \u306e\u7de8\u96c6<\/li>\n\n\n\n<li>app\/Exceptions\/Handler.php \u306e\u7de8\u96c6\uff08Laravel10\u306e\u5834\u5408\uff09<br>bootstrap\/app.php \u306e\u7de8\u96c6\uff08Laravel11\u306e\u5834\u5408\uff09<\/li>\n\n\n\n<li>\u52d5\u4f5c\u78ba\u8a8d<\/li>\n<\/ol>\n\n\n\n<h2 id=\"toc2\" class=\"wp-block-heading\">config\/logging.php<\/h2>\n\n\n\n<p>single\u30c1\u30e3\u30f3\u30cd\u30eb\u306e\u4e0b\u306b\u3067\u3082\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&#039;sql_error&#039; =&gt; &#x5B;\n            &#039;driver&#039; =&gt; &#039;daily&#039;,\n            &#039;path&#039; =&gt; storage_path(&#039;logs\/QueryException\/sql_error.log&#039;),\n            &#039;level&#039; =&gt; &#039;error&#039;,\n            &#039;days&#039; =&gt; 365,\n            &#039;replace_placeholders&#039; =&gt; true,\n        ],\n<\/pre><\/div>\n\n\n<p>replace_placeholders\u306b\u3064\u3044\u3066\u306f\u3001\u6b21\u306e\u30da\u30fc\u30b8\u304c\u53c2\u8003\u306b\u306a\u308b\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/laravel\/laravel\/pull\/6139\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/laravel\/laravel\/pull\/6139<\/a><\/p>\n\n\n\n<h2 id=\"toc3\" class=\"wp-block-heading\">app\/Exceptions\/Handler.php\uff08Laravel10\u306e\u5834\u5408\uff09<\/h2>\n\n\n\n<p>\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\npublic function register(): void\n    {\n        $this-&gt;reportable(function (Throwable $e) {\n            \/\/\n        });\n\n        $this-&gt;reportable(function (QueryException $e) {\n            Log::channel(&#039;sql_error&#039;)-&gt;error($e-&gt;getMessage());\n            Log::channel(&#039;sql_error&#039;)-&gt;error($e-&gt;getSql());\n            Log::channel(&#039;sql_error&#039;)-&gt;error($e-&gt;getBindings());\n        });\n    }\n<\/pre><\/div>\n\n\n<h2 id=\"toc4\" class=\"wp-block-heading\">bootstrap\/app.php\uff08Laravel11\u306e\u5834\u5408\uff09<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n\nuse Illuminate\\Database\\QueryException;\nuse Illuminate\\Foundation\\Application;\nuse Illuminate\\Foundation\\Configuration\\Exceptions;\nuse Illuminate\\Foundation\\Configuration\\Middleware;\nuse Illuminate\\Support\\Facades\\Log;\n\nreturn Application::configure(basePath: dirname(__DIR__))\n    -&gt;withRouting(\n        web: __DIR__.&#039;\/..\/routes\/web.php&#039;,\n        commands: __DIR__.&#039;\/..\/routes\/console.php&#039;,\n        health: &#039;\/up&#039;,\n    )\n    -&gt;withMiddleware(function (Middleware $middleware) {\n        \/\/\n    })\n    -&gt;withExceptions(function (Exceptions $exceptions) {\n        $exceptions-&gt;report(function (QueryException $e) {\n            Log::channel(&#039;sql_error&#039;)-&gt;error($e-&gt;getMessage());\n            Log::channel(&#039;sql_error&#039;)-&gt;error($e-&gt;getSql());\n            Log::channel(&#039;sql_error&#039;)-&gt;error($e-&gt;getBindings());\n        });\n    })-&gt;create();\n<\/pre><\/div>\n\n\n<h2 id=\"toc5\" class=\"wp-block-heading\">\u52d5\u4f5c\u78ba\u8a8d<\/h2>\n\n\n\n<p>\u4f55\u3089\u304b\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3067\u3001\u6b21\u306e\u30a8\u30e9\u30fc\u304c\u51fa\u308b\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3057\u3001<br>storage\/logs\u30d5\u30a9\u30eb\u30c0\u306b\u4f5c\u6210\u3055\u308c\u308b\u300csql_error-YYYY-MM-DD.log\u300d\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u3092\u78ba\u8a8d\u3059\u308c\u3070\u826f\u3044\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nDB::table(&#039;aiueo&#039;)-&gt;get();\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u76ee\u7684 SQL\u95a2\u9023\u306e\u30a8\u30e9\u30fc\u3060\u3051\u7279\u5b9a\u306e\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306b\u8a18\u9332\u3055\u308c\u308b\u3088\u3046\u306b\u3057\u305f\u3044\u3002 \u624b\u9806 config\/logging.php single\u30c1\u30e3\u30f3\u30cd\u30eb\u306e\u4e0b\u306b\u3067\u3082\u8ffd\u52a0\u3059\u308b\u3002 replace_placeholders\u306b\u3064\u3044\u3066\u306f\u3001\u6b21\u306e\u30da [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[96],"tags":[88,81],"class_list":["post-1070","post","type-post","status-publish","format-standard","hentry","category-laravel","tag-laravel","tag-php"],"_links":{"self":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/1070","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1070"}],"version-history":[{"count":2,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/1070\/revisions"}],"predecessor-version":[{"id":1187,"href":"https:\/\/shinke1987.net\/index.php?rest_route=\/wp\/v2\/posts\/1070\/revisions\/1187"}],"wp:attachment":[{"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shinke1987.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}