summaryrefslogtreecommitdiff
path: root/src/log.h
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-10-16 12:45:00 +0300
committerPerttu Ahola <celeron55@gmail.com>2011-10-16 12:45:00 +0300
commit4846846a2d28e06f347cb46ffe6be2a42337eb32 (patch)
treea3006c2ce74b3ff26ced1316ff99bb9b9b459cfa /src/log.h
parent414c61489319a56341ac5be808587c8c3ca84255 (diff)
downloadminetest-4846846a2d28e06f347cb46ffe6be2a42337eb32.tar.gz
minetest-4846846a2d28e06f347cb46ffe6be2a42337eb32.tar.bz2
minetest-4846846a2d28e06f347cb46ffe6be2a42337eb32.zip
Initially add small and tight logging facility
Diffstat (limited to 'src/log.h')
-rw-r--r--src/log.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/log.h b/src/log.h
new file mode 100644
index 000000000..a5e840a4d
--- /dev/null
+++ b/src/log.h
@@ -0,0 +1,69 @@
+/*
+Minetest-c55
+Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#ifndef LOG_HEADER
+#define LOG_HEADER
+
+#include <string>
+
+/*
+ Use this for logging everything.
+
+ If you need to explicitly print something, use dstream or cout or cerr.
+*/
+
+enum LogMessageLevel {
+ LMT_ERROR, /* Something failed ("invalid map data on disk, block (2,2,1)") */
+ LMT_ACTION, /* In-game actions ("celeron55 placed block at (12,4,-5)") */
+ LMT_INFO, /* More deep info ("saving map on disk (only_modified=true)") */
+ LMT_VERBOSE, /* Flood-style ("loaded block (2,2,2) from disk") */
+ LMT_NUM_VALUES,
+};
+
+class ILogOutput
+{
+public:
+ /* line: Full line with timestamp, level and thread */
+ virtual void printLog(const std::string &line){};
+ /* line: Only actual printed text */
+ virtual void printLog(enum LogMessageLevel lev, const std::string &line){};
+};
+
+void log_add_output(ILogOutput *out, enum LogMessageLevel lev);
+void log_add_output_maxlev(ILogOutput *out, enum LogMessageLevel lev);
+void log_add_output_all_levs(ILogOutput *out);
+
+void log_register_thread(const std::string &name);
+
+void log_printline(enum LogMessageLevel lev, const std::string &text);
+
+#define LOGLINEF(lev, ...)\
+{\
+ char buf[10000];\
+ snprintf(buf, 10000, __VA_ARGS__);\
+ log_printline(lev, buf);\
+}
+
+extern std::ostream errorstream;
+extern std::ostream actionstream;
+extern std::ostream infostream;
+extern std::ostream verbosestream;
+
+#endif
+