Skip to content

Conversation

@shwetd19
Copy link

@shwetd19 shwetd19 commented Feb 13, 2025

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • I have updated the documentation.

Description:

This PR refactors the logging mechanism in the OpenWISP configuration system to centralize logging in the agent (openwisp.agent) instead of directly using the logger command in init.d scripts.

Changes:

  1. Removed Direct logger Calls:

    • Removed logger calls from openwisp-reload-config and openwisp.init.
  2. Added Logging to Agent:

    • Added a log_message function in openwisp.agent to handle logging.
    • Implemented support for the --log-message argument in the agent to log messages.
  3. Updated Scripts:

    • Updated openwisp-reload-config to call the agent for logging via /usr/sbin/openwisp-config --log-message.

Testing:

  • Verified that log messages are correctly generated by the agent when:
    • Running /usr/sbin/openwisp-reload-config.
    • Using the --log-message argument with /usr/sbin/openwisp-config.
    • Restarting the OpenWISP service.

Fixes:

# Logging function
log_message() {
local level="$1"
local message="${2:-}" # Default to an empty string if the second argument is not provided
Copy link
Member

Choose a reason for hiding this comment

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

I would make the message mandatory. For the level I would fall back to daemon.info if none is provided.

local level="$1"
local message="${2:-}" # Default to an empty string if the second argument is not provided

if [ -z "$message" ]; then
Copy link
Member

Choose a reason for hiding this comment

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

You don't need this if statement. You can provide a default value in the assignment of the message variable.

Copy link
Author

Choose a reason for hiding this comment

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

Why is the if [ -z "$message" ] check unnecessary when we already have local message="${2:-}"? Could you clarify the reasoning?

Copy link
Member

Choose a reason for hiding this comment

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

Hi @shwetd19
If you see the above comment, Oliver suggested a fall back when message is not provided. In that case, this check will be unnecessary

@shwetd19
Copy link
Author

Hey @okraits , I've made the suggested changes

  • Added log_message() function in openwisp.agent to handle logging
  • Added command-line arguments --log-level and --log-message to agent
  • Updated openwisp-reload-config and openwisp.init to use the agent for logging
  • Made message parameter mandatory with level defaulting to daemon.info

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 this pull request may close these issues.

[refactor] Move log messages from init.d to agent

3 participants