Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rollover strategy of log4j2 in nacos 1.4.x will cause unlimited log files #11132

Closed
zcz3313 opened this issue Sep 14, 2023 · 5 comments
Closed

Comments

@zcz3313
Copy link

zcz3313 commented Sep 14, 2023

Describe the bug

according to log4j2#DefaultRolloverStrategy

image

nacos strategy as follows:
image

this strategy means, the number of log files generated per day is limited, but the number of days is unlimited.
nacos client can also generate log files in every day.

Expected behavior
max days limit strategy should be added

@FeiXiangDouLi
Copy link

@i will solve it@

@FeiXiangDouLi
Copy link

FeiXiangDouLi commented Sep 22, 2023

@KomachiSion 请问一下1.4.x版本,我应该怎么提交合并申请?fork项目是2.3的版本,已经配置了删除策略了。不知道1.4.x的版本问题怎么去弄。

@FeiXiangDouLi
Copy link

<Configuration status="WARN">
    <Properties>
        <Property name="userHome" value="${sys:user.home}"/>
        <Property name="logPath" value="${sys:JM.LOG.PATH:-${userHome}}"/>
        <Property name="logRetainSize" value="${sys:JM.LOG.RETAIN.FILE.SIZE:-1GB}"/>
        <Property name="logRetainCount" value="${sys:JM.LOG.RETAIN.FILE.COUNT:-100}"/>
    </Properties>
    <Appenders>
        <RollingFile name="CONFIG_LOG_FILE" fileName="${logPath}/nacos/config.log"
            filePattern="${logPath}/nacos/config.log.%d{yyyy-MM-dd}.%i">
            <PatternLayout>
                <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n</Pattern>
            </PatternLayout>
            
            <Policies>
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="${sys:JM.LOG.FILE.SIZE:-10MB}"/>
            </Policies>
            
            <DefaultRolloverStrategy max="${sys:JM.LOG.RETAIN.COUNT:-7}">
            	<Delete basePath="${logPath}/nacos" maxDepth="1" testMode="${sys:JM.LOG.RETAIN.DURATION.OFF:-true}">
                    <IfFileName glob="config.log.*.*" />
                    <IfLastModified age="${sys:JM.LOG.RETAIN.DURATION:-P30D}" >
                        <IfAny>
                            <IfAccumulatedFileSize exceeds="${logRetainSize}" />
                            <IfAccumulatedFileCount exceeds="${logRetainCount}" />
                        </IfAny>
                    </IfLastModified>
                </Delete>
            </DefaultRolloverStrategy>
        </RollingFile>

        <Async name="ASYNC_CONFIG" bufferSize="1024" blocking="false">
            <AppenderRef ref="CONFIG_LOG_FILE"/>
        </Async>
        
        <RollingFile name="NAMING_LOG_FILE" fileName="${logPath}/nacos/naming.log"
            filePattern="${logPath}/nacos/naming.log.%d{yyyy-MM-dd}.%i">
            <PatternLayout>
                <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n</Pattern>
            </PatternLayout>
            
            <Policies>
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="${sys:JM.LOG.FILE.SIZE:-10MB}"/>
            </Policies>
            
            <DefaultRolloverStrategy max="${sys:JM.LOG.RETAIN.COUNT:-7}">
            	<Delete basePath="${logPath}/nacos" maxDepth="1" testMode="${sys:JM.LOG.RETAIN.DURATION.OFF:-true}">
                    <IfFileName glob="naming.log.*.*" />
                    <IfLastModified age="${sys:JM.LOG.RETAIN.DURATION:-P30D}" >
                        <IfAny>
                            <IfAccumulatedFileSize exceeds="${logRetainSize}" />
                            <IfAccumulatedFileCount exceeds="${logRetainCount}" />
                        </IfAny>
                    </IfLastModified>
                </Delete>
            </DefaultRolloverStrategy>
        </RollingFile>

        <Async name="ASYNC_NAMING" bufferSize="1024" blocking="false">
            <AppenderRef ref="NAMING_LOG_FILE"/>
        </Async>
    </Appenders>
    
    <Loggers>
        <Logger name="com.alibaba.nacos.client" level="${sys:com.alibaba.nacos.config.log.level:-info}"
            additivity="false">
            <AppenderRef ref="CONFIG_LOG_FILE"/>
        </Logger>
        
        <Logger name="com.alibaba.nacos.client.config" level="${sys:com.alibaba.nacos.config.log.level:-info}"
            additivity="false">
            <AppenderRef ref="CONFIG_LOG_FILE"/>
        </Logger>
        
        <Logger name="com.alibaba.nacos.client.naming" level="${sys:com.alibaba.nacos.naming.log.level:-info}"
            additivity="false">
            <AppenderRef ref="NAMING_LOG_FILE"/>
        </Logger>
        <Root level="INFO">
            <AppenderRef ref="CONFIG_LOG_FILE"/>
        </Root>
    </Loggers>
</Configuration>

这是我修改后的完整配置,新增了删除策略,默认删除30天以上的日志,但是保留最近的1GB或100个日志文件。请问这个配置策略是否可以?(查看nacos 最新的日志配置,默认保留时间是180天,日志可能会达到10G+,个人感觉使用方更多关注的是自己的业务服务日志,很少关注nacos这边的日志,感觉10G+占用磁盘空间有点多了。)

@KomachiSion
Copy link
Collaborator

v1.x-develop branch

@KomachiSion
Copy link
Collaborator

保持和2.x一致的策略即可。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants