Elixir Language
IO.inspect और लेबल के साथ बेहतर डिबगिंग
खोज…
परिचय
IO.inspect
बहुत उपयोगी है जब आप विधि कॉलिंग की अपनी श्रृंखला को डीबग करने का प्रयास करते हैं। यह गन्दा हो सकता है यदि आप इसका उपयोग अक्सर करते हैं।
चूंकि अमृत 1.4.0 IO.inspect
का label
विकल्प मदद कर सकता है
टिप्पणियों
केवल Elixir 1.4+ के साथ काम करता है, लेकिन मैं अभी तक उसे टैग नहीं कर सकता।
बिना लेबल के
url
|> IO.inspect
|> HTTPoison.get!
|> IO.inspect
|> Map.get(:body)
|> IO.inspect
|> Poison.decode!
|> IO.inspect
यह बिना किसी संदर्भ के बहुत सारे आउटपुट देगा:
"https://jsonplaceholder.typicode.com/posts/1"
%HTTPoison.Response{body: "{\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\",\n \"body\": \"quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto\"\n}",
headers: [{"Date", "Thu, 05 Jan 2017 14:29:59 GMT"},
{"Content-Type", "application/json; charset=utf-8"},
{"Content-Length", "292"}, {"Connection", "keep-alive"},
{"Set-Cookie",
"__cfduid=d56d1be0a544fcbdbb262fee9477600c51483626599; expires=Fri, 05-Jan-18 14:29:59 GMT; path=/; domain=.typicode.com; HttpOnly"},
{"X-Powered-By", "Express"}, {"Vary", "Origin, Accept-Encoding"},
{"Access-Control-Allow-Credentials", "true"},
{"Cache-Control", "public, max-age=14400"}, {"Pragma", "no-cache"},
{"Expires", "Thu, 05 Jan 2017 18:29:59 GMT"},
{"X-Content-Type-Options", "nosniff"},
{"Etag", "W/\"124-yv65LoT2uMHrpn06wNpAcQ\""}, {"Via", "1.1 vegur"},
{"CF-Cache-Status", "HIT"}, {"Server", "cloudflare-nginx"},
{"CF-RAY", "31c7a025e94e2d41-TXL"}], status_code: 200}
"{\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\",\n \"body\": \"quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto\"\n}"
%{"body" => "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto",
"id" => 1,
"title" => "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"userId" => 1}
लेबल के साथ
संदर्भ जोड़ने के लिए label
विकल्प का उपयोग करने से बहुत मदद मिल सकती है:
url
|> IO.inspect(label: "url")
|> HTTPoison.get!
|> IO.inspect(label: "raw http resonse")
|> Map.get(:body)
|> IO.inspect(label: "raw body")
|> Poison.decode!
|> IO.inspect(label: "parsed body")
url: "https://jsonplaceholder.typicode.com/posts/1"
raw http resonse: %HTTPoison.Response{body: "{\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\",\n \"body\": \"quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto\"\n}",
headers: [{"Date", "Thu, 05 Jan 2017 14:33:06 GMT"},
{"Content-Type", "application/json; charset=utf-8"},
{"Content-Length", "292"}, {"Connection", "keep-alive"},
{"Set-Cookie",
"__cfduid=d22d817e48828169296605d27270af7e81483626786; expires=Fri, 05-Jan-18 14:33:06 GMT; path=/; domain=.typicode.com; HttpOnly"},
{"X-Powered-By", "Express"}, {"Vary", "Origin, Accept-Encoding"},
{"Access-Control-Allow-Credentials", "true"},
{"Cache-Control", "public, max-age=14400"}, {"Pragma", "no-cache"},
{"Expires", "Thu, 05 Jan 2017 18:33:06 GMT"},
{"X-Content-Type-Options", "nosniff"},
{"Etag", "W/\"124-yv65LoT2uMHrpn06wNpAcQ\""}, {"Via", "1.1 vegur"},
{"CF-Cache-Status", "HIT"}, {"Server", "cloudflare-nginx"},
{"CF-RAY", "31c7a4b8ae042d77-TXL"}], status_code: 200}
raw body: "{\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"sunt aut facere repellat provident occaecati excepturi optio reprehenderit\",\n \"body\": \"quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto\"\n}"
parsed body: %{"body" => "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto",
"id" => 1,
"title" => "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"userId" => 1}
Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow