summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Base/Log.h')
-rw-r--r--Swiften/Base/Log.h14
1 files changed, 11 insertions, 3 deletions
diff --git a/Swiften/Base/Log.h b/Swiften/Base/Log.h
index e3e04a5..255e478 100644
--- a/Swiften/Base/Log.h
+++ b/Swiften/Base/Log.h
@@ -7,6 +7,7 @@
7#pragma once 7#pragma once
8 8
9#include <cstdio> 9#include <cstdio>
10#include <functional>
10#include <memory> 11#include <memory>
11#include <sstream> 12#include <sstream>
12 13
@@ -18,20 +19,22 @@ namespace Swift {
18 enum Severity { 19 enum Severity {
19 error, warning, info, debug 20 error, warning, info, debug
20 }; 21 };
22 using Callback = std::function<void(Severity severity, std::string file, int line, std::string function, std::string message)>;
21 23
22 Log(); 24 Log();
23 ~Log(); 25 ~Log();
24 26
25 std::ostringstream& getStream( 27 std::ostringstream& getStream(
26 Severity severity, 28 Severity severity,
27 const std::string& severityString, 29 std::string severityString,
28 const std::string& file, 30 std::string file,
29 int line, 31 int line,
30 const std::string& function); 32 std::string function);
31 33
32 static Severity getLogLevel(); 34 static Severity getLogLevel();
33 static void setLogLevel(Severity level); 35 static void setLogLevel(Severity level);
34 static void setLogFile(const std::string& fileName); 36 static void setLogFile(const std::string& fileName);
37 static void setLogCallback(Callback callback);
35 38
36 private: 39 private:
37 struct LogFileClose { 40 struct LogFileClose {
@@ -43,6 +46,11 @@ namespace Swift {
43 }; 46 };
44 std::ostringstream stream; 47 std::ostringstream stream;
45 static std::unique_ptr<FILE, LogFileClose> logfile; 48 static std::unique_ptr<FILE, LogFileClose> logfile;
49 static Callback logCallback;
50 Severity severity_;
51 std::string file_;
52 int line_;
53 std::string function_;
46 }; 54 };
47} 55}
48 56