{"id":2510,"date":"2024-08-10T10:48:53","date_gmt":"2024-08-10T02:48:53","guid":{"rendered":"https:\/\/saludpcb.com\/zh\/?p=2510"},"modified":"2024-08-10T11:03:31","modified_gmt":"2024-08-10T03:03:31","slug":"https-saludpcb-com-esp32-tutorial-esp_logx","status":"publish","type":"post","link":"https:\/\/saludpcb.com\/zh\/https-saludpcb-com-esp32-tutorial-esp_logx\/","title":{"rendered":"ESP32 \u5165\u9580\u5230\u7cbe\u901a &#8211; ESP_LOGx"},"content":{"rendered":"\n<hr class=\"wp-block-separator alignwide has-text-color has-palette-color-1-color has-alpha-channel-opacity has-palette-color-1-background-color has-background is-style-wide\"\/>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>\u5167\u5bb9<\/h2><nav><ul><li class=\"\"><a href=\"#\u7c21\u4ecb\">\u7c21\u4ecb<\/a><\/li><li class=\"\"><a href=\"#esp-lo-gx-\u5404\u7a2e\u7d1a\u5225\">ESP_LOGx \u5404\u7a2e\u7d1a\u5225<\/a><\/li><li class=\"\"><a href=\"#\u5982\u4f55\u4f7f\u7528-esp-lo-gx\">\u5982\u4f55\u4f7f\u7528 ESP_LOGx<\/a><\/li><li class=\"\"><a href=\"#\u914d\u7f6e-esp-lo-gx-\u7d1a\u5225\">\u914d\u7f6e ESP_LOGx \u7d1a\u5225<\/a><\/li><li class=\"\"><a href=\"#\u5b89\u88dd-vs-code-\u548c-esp-idf-vs-code-\u64f4\u5c55\">\u5b89\u88dd VSCode \u548c ESP-IDF VSCode \u64f4\u5c55<\/a><\/li><li class=\"\"><a href=\"#\u65b0\u5efa-esp-32-\u5c08\u6848\">\u65b0\u5efa ESP32 \u5c08\u6848<\/a><\/li><li class=\"\"><a href=\"#esp-lo-gx-\u7bc4\u4f8b\">ESP_LOGx \u7bc4\u4f8b<\/a><\/li><li class=\"\"><a href=\"#\u7de8\u8b6f\u548c\u71d2\u9304\">\u7de8\u8b6f\u548c\u71d2\u9304<\/a><\/li><li class=\"\"><a href=\"#\u67e5\u770b\u7d50\u679c\">\u67e5\u770b\u7d50\u679c<\/a><\/li><li class=\"\"><a href=\"#\u7d50\u8ad6\">\u7d50\u8ad6<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u7c21\u4ecb\">\u7c21\u4ecb<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-top is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:0px\"><\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center has-medium-font-size is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">\u5728 ESP32 \u7684 ESP-IDF \u4e2d\uff0cesp_logx \u662f\u4e00\u500b\u7528\u65bc\u8a18\u9304 LOG \u4fe1\u606f\u7684\u51fd\u6578\u3002<a href=\"https:\/\/docs.espressif.com\/projects\/esp-idf\/en\/latest\/esp32\/api-reference\/system\/log.html\" target=\"_blank\" rel=\"noopener\">ESP_LOGx<\/a> \u51fd\u6578\u662f\u4e00\u500b\u5de8\u96c6\uff0c\u7528\u4f86\u7c21\u5316 LOG \u8a18\u9304\u7684\u8abf\u8a66\uff0c\u63d0\u4f9b\u4e0d\u540c\u7d1a\u5225\u7684 LOG \u8f38\u51fa\u3002<\/pre>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"esp-lo-gx-\u5404\u7a2e\u7d1a\u5225\">ESP_LOGx \u5404\u7a2e\u7d1a\u5225<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-top is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:0px\"><\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center has-medium-font-size is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">ESP_LOGE : \u8a18\u9304\u932f\u8aa4\u4fe1\u606f\uff0c\u901a\u5e38\u8868\u793a\u7a0b\u5e8f\u9047\u5230\u4e86\u4e00\u4e9b\u9700\u8981\u7acb\u5373\u8655\u7406\u7684\u554f\u984c\u3002<br>ESP_LOGW : \u8a18\u9304\u8b66\u544a\u4fe1\u606f\uff0c\u8868\u793a\u7a0b\u5e8f\u53ef\u80fd\u5b58\u5728\u6f5b\u5728\u554f\u984c\uff0c\u4f46\u4e0d\u6703\u7acb\u5373\u5f71\u97ff\u529f\u80fd\u3002<br>ESP_LOGI : \u8a18\u9304\u666e\u901a\u7684\u4fe1\u606f\uff0c\u8868\u793a\u7a0b\u5e8f\u7684\u6b63\u5e38\u904b\u884c\u72c0\u6cc1\u6216\u72c0\u614b\u4fe1\u606f\u3002<br>ESP_LOGG : \u8a18\u9304\u8abf\u8a66\u4fe1\u606f\uff0c\u901a\u5e38\u7528\u65bc\u958b\u767c\u968e\u6bb5\uff0c\u5305\u542b\u66f4\u8a73\u7d30\u7684\u904b\u884c\u7d30\u7bc0\u3002<br>ESP_LOGE : \u8a18\u9304\u975e\u5e38\u8a73\u7d30\u7684\u8abf\u8a66\u4fe1\u606f\uff0c\u901a\u5e38\u7528\u65bc\u6700\u7d30\u7c92\u5ea6\u7684\u8abf\u8a66\u3002<\/pre>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5982\u4f55\u4f7f\u7528-esp-lo-gx\">\u5982\u4f55\u4f7f\u7528 ESP_LOGx<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-top is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:0px\"><\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center has-medium-font-size is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">ESP_LOGx \u662f\u4e00\u500b\u5de8\u96c6\uff0c\u5be6\u969b\u4e0a\u662f\u57fa\u65bc\u4e0d\u540c\u7684 LOG \u7d1a\u5225\u4f86\u547c\u53eb\u4e0d\u540c\u7684\u51fd\u6578\u3002\u5176\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b...<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">ESP_LOGx(level, tag, format, ...)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">level\uff1a LOG \u7d1a\u5225\uff0c\u4f8b\u5982 ESP_LOG_INFO\u3002<br>tag\uff1a\u7528\u65bc\u6a19\u8b58 LOG \u4f86\u6e90\u7684\u6a19\u7c64\u3002<br>format\uff1a\u683c\u5f0f\u5b57\u7b26\u4e32\uff0c\u985e\u4f3c\u65bc printf \u7684\u683c\u5f0f\u3002<br>...\uff1a\u683c\u5f0f\u5b57\u7b26\u4e32\u4e2d\u7684\u8b8a\u91cf\u90e8\u5206\u3002<\/pre>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u914d\u7f6e-esp-lo-gx-\u7d1a\u5225\">\u914d\u7f6e ESP_LOGx \u7d1a\u5225<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-top is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:0px\"><\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center has-medium-font-size is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-preformatted\"><a href=\"https:\/\/docs.espressif.com\/projects\/esp-idf\/en\/latest\/esp32\/api-reference\/system\/log.html\" target=\"_blank\" rel=\"noopener\">\u975c\u614b\u914d\u7f6e<\/a><br><br>\u5728 sdkconfig \u6587\u4ef6\u4e2d\uff0c\u4f60\u53ef\u4ee5\u8a2d\u7f6e\u5168\u5c40 LOG \u7d1a\u5225\u3002\u4f8b\u5982...<br><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">CONFIG_LOG_DEFAULT_LEVEL_INFO=y<\/code><\/pre>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-top is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:0px\"><\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center has-medium-font-size is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">\u52d5\u614b\u914d\u7f6e<br><br>\u5728\u7a0b\u5f0f\u4e2d\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528 esp_log_level_set \u51fd\u6578\u4f86\u52d5\u614b\u8a2d\u7f6e\u7684 LOG \u7d1a\u5225\uff0c\u4f8b\u5982...<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE\n#include \"esp_log.h\"\n\n\/\/ Define the log tag for this component\nstatic const char *TAG = \"MY_TAG\";\n\nvoid app_main() {\n    \/\/ Set the global log level to INFO\n    esp_log_level_set(\"*\", ESP_LOG_INFO);\n\n    \/\/ This DEBUG message will not be shown because global level is INFO\n    ESP_LOGD(TAG, \"This DEBUG message will not be shown.\");\n\n    \/\/ This INFO message will be shown\n    ESP_LOGI(TAG, \"This INFO message will be shown.\");\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">\u6ce8\u610f<br><br><a href=\"https:\/\/docs.espressif.com\/projects\/esp-idf\/en\/latest\/esp32\/api-reference\/system\/log.html\" target=\"_blank\" rel=\"noopener\">esp_log_level_set()<\/a> \u662f\u7121\u6cd5\u5c07 LOG \u7b49\u7d1a\u8a2d\u5b9a\u9ad8\u65bc CONFIG_LOG_MAXIMUM_LEVEL \u8a2d\u5b9a\u7684\u7b49\u7d1a\u3002\u5982\u9700\u5728\u7de8\u8b6f\u6642\u5c07\u7279\u5b9a\u6a94\u6848\u7684 LOG \u7b49\u7d1a\u63d0\u9ad8\u5230\u6b64\u6700\u9ad8\u7b49\u7d1a\u4ee5\u4e0a\uff0c\u53ef\u4f7f\u7528 LOG_LOCAL_LEVEL \u5de8\u96c6\u3002<\/pre>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5b89\u88dd-vs-code-\u548c-esp-idf-vs-code-\u64f4\u5c55\">\u5b89\u88dd VSCode \u548c ESP-IDF VSCode \u64f4\u5c55<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-top is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:0px\"><\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center has-medium-font-size is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">\u78ba\u4fdd\u4f60\u5df2\u7d93\u5b89\u88dd\u548c\u914d\u7f6e\u597d\u4e86 ESP-IDF \u958b\u767c\u74b0\u5883\u3002\u60a8\u4e5f\u53ef\u4ee5\u53c3\u8003 <a href=\"https:\/\/saludpcb.com\/zh\/esp32-tutorial-esp-idf-with-vscode\/\">ESP32 \u5165\u9580\u5230\u7cbe\u901a \u2013 \u5728 VSCode \u5b89\u88dd ESP-IDF \u63d2\u4ef6<\/a> \u9019\u7bc7\u6587\u7ae0\u3002<\/pre>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u65b0\u5efa-esp-32-\u5c08\u6848\">\u65b0\u5efa ESP32 \u5c08\u6848<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-top is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:0px\"><\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center has-medium-font-size is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">\u5229\u7528\u5728 VSCode \u7684 IDF \u63d2\u4ef6\u4f86\u65b0\u5efa\u4e00\u500b ESP32 \u5c08\u6848\u53ef\u53c3\u8003 <a href=\"https:\/\/saludpcb.com\/zh\/esp32-tutorial-how-to-create-an-esp32-project-with-vscode\/\">ESP32 \u5165\u9580\u5230\u7cbe\u901a \u2013 \u5982\u4f55\u7528 VSCode \u5275\u5efa ESP32 \u5c08\u6848<\/a>\u3002<\/pre>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"esp-lo-gx-\u7bc4\u4f8b\">ESP_LOGx \u7bc4\u4f8b<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-top is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:0px\"><\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center has-medium-font-size is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">#include \"esp_log.h\"\n\nstatic const char *TAG = \"APP_TAG\";\n\nvoid app_main() {\n    ESP_LOGE(TAG, \"This is an error message: %s\", \"Something went wrong\");\n    ESP_LOGW(TAG, \"This is a warning message\");\n    ESP_LOGI(TAG, \"This is an info message\");\n    ESP_LOGD(TAG, \"This is a debug message with value: %d\", 100);\n    ESP_LOGV(TAG, \"This is a verbose message with string: %s\", \"Verbose info\");\n}<\/code><\/pre>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u7de8\u8b6f\u548c\u71d2\u9304\">\u7de8\u8b6f\u548c\u71d2\u9304<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-top is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:0px\"><\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center has-medium-font-size is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">\u5728 VSCode \u4e2d\u627e\u5230 \"ESP32-IDF : Build, Flash and Monitor\" ICON \u57f7\u884c\u548c\u71d2\u9304\u3002<\/pre>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u67e5\u770b\u7d50\u679c\">\u67e5\u770b\u7d50\u679c<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-top is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:0px\"><\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center has-medium-font-size is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">\u6211\u5011\u53ef\u4ee5\u67e5\u770b\u5728\u7d42\u7aef\u6a5f\u7684\u5217\u5370\u7d50\u679c\uff0c\u5982\u4e0b...<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">I (1000) APP_TAG: This is an info message\nD (1001) APP_TAG: This is a debug message with value: 100\nV (1002) APP_TAG: This is a verbose message with string: Verbose info\nE (1003) APP_TAG: This is an error message: Something went wrong\nW (1004) APP_TAG: This is a warning message<\/code><\/pre>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u7d50\u8ad6\">\u7d50\u8ad6<\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-top is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:0px\"><\/div>\n\n\n\n<div class=\"wp-block-column is-vertically-aligned-center has-medium-font-size is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">ESP_LOGx \u63d0\u4f9b\u4e86\u9748\u6d3b\u7684 LOG \u8a18\u9304\u529f\u80fd\uff0c\u4f7f\u4f60\u53ef\u4ee5\u6839\u64da LOG \u7d1a\u5225\u548c\u6a19\u7c64\u4f86\u63a7\u5236 LOG \u8f38\u51fa\u3002\u901a\u904e\u914d\u7f6e LOG \u7d1a\u5225\u548c\u4f7f\u7528\u4e0d\u540c\u7684 LOG \u5de8\u96c6\uff0c\u60a8\u53ef\u4ee5\u5728\u958b\u767c\u904e\u7a0b\u4e2d\u7372\u5f97\u6240\u9700\u7684\u4fe1\u606f\uff0c\u4e26\u5728\u904b\u884c\u6642\u52d5\u614b\u8abf\u6574 LOG \u8f38\u51fa\u3002<br><\/pre>\n<\/div>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator alignwide has-text-color has-palette-color-1-color has-alpha-channel-opacity has-palette-color-1-background-color has-background is-style-wide\"\/>\n","protected":false},"excerpt":{"rendered":"<p>\u7c21\u4ecb \u5728 ESP32 \u7684 ESP-IDF \u4e2d\uff0cesp_logx \u662f\u4e00\u500b\u7528\u65bc\u8a18\u9304 LOG \u4fe1\u606f\u7684\u51fd\u6578\u3002ESP_L [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2519,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,53,57],"tags":[61,27,63,20,60,10,64,11,62],"class_list":["post-2510","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-module","category-esp32","category-tutorial","tag-bluetooth","tag-c","tag-firmware","tag-hardware","tag-iot","tag-mcu","tag-module","tag-tutorial","tag-wifi"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/posts\/2510","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/comments?post=2510"}],"version-history":[{"count":10,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/posts\/2510\/revisions"}],"predecessor-version":[{"id":2523,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/posts\/2510\/revisions\/2523"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/media\/2519"}],"wp:attachment":[{"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/media?parent=2510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/categories?post=2510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/saludpcb.com\/zh\/wp-json\/wp\/v2\/tags?post=2510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}