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

About the rotation of q2 logs #580

Open
cyp19901124 opened this issue Jan 9, 2024 · 4 comments · May be fixed by #583
Open

About the rotation of q2 logs #580

cyp19901124 opened this issue Jan 9, 2024 · 4 comments · May be fixed by #583

Comments

@cyp19901124
Copy link

cyp19901124 commented Jan 9, 2024

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);
}
@ar
Copy link
Member

ar commented Jan 12, 2024

Thank you for the report.

Can you confirm if your problem goes away if you use the following config?

<property name="prefix" value="log/q2"/>
<property name="suffix" value=".log"/>

without your trailing / in the prefix?

Deleting files is a dangerous operation. Setting DEF_MAXDEPTH to 1 as the default limit for recursive deletion operations provides a safer approach, but I agree with you that this should be configurable for situations where you know what you're doing.

alcarraz added a commit to alcarraz/jPOS that referenced this issue Feb 8, 2024
Signed-off-by: Andrés Alcarraz <alcarraz@gmail.com>

jpos#580 About the rotation of q2 logs
alcarraz added a commit to alcarraz/jPOS that referenced this issue Feb 8, 2024
So it does not fail on windows.

Signed-off-by: Andrés Alcarraz <alcarraz@gmail.com>

jpos#580 About the rotation of q2 logs
alcarraz added a commit to alcarraz/jPOS that referenced this issue Feb 9, 2024
Signed-off-by: Andrés Alcarraz <alcarraz@gmail.com>

jpos#580 About the rotation of q2 logs
alcarraz added a commit to alcarraz/jPOS that referenced this issue Feb 10, 2024
Signed-off-by: Andrés Alcarraz <alcarraz@gmail.com>

jpos#580 About the rotation of q2 logs
alcarraz added a commit to alcarraz/jPOS that referenced this issue Feb 10, 2024
Signed-off-by: Andrés Alcarraz <alcarraz@gmail.com>

jpos#580 About the rotation of q2 logs
@cyp19901124
Copy link
Author

Thank you very much for your quick response and for addressing the issue. I’ve confirmed that the functionality has indeed been fixed with your updates. I apologize for the delay in my reply; due to my infrequent use of GitHub, I only recently noticed the fix, and a few months have passed.

Again, I appreciate your support and for making the DEF_MAXDEPTH parameter configurable, which greatly helps in scenarios where more control is needed.

@alcarraz
Copy link
Contributor

alcarraz commented Sep 6, 2024 via email

@ar
Copy link
Member

ar commented Sep 6, 2024

We certainly can.

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

Successfully merging a pull request may close this issue.

3 participants