How to stop node from logging node.conf during startup

隐身守侯 提交于 2019-12-02 11:56:57

The contents of node.conf are printed at INFO level by the net.corda.node.services.config.ConfigHelper class. To prevent the contents of node.conf from being printed to the logs, you'd have to specify a custom logging configuration so that for the net.corda.node.services.config.ConfigHelper class, only messages at WARN or above should be printed to the logs.

The process for providing a custom Log4J2 logging configuration file for your node is documented here. You need to:

  • Create the custom logging file (e.g. test.xml)
  • Point your node to the custom logging file when starting the node (e.g. java -Dlog4j.configurationFile=test.xml -jar corda.jar)

Here's an example test.xml that prevents the contents of node.conf being printed to the logs:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
    <Properties>
        <Property name="log-path">logs</Property>
        <Property name="log-name">node-${hostName}</Property>
        <Property name="archive">${log-path}/archive</Property>
    </Properties>

    <Appenders>
        <Console name="Console-Appender" target="SYSTEM_OUT">
            <PatternLayout pattern="%highlight{%level{length=1} %d{HH:mm:ss} %T %c{1}.%M - %msg%n}{INFO=white,WARN=red,FATAL=bright red blink}"/>
        </Console>

        <RollingFile name="RollingFile-Appender"
                 fileName="${log-path}/${log-name}.log"
                 filePattern="${archive}/${log-name}.%d{yyyy-MM-dd}-%i.log.gz">

            <PatternLayout pattern="[%-5level] %d{ISO8601}{GMT+0} [%t] %c{1} - %msg%n"/>

            <Policies>
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="10MB"/>
            </Policies>

            <DefaultRolloverStrategy min="1" max="10">
                <Delete basePath="${archive}" maxDepth="1">
                    <IfFileName glob="${log-name}*.log.gz"/>
                    <IfLastModified age="60d">
                        <IfAny>
                            <IfAccumulatedFileSize exceeds="10 GB"/>
                        </IfAny>
                    </IfLastModified>
                </Delete>
            </DefaultRolloverStrategy>
        </RollingFile>
    </Appenders>

    <Loggers>
        <Root level="error">
            <AppenderRef ref="Console-Appender"/>
            <AppenderRef ref="RollingFile-Appender"/>
        </Root>
        <Logger name="net.corda" level="error" additivity="false">
            <AppenderRef ref="Console-Appender"/>
            <AppenderRef ref="RollingFile-Appender"/>
        </Logger>
        <Logger name="net.corda.node.services.config.ConfigHelper" level="warn" additivity="false">
            <AppenderRef ref="RollingFile-Appender"/>
        </Logger>
    </Loggers>
</Configuration>

Note the final Logger block. We specify that any messages from net.corda.node.services.config.ConfigHelper (e.g. the contents of node.conf) should only be printed if they are at level WARN or above.

@Joel is there any way to point all the nodes to one custom logging file? I.e, when executing runnodes.jar, could you pass a single logfile as a paramater, i.e:

java -jar -Dlog4j.configurationFile=/Users/username/Desktop/Prototype/config/dev/log4j2.xml runnodes.jar

This doesn't seem to work... so curious.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!