Java -- ELK obtains logback.xml configuration information from nacos

background:

        After building ELK locally, I could upload logs normally to any project I started. However, when I deployed elk to the test environment, I found that the logs of the local project could not be uploaded normally. Before, I configured the upload address to On nacos, read nacos in logback.xml and then send the log to the specified IP.

Configuration information:

        logback.xml

<!--LogStash访问host-->
    <springProperty name="LOG_STASH_HOST" scope="context" source="logstash.host" defaultValue="127.0.0.1"/>

        nacos

logstash:
  host: 192.168.0.111

Cause Analysis:

        Previously, because elk and the project were both on the same machine, the "logstash.host" parameter of nacos was not actually read. Because there is a default "127.0.0.1" behind logback.xml, it did not affect it. Send logs normally.

        And why does logback.xml not obtain the configuration information on nacos? After checking the information, I found that files such as logback.xml and bootstrap.xml are loaded by the system by default and do not need to specify a file name. Therefore, logback.xml was loaded before nacos was loaded. After the "logstash.host" parameter could not be obtained, the default value was used, so my nacos configuration was equivalent to invalid.

solve:

        first step       

         I changed the name of bootstrap.xml to logback-nacos.xml so that the system will not automatically load this configuration file.

        Step 2

        Add the configuration file logback-nacos.xml on nacos

logging:
  config: classpath:logback-nacos.xml

        

                In this way, logback-nacos.xml will be loaded after nacos is loaded, and the "logstash.host" parameter value can be obtained normally.

result:

        Resolved smoothly

 

Acho que você gosta

Origin blog.csdn.net/DGH2430284817/article/details/130341435
Recomendado
Clasificación