Skip to content

About the rotation of q2 logs #580

@cyp19901124

Description

@cyp19901124

Regarding the rotation of q2 logs, I have configured the following content in the 00_logger.xml file to test the rotation and deletion of q2 logs, but the functionality to delete expired files is not working.

<log-listener class="org.jpos.util.DailyLogListener">
    <property name="window" value="86400" />
    <property name="prefix" value="logs/q2/" />
    <property name="suffix" value="q2.log"/>
    <property name="date-format" value="yyyy-MM-dd-HH"/>
    <property name="compression-format" value="gzip"/>
    <property name="maxsize" value="10000000"/>
    <property name="maxage" value="86400"/>
</log-listener>

I have checked and debugged the source code and found that the issue lies in the DEF_MAXDEPTH parameter. The parameter determines the depth of file queries and has a default value of 1. As a result, it cannot find expired files under the "logs/q2" directory. I suggest making this parameter configurable in the 00_logger.xml file.

try {
    Files.find(logBasePath, DEF_MAXDEPTH,
            (path, attributes) ->
                    path.getFileName().toString().matches(deleteRegex)
                    && attributes.isRegularFile()
                    && currentSystemTime - attributes.lastModifiedTime().toMillis() >= maxAge)
            .forEach(path -> {
                try {
                    Files.delete(path);
                } catch (IOException e) {
                    e.printStackTrace(System.err);
                }
            });
} catch (IOException e) {
    e.printStackTrace(System.err);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions