develop

Cloud Native Spring Log4j Logging

레이니블루 2024. 3. 3. 13:18

Cloud Native에서 Bible처럼 이야기되는 12 Factor App은 훌륭한 가이드이긴 한데, 실제 서비스를 개발 할 때에 전부를 지키지는 않고 있습니다. 그 중에서 거의 지키는 경우를 못 본 것으로 Log를 File로 남기지 말고 Event Stream으로 간주해서 Console Output으로 보내라는 부분입니다.

 

Spring으로 개발 할 때에 왜 저런 것을 지키지 않는지, 특히 Logging을 처리하는 Log4j에서는 어떻게 이야기하는지를 확인 해 보았습니다.

 

ref: Log4j – Using Log4j in Cloud Enabled Applications (apache.org)

 

Log4j – Using Log4j in Cloud Enabled Applications

<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apa

logging.apache.org

 

결론적으로 spring, 특히 java의 예외처럼 multi line logging을 하는 경우 file보다 성능이 떨어집니다.

    Benchmark                  Mode  Cnt       Score       Error  Units
    OutputBenchmark.console   thrpt   20   39291.885 ±  3370.066  ops/s
    OutputBenchmark.file      thrpt   20  654584.309 ± 59399.092  ops/s
    OutputBenchmark.redirect  thrpt   20   70284.576 ±  7452.167  ops/s

 

Logging to a File

While this is not the recommended 12-Factor approach, it performs very well. However, it requires that the application declares a volume where the log files will reside and then configures the log forwarder to tail those files. Care must also be taken to automatically manage the disk space used for the logs, which Log4j can perform via the “Delete” action on the RollingFileAppender.

 

현재 개발중인 서비스에서 여러 개발자들과 DevOps에서 고민해서 선택한 방법은 위에서 설명 한 것처럼 Logging to a File 입니다. Kubernetes에서 Spring Applicaiton은 Log4j에서 RollingFileAppender로 File로 남기고, 동일한 Helm Chart로 Fluentbit pod가 같이 배포되어서 Log를 Splunk로 전송하고 있습니다.

 

혹시 MemoryMappedFileAppender 같은 새로운 방식을 권정할까 했는데, 현실적으로 성능 문제를 해결 할 수는 없네요.