Last active
November 7, 2019 21:28
-
-
Save wreulicke/8d3750f3226d34603eadddec9b1703e5 to your computer and use it in GitHub Desktop.
運用を支えるためのログを出すにはどうするかのソース
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"timestamp": "2018-07-25T09:50:04.637+09:00", | |
"level": "INFO", | |
"thread": "pool-2-thread-3", | |
"requestId": "dbc64d80-163a-47b8-8b6b-da42b92c2dba", // トランザクションに紐づくID(後述) | |
"req.requestURI": "/buy", // リクエストされたURI | |
// 他にもあるけど省略 | |
"logger": "com.github.wreulicke.PaymentService", | |
"message": "決済が完了しました" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PaymentService { | |
public void purchase(Product product) { | |
// なんかいい感じの処理がある | |
log.info("決済が完了しました"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RequestIdFilter extends OncePerRequestFilter { | |
@Override | |
protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) | |
throws java.io.IOException, ServletException { | |
MDC.put("RequestId", UUID.randomUUID().toString()); | |
try { | |
chain.doFilter(request, response); | |
} finally { | |
MDC.remove("RequestId"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment