Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/robomongo/core/settings/SettingsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ namespace Robomongo
_autocompletionMode(AutocompleteAll),
_loadMongoRcJs(false),
_minimizeToTray(false),
_writeLogFile(true),
_lineNumbers(false),
_disableConnectionShortcuts(false),
_batchSize(50),
Expand Down Expand Up @@ -204,6 +205,7 @@ namespace Robomongo
_autoExpand = map.contains("autoExpand") ? map.value("autoExpand").toBool() : true;
_autoExec = map.contains("autoExec") ? map.value("autoExec").toBool() : true;
_minimizeToTray = map.contains("minimizeToTray") ? map.value("minimizeToTray").toBool() : false;
_writeLogFile = map.contains("writeLogFile") ? map.value("writeLogFile").toBool() : true;
_lineNumbers = map.contains("lineNumbers") ? map.value("lineNumbers").toBool() : false;
_imported = map.contains("imported") ? map.value("imported").toBool() : false;
_programExitedNormally = map.contains("programExitedNormally") ?
Expand Down Expand Up @@ -390,6 +392,7 @@ namespace Robomongo

map.insert("autoExec", _autoExec);
map.insert("minimizeToTray", _minimizeToTray);
map.insert("writeLogFile", _writeLogFile);
map.insert("toolbars", _toolbars);
map.insert("imported", _imported);
map.insert("anonymousID", _anonymousID);
Expand Down
2 changes: 2 additions & 0 deletions src/robomongo/core/settings/SettingsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ namespace Robomongo

void setMinimizeToTray(bool isMinimizingToTray) { _minimizeToTray = isMinimizingToTray; }
bool minimizeToTray() const { return _minimizeToTray; }
bool writeLogFile() const { return _writeLogFile; }

void setLineNumbers(bool showLineNumbers) { _lineNumbers = showLineNumbers; }
bool lineNumbers() const { return _lineNumbers; }
Expand Down Expand Up @@ -245,6 +246,7 @@ namespace Robomongo
bool _autoExpand;
bool _autoExec;
bool _minimizeToTray;
bool _writeLogFile;
bool _lineNumbers;
bool _disableConnectionShortcuts;
bool _programExitedNormally = true;
Expand Down
34 changes: 32 additions & 2 deletions src/robomongo/core/utils/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

#include <QDir>
#include <QMetaType>
#include <QLockFile>
#include <QTextStream>
#include <QTime>
#include <QDate>

#include "robomongo/core/utils/QtUtils.h"
#include "robomongo/core/settings/SettingsManager.h"
#include "robomongo/core/AppRegistry.h"

namespace
{
Expand All @@ -14,6 +20,14 @@ namespace

return path;
}

std::string getRobo3tLogPath()
{
static std::string path =
Robomongo::QtUtils::toStdString(QString("%1/.3T/robo-3t/%2/robo3t.log").arg(QDir::homePath()).arg(PROJECT_VERSION));

return path;
}
}

namespace Robomongo
Expand All @@ -32,7 +46,7 @@ namespace Robomongo
}

Logger::~Logger()
{
{
}

void Logger::print(const char *mess, mongo::logger::LogSeverity level, bool notify)
Expand All @@ -41,7 +55,7 @@ namespace Robomongo
}

void Logger::print(const std::string &mess, mongo::logger::LogSeverity level, bool notify)
{
{
print(QtUtils::toQString(mess), level, notify);
}

Expand All @@ -57,6 +71,22 @@ namespace Robomongo
logLevelStr[0] = logLevelStr[0].toUpper();
logLevelStr += ": ";
}

if (AppRegistry::instance().settingsManager()->writeLogFile()) {
std::string path = getRobo3tLogPath();
QLockFile lockfile(QtUtils::toQString(path + ".lock"));
QFile file(QtUtils::toQString(path));

if (lockfile.lock()) {
if (file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
QTextStream out(&file);
out << QDate::currentDate().toString(Qt::ISODate) << " " << QTime::currentTime().toString(Qt::TextDate) << " " << logLevelStr << mess << "\n";
file.close();
}
lockfile.unlock();
}
}

emit printed(logLevelStr + mess, level);
}
}
Expand Down