SpringBootã§ã®ãµã¼ãã¼ã¢ããªã±ã¼ã·ã§ã³ã¯ããã³ã³ããéç¨ãå½ããåã§ãã³ã³ããéç¨ãå½ããåã£ã¦ãã¨ã¯ãã°ãçãã°ãã¡ã¤ã«ãè¦ãããããªãã©ããã«éãããããã®ãè¦ãã®ãå½ããåã§ãè¤æ°ã®ãµã¼ãã¼ã§éç¨ããããã°ãéç´ãã¦ã¿ãå ´åã¯ä½ããã横æçã«ãã°ãæ¤ç´¢ããé ç®ãããã®ãå½ããåã§ãéç´ã·ã¹ãã ã¨ãæããã ãããã°ããã¼ã¹ã§ããã®ãå½ããåã§ã
ããããªäºæ ã«å¾æ¼ãããã¦ãç¾ä»£ã®ãµã¼ãã¼ã¢ããªã±ã¼ã·ã§ã³ã¯æ§é åãã°ãåºãã®ãå½ããåã§ãã SpringBootã§æ§é åãã°ãåºåããå ´åãç¾æ®µéã§ã¯ECS LoggingãLogstash Logback Encoderãªã©ã使ç¨ããã®ãä¸è¬çã§ãããã
ECS Loggingã¨ãã®è©±
ãECS Loggingãã¨è¨ãã¨ã³ã³ããéç¨ã®è©±ãããã¾ã£ã¦ãAmazon ECSã®ãã°ã®ãã¨ï¼ãã¨ãªãããã¡AWSãããªãããªããã¨ããAmazon ECS使ã£ã¦ããã©AWSä¾åãããããªããªããã¨ãã®åå¿ããã°ãã°ããã¾ããããã®ECSã¯ElasticCommonSchemaã§ãElasticsearchæèã§ãã
ECS Loggingã¯Elasticsearchã使ç¨ããå ´åã«ã¯ãã¡ãã使ãã¾ãããå¥ã«Elasticsearchã使ããªãã¦ãï¼ãã¨ãã°Amazon CloudWatch LogsãDatadogãªã©ï¼ãJSONã®æ§é åãã°ããã¼ã¹ã§ãããã®ã§ããã°ä½¿ãã¾ãã
Logstash Logback Encoderãä¼¼ããããªãããååã®éãLogbackç¨ãªã®ã§ãLog4j2ã¨ãã使ããªããã£ããã®ãæ¢ãããããæãã§ãã
ã§ããããã¯SpringBootã®å¤ã®ã©ã¤ãã©ãªã§ãããç¬èªã«ä¾åã追å ããå¿ è¦ãããã¾ãã ã¾ããSpringBootã®ä¾å管ç対象å¤ã®ããããã¼ã¸ã§ã³ãèªèº«ã§é¢åãè¦ãå¿ è¦ãããã¾ãã å°å³ã«é¢åèãã§ãããå¿ è¦ãªã®ã§ä»æ¹ãªãé¢åãè¦ã¦ãã¾ããããã°ãã°å¿ããããã¡ã§ãããã¾ãã
SpringBoot3.4ãã追å ã©ã¤ãã©ãªãªãã§æ§é åãã°ãåºåã§ããããã«ãªã
æ¬é¡ãåé ã®ãã¹ãã®éããSpringBoot3.4.0ã§SpringBootèªèº«ãæ§é åãã°ããµãã¼ãããããã§ãã詳ããã¯ä»¥ä¸ã®Springã®ããã°ãè¦ã¦ãã ããã
ããã§ã¯ logging.structured.format.console=ecs
ãæ¸ãã¦ãã¾ãã logging.structured.format.console=logstash
ãOKã§ããããã°ã®éãECSã¨Logstashãã¤ã¾ã ecs
㨠logstash
ã®äºå¤ããµãã¼ãããã¦ããããã§ãã
ãã¤ã«ã¹ãã¼ã³ãªãªã¼ã¹ã®ä½¿ãæ¹
GradleãMavenã§Springã®ãã¤ã«ã¹ãã¼ã³ãªãªã¼ã¹ã使ç¨ããå ´åãï¼ããããæ®æ®µä½¿ç¨ãã¦ããã§ãããï¼MavenCentralRepositoryã«ã¯ãªãã®ã§ãã¤ã«ã¹ãã¼ã³ãªãã¸ããªã®åç §ã追å ãã¦ããå¿ è¦ãããã¾ãã
Springã®ãã¤ã«ã¹ãã¼ã³ãªãã¸ããªã¯ https://repo.spring.io/milestone
ã§ãã
ï¼Springã®å
¬å¼ããã¥ã¡ã³ãã«ãæ¸ãã¦ããã ãã©ãæ¢ãã®é¢åã ã£ãã®ã§å²æï¼
Gradleã§ã¯build.gradle.kts
ã® repositories
ã«è¿½å ããã°OK
repositories {
mavenCentral()
maven {
url = uri("https://repo.spring.io/milestone")
}
}
ã©ãã§ããããã©IntelliJããã®è£å®ããããåè£ã«ã ãã¦ããã¦ããã£ã±ã¿ããªè¿½å ããã®Springãªãã ãªãã£ã¦ãªãã¾ããã
ã§ãããã ãã ã¨åããªãã
ãªããªãSpringBootãã©ã°ã¤ã³ã使ã£ã¦ãã®ã§ããã©ã°ã¤ã³ã®ä½¿ããªãã¸ããªã追å ãã¦ããå¿
è¦ãããã
ãã£ã¡ã¯ build.gradle.kts
ãããåã«è§£æ±ºãããªãããªã®ã§ settings.gradle
ã«æ¸ãã¾ãã
pluginManagement {
repositories {
gradlePluginPortal()
maven {
url = uri("https://repo.spring.io/milestone")
}
}
}
SpringBootGradlePluginã®ãã¼ã¸ã§ã³ã 3.4.0-M2
ã«ããã
plugins { java id("org.springframework.boot") version "3.4.0-M2" }
ããã§OKã ã¡ããã¨æå³ãããã¼ã¸ã§ã³ä½¿ããã¦ããã¯ç¢ºèªãã¨ãã¼ãã
ãã¨ã¯ logging.structured.format.console
ããããã£ããã£ããã gradle dependencies
ã§ä¾åã©ã¤ãã©ãªè¦ãããå®è£
ã³ã¼ã追ã£ã¦è¦ãããããã°åç
§ããªããLogWriterã«ã¹ã¿ãã¤ãºããããããã¨ããã
SpringBoot3.4以éã®å¯¾å¿
稼åä¸ã®ã¢ããªã±ã¼ã·ã§ã³ã®å ´åãç¾å¨ä½¿ç¨ãã¦ããæ§é åãã°ããããªãã¤ãããªããªãããã§ããªãã®ã§ãç¾å¨ä½¿ç¨ãã¦ãããã®ããããªãå¥æ®µæ ã¦ãå¿ è¦ã¯ããã¾ããã æ§é åãã°ã®é ç®è¿½å ãªã©ã«ã¹ã¿ãã¤ãºãã¦ããå ´åã¯å¯¾å¿å 容ãå¤ããã§ãããã ãã°åºåå¨ãã¯æ§è½ãªã©ã®å ¼ãåããããã¾ããåãã¦ãããªãç§ãªãç¹ã«æ ã¦ã¾ãããä½ãæ©ä¼ãããã°ã¡ãã£ã¨è¦ã¦ã¿ããã¼ãããã®æ¸©åº¦æã§å¯¾å¿ããã¨æãã¾ãã
ä¸æ¹ãæ°è¦ã§ããã°ãECS LoggingãLogstash Logback Encoderãªã©ãæ¤è¨ãããã®åã«ãSpringBootæ¨æºæ©è½ã®ããã§ååã ã£ããããªãããªï¼ããæ¤è¨ããã¨æãã¾ãã æ°è¦ã§ãªãã¦ããã°ã®ã«ã¹ã¿ãã¤ãºãªã©æãå ¥ãã¦ããªãã¦åã«æ§é åã ãããã£ã¦ãããã¾ã æ§é åãã°ã«ã§ãã¦ããªãããªã©ã®æ®µéã§ããã°ãã¨ããããããããã£æå¹ã«ãã¦ã¿ãã¨ããããã ã¨æãã¾ãã ãã ããã®ãªãä¾åã©ã¤ãã©ãªç®¡çã¯ä¸ã¤ã§ãæ¸ãããã«è¶ãããã¨ã¯ãªãã§ãã
ãããªæãã