1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-27 17:28:41 +00:00

Refactor logging

- Add warning log level
- Change debug_log_level setting to enumeration string
- Map Irrlicht log events to MT log events
- Encapsulate log_* functions and global variables into a class, Logger
- Unify dstream with standard logging mechanism
- Unify core.debug() with standard core.log() script API
This commit is contained in:
ShadowNinja 2015-10-13 03:57:44 -04:00 committed by kwolekr
parent e0b57c1140
commit 2139d7d45f
25 changed files with 599 additions and 652 deletions

View file

@ -89,7 +89,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
if (list_video_modes)
return print_video_modes();
if (!init_engine(game_params.log_level)) {
if (!init_engine()) {
errorstream << "Could not initialize game engine." << std::endl;
return false;
}
@ -321,10 +321,10 @@ void ClientLauncher::init_args(GameParams &game_params, const Settings &cmd_args
|| cmd_args.getFlag("random-input");
}
bool ClientLauncher::init_engine(int log_level)
bool ClientLauncher::init_engine()
{
receiver = new MyEventReceiver();
create_engine_device(log_level);
create_engine_device();
return device != NULL;
}
@ -455,7 +455,7 @@ bool ClientLauncher::launch_game(std::string &error_message,
if (game_params.game_spec.isValid() &&
game_params.game_spec.id != worldspec.gameid) {
errorstream << "WARNING: Overriding gamespec from \""
warningstream << "Overriding gamespec from \""
<< worldspec.gameid << "\" to \""
<< game_params.game_spec.id << "\"" << std::endl;
gamespec = game_params.game_spec;
@ -500,20 +500,8 @@ void ClientLauncher::main_menu(MainMenuData *menudata)
smgr->clear(); /* leave scene manager in a clean state */
}
bool ClientLauncher::create_engine_device(int log_level)
bool ClientLauncher::create_engine_device()
{
static const irr::ELOG_LEVEL irr_log_level[5] = {
ELL_NONE,
ELL_ERROR,
ELL_WARNING,
ELL_INFORMATION,
#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
ELL_INFORMATION
#else
ELL_DEBUG
#endif
};
// Resolution selection
bool fullscreen = g_settings->getBool("fullscreen");
u16 screenW = g_settings->getU16("screenW");
@ -561,10 +549,6 @@ bool ClientLauncher::create_engine_device(int log_level)
device = createDeviceEx(params);
if (device) {
// Map our log level to irrlicht engine one.
ILogger* irr_logger = device->getLogger();
irr_logger->setLogLevel(irr_log_level[log_level]);
porting::initIrrlicht(device);
}

View file

@ -90,13 +90,13 @@ public:
protected:
void init_args(GameParams &game_params, const Settings &cmd_args);
bool init_engine(int log_level);
bool init_engine();
bool launch_game(std::string &error_message, bool reconnect_requested,
GameParams &game_params, const Settings &cmd_args);
void main_menu(MainMenuData *menudata);
bool create_engine_device(int log_level);
bool create_engine_device();
void speed_tests();
bool print_video_modes();

View file

@ -17,8 +17,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __INPUT_HANDLER_H__
#define __INPUT_HANDLER_H__
#ifndef INPUT_HANDLER_H
#define INPUT_HANDLER_H
#include "irrlichttypes_extrabloated.h"
@ -86,16 +86,16 @@ public:
}
}
} else if (event.EventType == irr::EET_LOG_TEXT_EVENT) {
static const enum LogMessageLevel irr_loglev_conv[] = {
LMT_VERBOSE, // ELL_DEBUG
LMT_INFO, // ELL_INFORMATION
LMT_ACTION, // ELL_WARNING
LMT_ERROR, // ELL_ERROR
LMT_ERROR, // ELL_NONE
static const LogLevel irr_loglev_conv[] = {
LL_VERBOSE, // ELL_DEBUG
LL_INFO, // ELL_INFORMATION
LL_WARNING, // ELL_WARNING
LL_ERROR, // ELL_ERROR
LL_NONE, // ELL_NONE
};
assert(event.LogEvent.Level < ARRLEN(irr_loglev_conv));
log_printline(irr_loglev_conv[event.LogEvent.Level],
std::string("Irrlicht: ") + (const char *)event.LogEvent.Text);
g_logger.log(irr_loglev_conv[event.LogEvent.Level],
std::string("Irrlicht: ") + (const char*) event.LogEvent.Text);
return true;
}
/* always return false in order to continue processing events */