3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 Use this for logging everything.
28 If you need to explicitly print something, use dstream or cout or cerr.
31 enum LogMessageLevel {
32 LMT_ERROR, /* Something failed ("invalid map data on disk, block (2,2,1)") */
33 LMT_ACTION, /* In-game actions ("celeron55 placed block at (12,4,-5)") */
34 LMT_INFO, /* More deep info ("saving map on disk (only_modified=true)") */
35 LMT_VERBOSE, /* Flood-style ("loaded block (2,2,2) from disk") */
46 /* line: Full line with timestamp, level and thread */
47 virtual void printLog(const std::string &line){};
48 /* line: Full line with timestamp, level and thread */
49 virtual void printLog(const std::string &line, enum LogMessageLevel lev){};
50 /* line: Only actual printed text */
51 virtual void printLog(enum LogMessageLevel lev, const std::string &line){};
56 void log_add_output(ILogOutput *out, enum LogMessageLevel lev);
57 void log_add_output_maxlev(ILogOutput *out, enum LogMessageLevel lev);
58 void log_add_output_all_levs(ILogOutput *out);
59 void log_remove_output(ILogOutput *out);
60 void log_set_lev_silence(enum LogMessageLevel lev, bool silence);
62 void log_register_thread(const std::string &name);
63 void log_deregister_thread();
65 void log_printline(enum LogMessageLevel lev, const std::string &text);
67 #define LOGLINEF(lev, ...)\
70 snprintf(buf, 10000, __VA_ARGS__);\
71 log_printline(lev, buf);\
74 extern std::ostream errorstream;
75 extern std::ostream actionstream;
76 extern std::ostream infostream;
77 extern std::ostream verbosestream;
79 extern bool log_trace_level_enabled;
81 #define TRACESTREAM(x){ if(log_trace_level_enabled) verbosestream x; }
82 #define TRACEDO(x){ if(log_trace_level_enabled){ x ;} }
84 extern std::ostream *dout_con_ptr;
85 extern std::ostream *derr_con_ptr;
86 extern std::ostream *dout_server_ptr;
87 extern std::ostream *derr_server_ptr;
88 #define dout_con (*dout_con_ptr)
89 #define derr_con (*derr_con_ptr)
90 #define dout_server (*dout_server_ptr)
91 #define derr_server (*derr_server_ptr)
94 extern std::ostream *dout_client_ptr;
95 extern std::ostream *derr_client_ptr;
96 #define dout_client (*dout_client_ptr)
97 #define derr_client (*derr_client_ptr)