2018-01-28 14:23:55 +01:00
|
|
|
#include "singletons/loggingmanager.hpp"
|
2018-04-27 22:11:19 +02:00
|
|
|
|
|
|
|
#include "application.hpp"
|
2018-01-28 14:23:55 +01:00
|
|
|
#include "debug/log.hpp"
|
|
|
|
#include "singletons/pathmanager.hpp"
|
|
|
|
#include "singletons/settingsmanager.hpp"
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QStandardPaths>
|
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
namespace singletons {
|
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
void LoggingManager::initialize()
|
2018-01-28 14:23:55 +01:00
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
this->pathManager = getApp()->paths;
|
2018-01-28 14:23:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoggingManager::addMessage(const QString &channelName, messages::MessagePtr message)
|
|
|
|
{
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
2018-01-28 14:23:55 +01:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
if (!app->settings->enableLogging) {
|
2018-01-28 14:23:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto it = this->loggingChannels.find(channelName);
|
|
|
|
if (it == this->loggingChannels.end()) {
|
|
|
|
auto channel = new LoggingChannel(channelName, this->getDirectoryForChannel(channelName));
|
|
|
|
channel->addMessage(message);
|
2018-01-28 15:28:02 +01:00
|
|
|
this->loggingChannels.emplace(channelName,
|
|
|
|
std::unique_ptr<LoggingChannel>(std::move(channel)));
|
2018-01-28 14:23:55 +01:00
|
|
|
} else {
|
|
|
|
it->second->addMessage(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString LoggingManager::getDirectoryForChannel(const QString &channelName)
|
|
|
|
{
|
2018-05-15 19:44:58 +02:00
|
|
|
auto customPath = getApp()->settings->logPath;
|
|
|
|
|
2018-01-28 14:23:55 +01:00
|
|
|
if (channelName.startsWith("/whispers")) {
|
2018-05-15 19:44:58 +02:00
|
|
|
if (customPath != "")
|
|
|
|
return customPath + "/Whispers";
|
2018-04-27 22:11:19 +02:00
|
|
|
return this->pathManager->whispersLogsFolderPath;
|
2018-01-28 14:23:55 +01:00
|
|
|
} else if (channelName.startsWith("/mentions")) {
|
2018-05-15 19:44:58 +02:00
|
|
|
if (customPath != "")
|
|
|
|
return customPath + "/Mentions";
|
2018-04-27 22:11:19 +02:00
|
|
|
return this->pathManager->mentionsLogsFolderPath;
|
2018-01-28 14:23:55 +01:00
|
|
|
} else {
|
2018-05-15 19:44:58 +02:00
|
|
|
if (customPath != "") {
|
|
|
|
QString logPath(customPath + QDir::separator() + channelName);
|
|
|
|
|
|
|
|
if (!this->pathManager->createFolder(logPath)) {
|
|
|
|
debug::Log("Error creating channel logs folder for channel {}", channelName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return logPath;
|
|
|
|
}
|
2018-04-27 22:11:19 +02:00
|
|
|
QString logPath(this->pathManager->channelsLogsFolderPath + QDir::separator() +
|
|
|
|
channelName);
|
2018-01-28 14:23:55 +01:00
|
|
|
|
2018-04-27 22:11:19 +02:00
|
|
|
if (!this->pathManager->createFolder(logPath)) {
|
2018-01-28 14:23:55 +01:00
|
|
|
debug::Log("Error creating channel logs folder for channel {}", channelName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return logPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-15 19:44:58 +02:00
|
|
|
void LoggingManager::refreshLoggingPath()
|
|
|
|
{
|
|
|
|
// if (app->settings->logPath == "") {
|
|
|
|
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
|
2018-01-28 14:23:55 +01:00
|
|
|
} // namespace singletons
|
|
|
|
} // namespace chatterino
|