summaryrefslogtreecommitdiffstats
path: root/mmc_updater/src/Log.cpp
diff options
context:
space:
mode:
authorAndrew <forkk@forkk.net>2013-12-09 12:04:05 -0600
committerAndrew <forkk@forkk.net>2013-12-09 12:04:05 -0600
commit7f52bed9e3f559adcbcf3f3c1c7ac2251964db8c (patch)
tree52097b57dc7d18ec4e35ef3a8e554af2d91545e8 /mmc_updater/src/Log.cpp
parent9410dd042ea62224fa3e0eb3b525abbdf0c316ee (diff)
parent220e07aef4a34dca9f31ae0c5bb994e5c594125d (diff)
downloadMultiMC-7f52bed9e3f559adcbcf3f3c1c7ac2251964db8c.tar
MultiMC-7f52bed9e3f559adcbcf3f3c1c7ac2251964db8c.tar.gz
MultiMC-7f52bed9e3f559adcbcf3f3c1c7ac2251964db8c.tar.lz
MultiMC-7f52bed9e3f559adcbcf3f3c1c7ac2251964db8c.tar.xz
MultiMC-7f52bed9e3f559adcbcf3f3c1c7ac2251964db8c.zip
Merge branch 'feature_updater' into develop
Diffstat (limited to 'mmc_updater/src/Log.cpp')
-rw-r--r--mmc_updater/src/Log.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/mmc_updater/src/Log.cpp b/mmc_updater/src/Log.cpp
new file mode 100644
index 00000000..d4e5a214
--- /dev/null
+++ b/mmc_updater/src/Log.cpp
@@ -0,0 +1,65 @@
+#include "Log.h"
+
+#include "Platform.h"
+#include "StringUtils.h"
+#include "ProcessUtils.h"
+
+#include <string.h>
+#include <iostream>
+
+Log m_globalLog;
+
+Log* Log::instance()
+{
+ return &m_globalLog;
+}
+
+Log::Log()
+{
+}
+
+Log::~Log()
+{
+}
+
+void Log::open(const std::string& path)
+{
+ m_mutex.lock();
+ m_output.open(path.c_str(),std::ios_base::out | std::ios_base::app);
+ m_mutex.unlock();
+}
+
+void Log::writeToStream(std::ostream& stream, Type type, const char* text)
+{
+ // Multiple processes may be writing to the same log file during
+ // an update. No attempt is made to synchronize access to the file.
+ //
+ // Under Unix, appends to a single file on a local FS by multiple writers should be atomic
+ // provided that the length of 'text' is less than PIPE_BUF
+ //
+ switch (type)
+ {
+ case Info:
+ stream << "INFO ";
+ break;
+ case Warn:
+ stream << "WARN ";
+ break;
+ case Error:
+ stream << "ERROR ";
+ break;
+ }
+ stream << '(' << intToStr(ProcessUtils::currentProcessId()) << ") " << text << std::endl;
+}
+
+void Log::write(Type type, const char* text)
+{
+ m_mutex.lock();
+ writeToStream(std::cerr,type,text);
+ if (m_output.is_open())
+ {
+ writeToStream(m_output,type,text);
+ }
+ m_mutex.unlock();
+}
+