mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-23 21:46:03 +03:00
Add the --logdir commandline option
To log to a different file for every sync. This also changed a QueuedConnection to AutoConnection, that way we directly save the log from the main thread in the file without waiting for the event loop (so if it crashes before, the log has been writen)
This commit is contained in:
parent
1f2ba7e254
commit
7c1f91abdd
4 changed files with 47 additions and 8 deletions
|
@ -526,7 +526,9 @@ void Application::setupLogBrowser()
|
|||
_logBrowser = new LogBrowser;
|
||||
qInstallMsgHandler( mirallLogCatcher );
|
||||
// ## TODO: allow new log name maybe?
|
||||
if (!_logFile.isEmpty()) {
|
||||
if (!_logDirectory.isEmpty()) {
|
||||
enterNextLogFile();
|
||||
} else if (!_logFile.isEmpty()) {
|
||||
qDebug() << "Logging into logfile: " << _logFile << " with flush " << _logFlush;
|
||||
_logBrowser->setLogFile( _logFile, _logFlush );
|
||||
}
|
||||
|
@ -542,6 +544,30 @@ void Application::setupLogBrowser()
|
|||
|
||||
}
|
||||
|
||||
void Application::enterNextLogFile()
|
||||
{
|
||||
if (_logBrowser && !_logDirectory.isEmpty()) {
|
||||
QDir dir(_logDirectory);
|
||||
if (!dir.exists()) {
|
||||
dir.mkpath(".");
|
||||
}
|
||||
|
||||
// Find out what is the file with the highest nymber if any
|
||||
QStringList files = dir.entryList(QStringList("owncloud.log.*"),
|
||||
QDir::Files);
|
||||
QRegExp rx("owncloud.log.(\\d+)");
|
||||
uint maxNumber = 0;
|
||||
foreach(const QString &s, files) {
|
||||
if (rx.exactMatch(s)) {
|
||||
maxNumber = qMax(maxNumber, rx.cap(1).toUInt());
|
||||
}
|
||||
}
|
||||
|
||||
QString filename = _logDirectory + "/owncloud.log." + QString::number(maxNumber+1);
|
||||
_logBrowser->setLogFile(filename , _logFlush);
|
||||
}
|
||||
}
|
||||
|
||||
QNetworkProxy proxyFromConfig(const MirallConfigFile& cfg)
|
||||
{
|
||||
QNetworkProxy proxy;
|
||||
|
@ -839,6 +865,10 @@ void Application::slotSyncStateChange( const QString& alias )
|
|||
computeOverallSyncStatus();
|
||||
|
||||
qDebug() << "Sync state changed for folder " << alias << ": " << result.statusString();
|
||||
|
||||
if (result.status() == SyncResult::Success || result.status() == SyncResult::Error) {
|
||||
enterNextLogFile();
|
||||
}
|
||||
}
|
||||
|
||||
void Application::parseOptions(const QStringList &options)
|
||||
|
@ -862,6 +892,12 @@ void Application::parseOptions(const QStringList &options)
|
|||
} else {
|
||||
setHelp();
|
||||
}
|
||||
} else if (option == QLatin1String("--logdir")) {
|
||||
if (it.hasNext() && !it.peekNext().startsWith(QLatin1String("--"))) {
|
||||
_logDirectory = it.next();
|
||||
} else {
|
||||
setHelp();
|
||||
}
|
||||
} else if (option == QLatin1String("--logflush")) {
|
||||
_logFlush = true;
|
||||
} else if (option == QLatin1String("--monoicons")) {
|
||||
|
@ -974,6 +1010,7 @@ setHelp();
|
|||
std::cout << " -h --help : show this help screen." << std::endl;
|
||||
std::cout << " --logwindow : open a window to show log output." << std::endl;
|
||||
std::cout << " --logfile <filename> : write log output to file <filename>." << std::endl;
|
||||
std::cout << " --logdir <name> : write each sync log output in a different file in directory <name>." << std::endl;
|
||||
std::cout << " --logflush : flush the log file after every write." << std::endl;
|
||||
std::cout << " --monoicons : Use black/white pictograms for systray." << std::endl;
|
||||
std::cout << " --confdir <dirname> : Use the given configuration directory." << std::endl;
|
||||
|
|
|
@ -79,6 +79,7 @@ protected:
|
|||
void setupContextMenu();
|
||||
void setupLogBrowser();
|
||||
void setupProxy();
|
||||
void enterNextLogFile();
|
||||
|
||||
//folders have to be disabled while making config changes
|
||||
void computeOverallSyncStatus();
|
||||
|
@ -133,6 +134,7 @@ private:
|
|||
QMap<QString, QString> _overallStatusStrings;
|
||||
LogBrowser *_logBrowser;
|
||||
QString _logFile;
|
||||
QString _logDirectory;
|
||||
bool _showLogWindow;
|
||||
bool _logFlush;
|
||||
bool _helpOnly;
|
||||
|
|
|
@ -113,15 +113,12 @@ LogBrowser::LogBrowser(QWidget *parent) :
|
|||
|
||||
setModal(false);
|
||||
|
||||
// needs to be a queued connection as logs from other threads come in
|
||||
connect(Logger::instance(), SIGNAL(newLog(QString)),this,SLOT(slotNewLog(QString)), Qt::QueuedConnection);
|
||||
// Direct connection for log comming from this thread, and queued for the one in a different thread
|
||||
connect(Logger::instance(), SIGNAL(newLog(QString)),this,SLOT(slotNewLog(QString)), Qt::AutoConnection);
|
||||
}
|
||||
|
||||
LogBrowser::~LogBrowser()
|
||||
{
|
||||
if( _logstream ) {
|
||||
_logFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
void LogBrowser::slotNewLog( const QString& msg )
|
||||
|
@ -138,6 +135,9 @@ void LogBrowser::slotNewLog( const QString& msg )
|
|||
|
||||
void LogBrowser::setLogFile( const QString & name, bool flush )
|
||||
{
|
||||
if( _logstream ) {
|
||||
_logFile.close();
|
||||
}
|
||||
_logFile.setFileName( name );
|
||||
|
||||
if(!_logFile.open(QIODevice::WriteOnly)) {
|
||||
|
@ -150,7 +150,7 @@ void LogBrowser::setLogFile( const QString & name, bool flush )
|
|||
return;
|
||||
}
|
||||
_doFileFlush = flush;
|
||||
_logstream = new QTextStream( &_logFile );
|
||||
_logstream.reset(new QTextStream( &_logFile ));
|
||||
}
|
||||
|
||||
void LogBrowser::slotFind()
|
||||
|
|
|
@ -67,7 +67,7 @@ private:
|
|||
|
||||
QFile _logFile;
|
||||
bool _doFileFlush;
|
||||
QTextStream *_logstream;
|
||||
QScopedPointer<QTextStream> _logstream;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
|
Loading…
Reference in a new issue