44#include < unistd.h>
55
66// library includes
7- #include < QDebug>
87#include < QDir>
98#include < QMutex>
109#include < QTimer>
@@ -30,6 +29,8 @@ namespace {
3029
3130namespace appimagelauncher ::daemon {
3231
32+ Q_LOGGING_CATEGORY (fswCat, " appimagelauncher.daemon.filesystemwatcher" )
33+
3334 class FileSystemWatcher ::PrivateData {
3435 public:
3536 enum EVENT_TYPES {
@@ -111,18 +112,18 @@ namespace appimagelauncher::daemon {
111112 bool startWatching (const QDir& directory) {
112113 static const auto mask = fileChangeEvents | fileRemovalEvents;
113114
114- qDebug ( ) << " start watching directory " << directory;
115+ qCDebug (fswCat ) << " start watching directory " << directory;
115116
116117 if (!directory.exists ()) {
117- qDebug ( ) << " Warning: directory " << directory.absolutePath () << " does not exist, skipping" ;
118+ qCDebug (fswCat ) << " Warning: directory " << directory.absolutePath () << " does not exist, skipping" ;
118119 return true ;
119120 }
120121
121122 const int watchFd = inotify_add_watch (inotifyFd, directory.absolutePath ().toStdString ().c_str (), mask);
122123
123124 if (watchFd == -1 ) {
124125 const auto error = errno;
125- std::cerr << " Failed to start watching: " << strerror (error) << std::endl ;
126+ qCCritical (fswCat) << " Failed to start watching: " << strerror (error);
126127 return false ;
127128 }
128129
@@ -161,11 +162,11 @@ namespace appimagelauncher::daemon {
161162 // therefore, we can remove the file descriptor from the map in any case
162163 watchFdMap.erase (watchFd);
163164
164- qDebug ( ) << " stop watching watchfd " << watchFd;
165+ qCDebug (fswCat ) << " stop watching watchfd " << watchFd;
165166
166167 if (inotify_rm_watch (inotifyFd, watchFd) == -1 ) {
167168 const auto error = errno;
168- std::cerr << " Failed to stop watching: " << strerror (error) << std::endl ;
169+ qCCritical (fswCat) << " Failed to stop watching: " << strerror (error);
169170 return false ;
170171 }
171172
@@ -180,7 +181,7 @@ namespace appimagelauncher::daemon {
180181 const auto watchFd = pair.first ;
181182
182183 if (!stopWatching (watchFd)) {
183- std::cerr << " Warning: Failed to stop watching on file descriptor " << watchFd << std::endl ;
184+ qCCritical (fswCat) << " Warning: Failed to stop watching on file descriptor " << watchFd;
184185 }
185186 }
186187
@@ -233,7 +234,7 @@ namespace appimagelauncher::daemon {
233234 QMutexLocker lock{d->mutex };
234235
235236 if (d->isRunning ) {
236- qDebug ( ) << " tried to start file system watcher while it's running already" ;
237+ qCDebug (fswCat ) << " tried to start file system watcher while it's running already" ;
237238 return true ;
238239 }
239240 }
@@ -255,7 +256,7 @@ namespace appimagelauncher::daemon {
255256 QMutexLocker lock{d->mutex };
256257
257258 if (!d->isRunning ) {
258- qDebug ( ) << " tried to stop file system watcher while stopped" ;
259+ qCDebug (fswCat ) << " tried to stop file system watcher while stopped" ;
259260 return true ;
260261 }
261262 }
@@ -298,7 +299,7 @@ namespace appimagelauncher::daemon {
298299 // therefore we use a simple linear search to remove non-existing directories
299300 for (auto it = watchedDirectories.begin (); it != watchedDirectories.end (); ++it) {
300301 if (!it->exists ()) {
301- std::cout << " Directory " << it->path (). toStdString () << " does not exist, skipping" << std::endl ;
302+ qCDebug (fswCat) << " Directory " << it->path () << " does not exist, skipping" ;
302303 it = watchedDirectories.erase (it);
303304 }
304305 }
0 commit comments