2011-10-16 05:45:00 -04:00
|
|
|
/*
|
2013-02-24 12:40:43 -05:00
|
|
|
Minetest
|
2013-02-24 13:38:45 -05:00
|
|
|
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2011-10-16 05:45:00 -04:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 10:56:56 -04:00
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
2011-10-16 05:45:00 -04:00
|
|
|
(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
|
2012-06-05 10:56:56 -04:00
|
|
|
GNU Lesser General Public License for more details.
|
2011-10-16 05:45:00 -04:00
|
|
|
|
2012-06-05 10:56:56 -04:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2011-10-16 05:45:00 -04:00
|
|
|
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.
|
2014-12-12 15:12:31 -05:00
|
|
|
|
2011-10-16 05:45:00 -04:00
|
|
|
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:
|
2014-12-12 15:12:31 -05:00
|
|
|
ILogOutput() :
|
|
|
|
silence(false)
|
|
|
|
{}
|
|
|
|
|
2011-10-16 05:45:00 -04:00
|
|
|
/* line: Full line with timestamp, level and thread */
|
|
|
|
virtual void printLog(const std::string &line){};
|
2011-11-27 07:28:54 -05:00
|
|
|
/* line: Full line with timestamp, level and thread */
|
|
|
|
virtual void printLog(const std::string &line, enum LogMessageLevel lev){};
|
2011-10-16 05:45:00 -04:00
|
|
|
/* line: Only actual printed text */
|
|
|
|
virtual void printLog(enum LogMessageLevel lev, const std::string &line){};
|
2014-12-12 15:12:31 -05:00
|
|
|
|
|
|
|
bool silence;
|
2011-10-16 05:45:00 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
2011-11-27 06:52:10 -05:00
|
|
|
void log_remove_output(ILogOutput *out);
|
2014-12-12 15:12:31 -05:00
|
|
|
void log_set_lev_silence(enum LogMessageLevel lev, bool silence);
|
2011-10-16 05:45:00 -04:00
|
|
|
|
|
|
|
void log_register_thread(const std::string &name);
|
2011-11-27 06:52:10 -05:00
|
|
|
void log_deregister_thread();
|
2011-10-16 05:45:00 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2012-05-20 11:30:30 -04:00
|
|
|
extern bool log_trace_level_enabled;
|
|
|
|
|
|
|
|
#define TRACESTREAM(x){ if(log_trace_level_enabled) verbosestream x; }
|
|
|
|
#define TRACEDO(x){ if(log_trace_level_enabled){ x ;} }
|
|
|
|
|
2015-04-01 09:01:28 -04:00
|
|
|
extern std::ostream *dout_con_ptr;
|
|
|
|
extern std::ostream *derr_con_ptr;
|
|
|
|
extern std::ostream *dout_server_ptr;
|
|
|
|
extern std::ostream *derr_server_ptr;
|
|
|
|
#define dout_con (*dout_con_ptr)
|
|
|
|
#define derr_con (*derr_con_ptr)
|
|
|
|
#define dout_server (*dout_server_ptr)
|
|
|
|
#define derr_server (*derr_server_ptr)
|
|
|
|
|
|
|
|
#ifndef SERVER
|
|
|
|
extern std::ostream *dout_client_ptr;
|
|
|
|
extern std::ostream *derr_client_ptr;
|
|
|
|
#define dout_client (*dout_client_ptr)
|
|
|
|
#define derr_client (*derr_client_ptr)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-10-16 05:45:00 -04:00
|
|
|
#endif
|
|
|
|
|