Status-> System log, new text should be at the top, not bottom

Here is what I mean

See discussion at:

I tested that "reversed syslog" on my own system, but as I had already used OpenWrt so long, it seemed wrong to have log as new lines on top.

2 Likes

Thanks !

I pulled the code from the syslog.js on my system, but it was just one continuous and unreadable line of text.

I asked chatgpt to properly format and indent the code, it returned the following

'use strict';
'require view';
'require fs';
'require ui';

return view.extend({
    load: function() {
        return Promise.all([
            L.resolveDefault(fs.stat('/sbin/logread'), null),
            L.resolveDefault(fs.stat('/usr/sbin/logread'), null)
        ]).then(function(stat) {
            var logger = stat[0] ? stat[0].path : stat[1] ? stat[1].path : null;
            return fs.exec_direct(logger, ['-e', '^']).catch(function(err) {
                ui.addNotification(
                    null,
                    E('p', {}, _('Unable to load log data: ' + err.message))
                );
                return '';
            });
        });
    },
    render: function(logdata) {
        var loglines = logdata.trim().split(/\n/);
        return E([], [
            E('h2', {}, [_('System Log')]),
            E('div', {'id': 'content_syslog'}, [
                E('textarea', {
                    'id': 'syslog',
                    'style': 'font-size:12px',
                    'readonly': 'readonly',
                    'wrap': 'off',
                    'rows': loglines.length + 1
                }, [loglines.join('\n')])
            ])
        ]);
    },
    handleSaveApply: null,
    handleSave: null,
    handleReset: null
});

According to that post, it would be a matter of changing the code

fs.exec_direct('/sbin/logread'

to

loglines.join('\n') => loglines.reverse().join('\n')

Unfortunately, the orignal line no longer exists in the current incarnation of syslog.js

I think that you can see the format from my previous WNDR3700 community build's (Build for WNDR3700v1/v2 / WNDR3800 (discontinued)) download site:

...-luci.patch shows the changes:

I wanted to show only the 50 last lines, and the code goes like shown below:

I created a seaprate menu item and page for that, so the code is a bit more complex, but the crucial part is:
loglines.join('\n') change to
loglines.slice(-50).reverse().join('\n')
or just
loglines.reverse().join('\n')

key extract:

render: function(logdata) {
+		var loglines = logdata.trim().split(/\n/);
+
+		return E([], [
+			E('h2', {}, [ _('Last 50 lines of System Log (recent on top)') ]),
+			E('div', { 'id': 'content_syslog' }, [
+				E('textarea', {
+					'id': 'syslog',
+					'style': 'font-size:12px',
+					'readonly': 'readonly',
+					'wrap': 'off',
+					'rows': 52
+				}, [ loglines.slice(-50).reverse().join('\n') ])
+			])
+		]);
+	},

full code:

diff --git a/modules/luci-mod-status/htdocs/luci-static/resources/view/status/recentlog.js b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/recentlog.js
new file mode 100644
index 000000000..219034a4b
--- /dev/null
+++ b/modules/luci-mod-status/htdocs/luci-static/resources/view/status/recentlog.js
@@ -0,0 +1,33 @@
+'use strict';
+'require fs';
+'require ui';
+
+return L.view.extend({
+	load: function() {
+		return fs.exec_direct('/sbin/logread', [ '-e', '^' ]).catch(function(err) {
+			ui.addNotification(null, E('p', {}, _('Unable to load log data: ' + err.message)));
+			return '';
+		});
+	},
+
+	render: function(logdata) {
+		var loglines = logdata.trim().split(/\n/);
+
+		return E([], [
+			E('h2', {}, [ _('Last 50 lines of System Log (recent on top)') ]),
+			E('div', { 'id': 'content_syslog' }, [
+				E('textarea', {
+					'id': 'syslog',
+					'style': 'font-size:12px',
+					'readonly': 'readonly',
+					'wrap': 'off',
+					'rows': 52
+				}, [ loglines.slice(-50).reverse().join('\n') ])
+			])
+		]);
+	},
+
+	handleSaveApply: null,
+	handleSave: null,
+	handleReset: null
+});
diff --git a/modules/luci-mod-status/root/usr/share/luci/menu.d/luci-mod-status.json b/modules/luci-mod-status/root/usr/share/luci/menu.d/luci-mod-status.json
index e726c56b2..3c9fe48c5 100644
--- a/modules/luci-mod-status/root/usr/share/luci/menu.d/luci-mod-status.json
+++ b/modules/luci-mod-status/root/usr/share/luci/menu.d/luci-mod-status.json
@@ -35,9 +35,18 @@
 		}
 	},
 
+	"admin/status/recentlog": {
+		"title": "Last 50 lines in log",
+		"order": 4,
+		"action": {
+			"type": "view",
+			"path": "status/recentlog"
+		}
+	},
+
 	"admin/status/logs": {
 		"title": "System Log",
-		"order": 4,
+		"order": 5,
 		"action": {
 			"type": "alias",
 			"path": "admin/status/logs/syslog"
@@ -67,7 +76,7 @@
 
 	"admin/status/processes": {
 		"title": "Processes",
-		"order": 6,
+		"order": 7,
 		"action": {
 			"type": "view",
 			"path": "status/processes"
@@ -92,7 +101,7 @@
 
 	"admin/status/realtime": {
 		"title": "Realtime Graphs",
-		"order": 7,
+		"order": 8,
 		"action": {
 			"type": "alias",
 			"path": "admin/status/realtime/load"

It does exists there. At least in master and 22.03 and 21.02 and 19.07

An alternative may be to scroll to the bottom of the page on page loading...

On every system logs are always from top to bottom and people would expect the same

1 Like

I confirm the code below works as discussed
Version
LuCI openwrt-22.03 branch (git-22.361.69894-438c598)https://github.com/openwrt/luci
OpenWrt 22.03.3 r20028-43d71ad93e
luci git-20.074.84698-ead5e81

'use strict';
'require view';
'require fs';
'require ui';

return view.extend({
    load: function() {
        return Promise.all([
            L.resolveDefault(fs.stat('/sbin/logread'), null),
            L.resolveDefault(fs.stat('/usr/sbin/logread'), null)
        ]).then(function(stat) {
            var logger = stat[0] ? stat[0].path : stat[1] ? stat[1].path : null;
            return fs.exec_direct(logger, ['-e', '^']).catch(function(err) {
                ui.addNotification(
                    null,
                    E('p', {}, _('Unable to load log data: ' + err.message))
                );
                return '';
            });
        });
    },
    render: function(logdata) {
        var loglines = logdata.trim().split(/\n/);
        return E([], [
            E('h2', {}, [_('System Log')]),
            E('div', {'id': 'content_syslog'}, [
                E('textarea', {
                    'id': 'syslog',
                    'style': 'font-size:12px',
                    'readonly': 'readonly',
                    'wrap': 'off',
                    'rows': loglines.length + 1
                }, [loglines.reverse().join('\n')])
            ])
        ]);
    },
    handleSaveApply: null,
    handleSave: null,
    handleReset: null
});

So it seems the code literally flips the entries...which as noted:

I agree. Changing something that's standard and expected everywere else (e.g. even the same software but via the command line, from which the web GUI gets the data) - is a good source for/cause of confusion (and may mess up other's scripts).

I know it would confuse me, and the only refrence would be this one obscure thread and one PR.

Lastly given the log is rolling, inverting the entries may falsely imply the logs run from "the beginning".

I actually did run into that in a TP-Link OEM firmware, and that originally prompted me to try reversing.

But I did that as the quick "show last 50 lines" page, not for the whole log.

1 Like

I understand how it would be different from what you are used to.

However having the end of the syslog visible as soon as you open the page would be really great.

Now every time you load this page you must first scroll to the bottom

I understand why you clip the syslog to 50 lines to achieve this, but that's a problem if you're hunting a problem that occurred more than about 2 hours ago.

I just loaded my syslog page and I also scrolled to the bottom out of habit, not realizing what I need is right there at the top !

I would add a checked checkbox at the top of the interface with label "reverse chronological order" to make it easy for anyone to switch back and forth, and also as a reminder that they don't have to scroll down anymore.

I would be nice to also have this for the kernel log page.

astly, and this could be another feature request, but this page should live update as new entries appear in the log file, similair to "tail -f" so as to make page reloads unnecessary during long term monitoring.

I'd say it took me about maybe a week to get used to having the syslog in reverse but now I really dig it.

No more scrolling! :partying_face:

certainly a selective order and respective auto refresh with filter option would be nice but one would expect in case you need to read syslog you do have the skill to SSH and use logread too? :wink:

I second that suggestion! Add html code to automatically scroll down

1 Like