JJUG CCC 2024 Fall 2024-10-27 https://jjug.doorkeeper.jp/events/177443
JJUG CCC 2024 Fall 2024-10-27 https://jjug.doorkeeper.jp/events/177443
ã¯ããã« ãã®è¨äºã¯ Go ã¢ããã³ãã«ã¬ã³ãã¼ 2023 ã®æçµæ¥ 25 æ¥ç®ã®è¨äºã§ãã çãã log/slog 使ã£ã¦ã¾ããã便å©ãªã®ã§ãã²ä½¿ã£ã¦ãã ããã slog ã¯æ§é åãã°ãåºåããçºã®ããã±ã¼ã¸ã§ Go 1.21 ã§å°å ¥ããã¾ãããããã¾ã§ã zap ã zerolog ã¨ãã£ããµã¼ããã¼ãã£è£½ã®ãã¬ã¼ã使ãäºã§æ§é åãã°ãåºåããäºãã§ãã¾ããããæ§é åãã°ãåºåããæ©è½ã Go ã®æ¨æºã©ã¤ãã©ãªã«ãªãã¾ããã slog ã¨ã¯ é常㮠log ããã±ã¼ã¸ã¯ãæå»ã¨ã¡ãã»ã¼ã¸ã®åç´ãªåºåã«ãªãã¾ãã
ãã°ã®åºåå ´æ ãã°ã¯ãéçºè ãéç¨æ å½è ãè¦ã¤ããããç®æã«åºåãããã¨ãååã¨ãã¾ãããããã¡ã¤ã«ã«åºåããå ´åã¯ãlogãã£ã¬ã¯ããªãªã©ãä½æãã¦ãããã¨ããå§ããã¾ããåºæ¬çã«ãåºåå ã¯ä»¥ä¸ã®4ã¤ãæ³å®ããã¾ãã ã»ãã¡ã¤ã«ã«åºåãã ã³ã³ã½ã¼ã«å¤ã§èµ·åããã¢ããªã±ã¼ã·ã§ã³ã«ä½¿ç¨ãããæ¹æ³ã§ãã ã»æ¨æºåºå ã³ã³ã½ã¼ã«ããèµ·åããã¢ããªã±ã¼ã·ã§ã³ã§ä½¿ç¨ããã¾ããéä¸çµéãªã©ãåºåããããã®åºåæ¹æ³ã§ãã ã»å¤é¨ãã°ç®¡çãã¼ã«ã®ãã¡ã¤ã«ã«åºå å¤é¨ã®ãã°ç®¡çãã¼ã«ãç¨ãããã¨ãå¯è½ãªå ´åã¯ãå°ç¨ã®ãã°è¨é²å ´æã«åºåãããã¨ãæ¨å¥¨ãã¦ãã¾ãã ã»å¤é¨ã·ã¹ãã ã¸åºå éçºè ã»éç¨è ã®ä½æ¥ãã³ãã¥ãã±ã¼ã·ã§ã³ãåæ»ã«è¡ãããã«ãSlackãªã©ã®ãã£ãããã¼ã«ã«åºåããã±ã¼ã¹ãããã¾ãããã ãã稼åçã«æ³¨æããå¿ è¦ãããé度ãªãã°ã®åºåã¯æ§ããããã«ãã¾ãããã åºæ¬çã«ãå¤é¨ãã°ç®¡çã·ã¹ã
API Gateway (REST API) ã§ã¯ãéçºããã©ã·ã¥ã¼ã«å½¹ç«ã¤å®è¡ãã° (Execution Logs) ãåºåãããã¨ãã§ãã¾ãã AWS ãµãã¼ãã«åãåãããéã«ãããã®å®è¡ãã°ãããã¨ã¹ã ã¼ãºã§ãã å®è¡ãã°ã¯ãã¹ãã¼ã¸ããè¨å®ã§ãã¾ãã è¨å®å¾ãAPI Gateway ã«ãªã¯ã¨ã¹ããæããã¨ãCloudWatch Logs ã«åºåããã¾ãã ãã°ã°ã«ã¼ãåã¯ãAPI-Gateway-Execution-Logs_<API ID>/<ã¹ãã¼ã¸å> ã§ãã ãã¡ãã®å®è¡ãã°ã®å 容ã解説ãã¦ããã¾ãã ãªã¯ã¨ã¹ã/ã¬ã¹ãã³ã¹ API Gateway ã« Postman ãã以ä¸ã®ããã«ãªã¯ã¨ã¹ããæãã¾ãã ãã¹ãã©ã¡ã¼ã¿ groupId=111ãã¯ã¨ãªãã©ã¡ã¼ã¿ userId=222ãæ¬æã« name=hoge ãæå®ãã¦ãã¾ãã API Gateway ã¯ãã®ãªã¯ã¨ã¹
#翻訳 https://www.scalyr.com/blog/the-10-commandments-of-logging/ CC BY 4.0 @Brice Figureau 1.èªåã§ãã°ã®æ¸ãåºããããªã printfãã¤ãã£ããããã°ã¨ã³ããªãèªåã§ãã¡ã¤ã«ã«æ¸ãåºãããããã°ãã¼ãã·ã§ã³ãèªåã§ãã£ãããã¦ã¯ãããªããéç¨æ å½è ã«ãé¡ããã¦ãæ¨æºã©ã¤ãã©ãªãã·ã¹ãã APIã³ã¼ã«ã使ãããã«ããããããããã°ãå®è¡ä¸ã®ã¢ããªã±ã¼ã·ã§ã³ãä»ã®ã·ã¹ãã ã³ã³ãã¼ãã³ãã¨é©åã«é£æºãã¦ãç¹å¥ãªã·ã¹ãã è¨å®ãªãã«é©åãªå ´æã¾ãã¯ãããã¯ã¼ã¯ãµã¼ãã¹ã«ãã°ãè¨é²ã§ããããã«ãªãã ãã®ã³ã°ã©ã¤ãã©ãªã使ããããã°ãç¹ã«Javaã®ä¸çã«ã¯Log4j, JCL, slf4j, logbackãªã©å¤ãã®ãã®ãåå¨ãããç§ã¯slf4jã¨logbackãçµã¿åããã¦ä½¿ãã®ã好ãã ãã¨ã¦ããã¯ãã«ã§ãè¨
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}