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

luci-mod-status: display log_file in status if defined #7187

Merged
merged 1 commit into from
Jul 22, 2024

Conversation

Chris1189
Copy link
Contributor

Commit includes wrapper syslog in /usr/libexec. If a log file is configured, the output of this file is displayed. Otherwise the output of logread is displayed.

@systemcrash
Copy link
Contributor

Is it certain that the wrapper script passes the same exit codes as logread?

In general this is a good idea, although I think other devs would want to see the wrapper go in to a different repo. I don't think there's any real merit in doing so, since the GUI is the only place it gets leveraged here.

@Chris1189 Chris1189 force-pushed the pr/syslog_new branch 2 times, most recently from ed58ae8 to 5a98663 Compare July 8, 2024 12:33
@Chris1189
Copy link
Contributor Author

Chris1189 commented Jul 8, 2024

Is it certain that the wrapper script passes the same exit codes as logread?

In general this is a good idea, although I think other devs would want to see the wrapper go in to a different repo. I don't think there's any real merit in doing so, since the GUI is the only place it gets leveraged here.

This is a good point and I checked that there are the same return codes.
If there is the need to move the wrapper somewhere else, I will not obstruct that.

Commit includes wrapper syslog in /usr/libexec. If a log file is configured, the output of this file is displayed. Otherwise the output of logread is displayed.

Signed-off-by: Christian Korber <ckorber@tdt.de>
@Chris1189 Chris1189 marked this pull request as ready for review July 9, 2024 05:20
@Chris1189
Copy link
Contributor Author

I made the necessary changes, @systemcrash
The exit codes are identical to logread.

I am looking forward to your review.
Thank you!


return fs.exec_direct(logger, [ '-e', '^' ]).then(logdata => {
return fs.exec_direct(logger).then(logdata => {
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like you excised the ternary operator above - which more than anything looks like a sanity check in case stat[n] is null. Maybe a null check and handling isn't bad here after all. We would already be in some weird place because to arrive at this state implies that the wrapper is absent for some reason. I guess it's no worse anyway, because the old 'resolves' had null as a default. What does exec_direct do in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could also bring back the ternary operator
var logger = stat[0] ? stat[0].path : null;,
but as you already said it would be a weird place and the Promise already returns null in that case.

From the docs:
exec_direct executes the command while bypassing ubus with cgi-io helper applet at `cgi-bin/cgi-exec'. It is useful to fetch large command outputs, which may exceed the ubus message size limits. It also enforces the same access permission rules as the ubus base exec call.

@systemcrash systemcrash merged commit 734442a into openwrt:master Jul 22, 2024
5 checks passed
@systemcrash
Copy link
Contributor

Merged. Thanks @Chris1189

@stokito
Copy link
Contributor

stokito commented Jul 27, 2024

Sorry, that missed review of the PR. The logread command is the only one correct way to request logs. The command gets logs from the in-memory ring buffer of logd.
The syslog-ng is another more advanced log collection daemon that writes logs to a plain file.
Some router manufactures e.g. Turris use it instead of the default OpenWrt logd.
So the logread command doesn't have and ability to fetch logs from the logd.

Instead the syslog-ng created a shell script wrapper that reads logs from the log file. The script has a different path that's why in the LogView we need to detect which logread is installed.

I made a PR to the syslog-ng that will change the symlink the logread script once the syslog-ng is installed. Then the command will be the same whatever the logread implementation is in use and the LogView can be simplified.

Your implementation goes even further and it tries to read a log file itself instead of asking the logread command to do this.

	log_file="$(uci_get system @system[0] log_file "")"
	if [ -f "$log_file" ]; then
		cat "$log_file"
		return
	fi

You don't pass the -e flag to filter i.e. you should use grep -E "${pattern}" "${logfile}" as the logread script does. Basically you reinvented the existing logread script.
This is a breaking change because a filter doesn't work anymore.

As far I understood you wish to receive all the saved logs, not just those that the logd has in a ring buffer.
The logread command has an option -F <file> Log file.
So we may specify the log file instead to achieve same behavior. Maybe this should solved with some additional flag or time range i.g. if there are no logs in a ring buffer for the time then load logs from a file.

Here are sources of the logread https://github.com/openwrt/ubox/blob/master/log/logread.c#L148

Also check the OpenWrt Wiki: Logging messages page for some details.

So for now I would recommend to revert the commit (since it has breaking changes), merge the PR with alternatives, then simplify the logic here (maybe later).

But the archival log reading from a file should be decided separately. Do we really need the feature?
We can make a workaround by specifying a log file but anyway it would be good to discuss with the logread developers.

@systemcrash
Copy link
Contributor

@stokito we determined that -F is a write only parameter, not read. Ie destination file.

is there a good way to reconcile these disparities?

@stokito
Copy link
Contributor

stokito commented Jul 27, 2024

oh, yes it's used to redirect logs to the file.
The /etc/init.d/log script will start the /sbin/logread -f -F /var/log/mylog -p /var/run/log command to dump messages from a ring buffer into the file.
The question remains how to read from the file and do we need this at all. This may be useful to debug problems after reboot. Honestly, this kind of troubleshooting is anyway better to perform manually from command line and then disable the logging to a file to avoid erasing of a NAND flash.
Unless I missed something I think it would be better to revert the commit.

@systemcrash
Copy link
Contributor

systemcrash commented Jul 27, 2024 via email

@jow-
Copy link
Contributor

jow- commented Jul 27, 2024

I agree with @stokito here, don't implement parallel infrastructure in the gui, don't attempt to read log files directly when cli level commands exist for that purpose.

@systemcrash
Copy link
Contributor

Is that what you assess has happened here? The script still leverages logread. But until logread itself gains a parameter to read from other log files, the wrapper script uses cat.

@jow-
Copy link
Contributor

jow- commented Jul 29, 2024

Is that what you assess has happened here?

What happens here is that LuCI starts implementing log related infrastructure code, this belongs into base first.

@Chris1189
Copy link
Contributor Author

As @systemcrash mentioned logread only puts log messages to a specific file with -F.
In /etc/config/system the option log_file redirects log messages to the set file. We wanted to display contents of that file because this way we can see log messages from before boot.

From the messages you wrote to the discussion I gathered that you wish to add the filter option -e from logread to the syslog-wrapper?

My intent was not to implement parallel infrastructure but to add a feature. I want to read the file if it is set.

@Chris1189 Chris1189 deleted the pr/syslog_new branch October 22, 2024 07:01
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.

4 participants