-
Notifications
You must be signed in to change notification settings - Fork 798
/
Logger.cpp
69 lines (58 loc) · 1.96 KB
/
Logger.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "robomongo/core/utils/Logger.h"
#include <QDir>
#include <QMetaType>
#include "robomongo/core/AppRegistry.h"
#include "robomongo/core/domain/App.h"
#include "robomongo/core/EventBus.h"
#include "robomongo/core/settings/SettingsManager.h"
#include "robomongo/core/utils/QtUtils.h"
namespace Robomongo
{
Logger::Logger()
{
QFile file {
QString("%1/" PROJECT_NAME_LOWERCASE ".log").arg(QDir::tempPath())
};
//delete file if it size more than 5mb
if (file.exists() && file.size() > 5 * 1024 * 1024)
file.remove();
}
Logger::~Logger()
{
}
void Logger::print(const char *mess, mongo::logger::LogSeverity level, bool notify)
{
print(std::string(mess), level, notify);
}
void Logger::print(const std::string &mess, mongo::logger::LogSeverity level, bool notify)
{
print(QtUtils::toQString(mess), level, notify);
}
void Logger::print(const QString &msg, mongo::logger::LogSeverity level, bool notify)
{
if (!notify)
return;
// Make uniform log level strings e.g "Error: ", "Info: " etc...
auto logLevelStr = QString::fromStdString(level.toStringData().toString());
if (!logLevelStr.isEmpty()) {
logLevelStr = logLevelStr.toLower();
logLevelStr[0] = logLevelStr[0].toUpper();
logLevelStr += ": ";
}
emit printed(logLevelStr + msg.simplified(), level);
}
void sendLog(
QObject *sender, LogEvent::LogLevel const& severity,
std::string const& msg, bool const informUser /*= false*/)
{
AppRegistry::instance().bus()->send(
AppRegistry::instance().app(),
new LogEvent(sender, msg, severity, informUser)
);
}
void debugLog(std::string_view msg) {
if (!AppRegistry::instance().settingsManager()->debugMode())
return;
std::cout << msg << std::endl;
}
}