Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ecs-logging-javaつかってみた

shibadog
December 18, 2020

 ecs-logging-javaつかってみた

ecs-logging-javaつかってみた
第39回Elasticsearch勉強会 2020.12.17
#elasticsearchjp

shibadog

December 18, 2020
Tweet

More Decks by shibadog

Other Decks in Technology

Transcript

  1. ecs-loggin-javaいいところ • 依存追加とlogライブラリのLayoutを変更するだけ。 • ソースは変えずに、出力内容がイイ感じにJSONになる。 ◦ なのでgrokはjsonでやればOK • log4j2を使えば、オブジェクトをそのままlog.infoに渡すことも簡単 ◦

    メッセージ内容をJsonにしておけば勝手に構造化 • StackTraceをイイ感じに統一して構造化 {"@timestamp":"2019-08-06T12:09:12.375Z", "log.level": "INFO", "message":"Tomcat started on port(s): 8080 (http) with context path ''", "service.name":"spring-petclinic","process.thread.name":"restartedMain","log.logger":"org.springframework.boot.web.embedded.tomcat.TomcatWebServer"} {"@timestamp":"2019-08-06T12:09:12.379Z", "log.level": "INFO", "message":"Started PetClinicApplication in 7.095 seconds (JVM running for 9.082)", "service.name":"spring-petclinic","process.thread.name":"restartedMain","log.logger":"org.springframework.samples.petclinic.PetClinicApplication"} {"@timestamp":"2019-08-06T14:08:40.199Z", "log.level":"DEBUG", "message":"init find form", "service.name":"spring-petclinic","process.thread.name":"http-nio-8080-exec-8","log.logger":"org.springframework.samples.petclinic.owner.OwnerController","transaction .id":"28b7fb8d5aba51f1","trace.id":"2869b25b5469590610fea49ac04af7da"} @shiba_dog
  2. ecs-loggin-javaいいところ • 依存追加とlogライブラリのLayoutを変更するだけ。 • ソースは変えずに、出力内容がイイ感じにJSONになる。 ◦ なのでgrokはjsonでやればOK • log4j2を使えば、オブジェクトをそのままlog.infoに渡すことも簡単 ◦

    メッセージ内容をJsonにしておけば勝手に構造化 • StackTraceをイイ感じに統一して構造化 {"@timestamp":"2019-09-17T13:16:48.038Z", "log.level":"ERROR", "message":"Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: Expected: controller used to showcase what happens when an exception is thrown] with root cause", "process.thread.name":"http-nio-8080-exec-1","log.logger":"org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet]","log.origin":{"file.name":" DirectJDKLog.java","function":"log","file.line":175},"error.type":"java.lang.RuntimeException","error.message":"Expected: controller used to showcase what happens when an exception is thrown","error.stack_trace":[ "java.lang.RuntimeException: Expected: controller used to showcase what happens when an exception is thrown", "\tat org.springframework.samples.petclinic.system.CrashController.triggerException(CrashController.java:33)", "\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)", "\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)", "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)", "\tat java.lang.reflect.Method.invoke(Method.java:498)", "\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)", "\tat java.lang.Thread.run(Thread.java:748)"]} @shiba_dog