After many attempts trying to keep up with the changes in OSX's /var/log/system.log
using QFileSystemWatcher
I am still unable to make it work.
My QXLogWidget
class has a method to set the file path to watched:
void QXLogWidget::setLogPath(QString logPath) {
m_logPath = logPath;
// Start watching changes in logPath
m_watcher = new QFileSystemWatcher();
m_watcher->addPath(m_logPath);
// Connect watching events with the tail method
connect(m_watcher, &QFileSystemWatcher::fileChanged, this, &QXLogWidget::onFileChanged);
}
ยทยทยท
void QXLogWidget::onFileChanged(const QString &path) {
qDebug() << "fileChanged";
qDebug() << path;
readFile();
}
To keep it performant, readFile
stores the file size on each call, to start from that position next time.
However, this works perfectly for a log file inside the user's home. For example, making a copy of /var/log/system.log
to the user's home and appending lines manually with echo "something new" >> system.log
produces the expected notifications to QFileSystemWatcher
, which fires the connection to the onFileChanged
event manager.
At first sight, it seems a simple issue with /var/log/system.log
permissions but:
- Directly calling
readFile
the application reads and shows the contents of/var/log/system.log
- Monitoring
/var/log/system.log
withtail -f
, we make sure it is being appended frequently. - Permissions on
/var/log/system.log
are good enough for the sake of reading:
ls -Flah /var/log/system.log
-rw-r--r--@ 1 root admin 553K 27 may 11:03 /var/log/system.log
- I checked
/var/log/system.log
inode does not change when new lines are being appended to it. Although I did not expect such a thing for/var/log/system.log
, some systems rewrite log files.
So the situation is: QFile
can read a system file but QFileSystemWatcher
is not being notified by the OS when the file changes.
Any idea of what other condition must be relaxed here in order for QFileSystemWatcher
to be notified?