Line data Source code
1 : /*
2 : Minetest
3 : Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 :
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.
9 :
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.
14 :
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.
18 : */
19 :
20 : #ifndef LOG_HEADER
21 : #define LOG_HEADER
22 :
23 : #include <string>
24 :
25 : /*
26 : Use this for logging everything.
27 :
28 : If you need to explicitly print something, use dstream or cout or cerr.
29 : */
30 :
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") */
36 : LMT_NUM_VALUES,
37 : };
38 :
39 : class ILogOutput
40 : {
41 : public:
42 3 : ILogOutput() :
43 3 : silence(false)
44 3 : {}
45 :
46 : /* line: Full line with timestamp, level and thread */
47 0 : virtual void printLog(const std::string &line){};
48 : /* line: Full line with timestamp, level and thread */
49 6 : virtual void printLog(const std::string &line, enum LogMessageLevel lev){};
50 : /* line: Only actual printed text */
51 6 : virtual void printLog(enum LogMessageLevel lev, const std::string &line){};
52 :
53 : bool silence;
54 : };
55 :
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);
61 :
62 : void log_register_thread(const std::string &name);
63 : void log_deregister_thread();
64 :
65 : void log_printline(enum LogMessageLevel lev, const std::string &text);
66 :
67 : #define LOGLINEF(lev, ...)\
68 : {\
69 : char buf[10000];\
70 : snprintf(buf, 10000, __VA_ARGS__);\
71 : log_printline(lev, buf);\
72 : }
73 :
74 : extern std::ostream errorstream;
75 : extern std::ostream actionstream;
76 : extern std::ostream infostream;
77 : extern std::ostream verbosestream;
78 :
79 : extern bool log_trace_level_enabled;
80 :
81 : #define TRACESTREAM(x){ if(log_trace_level_enabled) verbosestream x; }
82 : #define TRACEDO(x){ if(log_trace_level_enabled){ x ;} }
83 :
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)
92 :
93 : #ifndef SERVER
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)
98 :
99 : #endif
100 :
101 : #endif
102 :
|