Skip to content

fix(log-rotate): skip access log when enable_access_log is set to false#11310

Merged
Baoyuantop merged 12 commits into
apache:masterfrom
flearc:feature/log-rotate
Jul 17, 2025
Merged

fix(log-rotate): skip access log when enable_access_log is set to false#11310
Baoyuantop merged 12 commits into
apache:masterfrom
flearc:feature/log-rotate

Conversation

@flearc

@flearc flearc commented May 31, 2024

Copy link
Copy Markdown
Contributor

Description

Fixes #11309

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@flearc flearc changed the title fix(log-rotate): skip access log when enable_access_log is set to false WIP: fix(log-rotate): skip access log when enable_access_log is set to false May 31, 2024
@flearc flearc changed the title WIP: fix(log-rotate): skip access log when enable_access_log is set to false fix(log-rotate): skip access log when enable_access_log is set to false Jun 7, 2024
Comment thread apisix/plugins/log-rotate.lua
@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the [email protected] list. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Sep 17, 2024
@flearc

flearc commented Sep 17, 2024

Copy link
Copy Markdown
Contributor Author

@shreemaan-abhishek PTAL

@github-actions github-actions Bot removed the stale label Sep 18, 2024
Comment thread apisix/plugins/log-rotate.lua Outdated
local access_log_file_size = file_size(default_logs[DEFAULT_ACCESS_LOG_FILENAME].file)
local error_log_file_size = file_size(default_logs[DEFAULT_ERROR_LOG_FILENAME].file)
local files = core.table.new(2, 0)
local files = {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why make this change? It seems unrelated to me. If it really is, you should remove it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same that no need to pre-allocate. It only needs to store one filename when enable_access_log is false.

end

local new_files = core.table.new(2, 0)
local new_files = core.table.new(#files, 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like unrelated change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new_files stores the name of access.log and error.log. If enable_access_log is set to false, nginx will not generate access.log file, no need to pre-allocate an array of length 2.



local function get_log_path_info(file_type)
local_conf = core.config.local_conf()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove this line?

@flearc flearc Sep 29, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local_conf is initialized in the init function now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should keep this line

the local_conf may change when APISIX is running

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and need to update enable_access_log, it may change

enable_access_log = core.table.try_read_attr(
        local_conf, "nginx_config", "http", "enable_access_log")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, first time I learned local_conf can be changed while APISIX running

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Sep 29, 2024
@flearc

flearc commented Sep 29, 2024

Copy link
Copy Markdown
Contributor Author

@shreemaan-abhishek Thanks for your advice! I have updated my PR and I would like to explain it again that since we can disable access.log by setting enable_access_log to false, the length of files and new_files is not guaranteed to be 2. So I adjusted the logic here.

@flearc

flearc commented Oct 8, 2024

Copy link
Copy Markdown
Contributor Author

@shreemaan-abhishek The lint CI has been fixed. The other two test cases' failures seems unrelated. Please review.

@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the [email protected] list. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Dec 16, 2024
@github-actions

Copy link
Copy Markdown

This pull request/issue has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

@github-actions github-actions Bot closed this Jan 24, 2025
@flearc

flearc commented May 16, 2025

Copy link
Copy Markdown
Contributor Author

@Baoyuantop I can't reopen it, maybe need a new PR.

@Baoyuantop Baoyuantop reopened this May 19, 2025
@flearc

flearc commented May 26, 2025

Copy link
Copy Markdown
Contributor Author

@Baoyuantop The failing CI test is not related to the changes in this PR, and I've verified that the same failure exists in the latest several commits on master, it needs to be addressed in a separate PR.

@Baoyuantop

Copy link
Copy Markdown
Contributor

Hi @flearc, can you merge the latest master branch?

@flearc

flearc commented Jun 9, 2025

Copy link
Copy Markdown
Contributor Author

Hi @flearc, can you merge the latest master branch?

@Baoyuantop done

@flearc

flearc commented Jun 13, 2025

Copy link
Copy Markdown
Contributor Author

@Baoyuantop
The t/plugin/request-id.t test failed in CI, but I couldn’t reproduce it locally. I believe the failure is not related to the changes in this PR. Could you please help check what might have caused it?

@flearc

flearc commented Jun 17, 2025

Copy link
Copy Markdown
Contributor Author

Hi @Baoyuantop, the tests have passed. Could you please assign additional reviewers for further review and merge?

@Baoyuantop
Baoyuantop self-requested a review June 17, 2025 08:40
Baoyuantop
Baoyuantop previously approved these changes Jul 3, 2025


local function get_log_path_info(file_type)
local_conf = core.config.local_conf()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should keep this line

the local_conf may change when APISIX is running



local function get_log_path_info(file_type)
local_conf = core.config.local_conf()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and need to update enable_access_log, it may change

enable_access_log = core.table.try_read_attr(
        local_conf, "nginx_config", "http", "enable_access_log")

@membphis

membphis commented Jul 4, 2025

Copy link
Copy Markdown
Member

I re-run the failed CI, it seems unrelated to this PR

@Baoyuantop
Baoyuantop merged commit 81caea1 into apache:master Jul 17, 2025
27 of 31 checks passed
@github-project-automation github-project-automation Bot moved this from 👀 In review to ✅ Done in ⚡️ Apache APISIX Roadmap Jul 17, 2025
@flearc
flearc deleted the feature/log-rotate branch July 17, 2025 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

bug: log-rotate plugin should not rotate the access log when the enable_access_log setting is set to false

5 participants