mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Use the logger; also, default to not showing much crap in console. Use --info-on-stderr to enable crap.
This commit is contained in:
parent
4846846a2d
commit
b65a5aceb0
16 changed files with 844 additions and 646 deletions
73
src/main.cpp
73
src/main.cpp
|
@ -438,6 +438,7 @@ Doing currently:
|
|||
#include "gettext.h"
|
||||
#include "settings.h"
|
||||
#include "profiler.h"
|
||||
#include "log.h"
|
||||
|
||||
// This makes textures
|
||||
ITextureSource *g_texturesource = NULL;
|
||||
|
@ -479,19 +480,15 @@ MainGameCallback *g_gamecallback = NULL;
|
|||
|
||||
// Connection
|
||||
std::ostream *dout_con_ptr = &dummyout;
|
||||
std::ostream *derr_con_ptr = &dstream_no_stderr;
|
||||
//std::ostream *dout_con_ptr = &dstream_no_stderr;
|
||||
//std::ostream *derr_con_ptr = &dstream_no_stderr;
|
||||
//std::ostream *dout_con_ptr = &dstream;
|
||||
//std::ostream *derr_con_ptr = &dstream;
|
||||
std::ostream *derr_con_ptr = &verbosestream;
|
||||
|
||||
// Server
|
||||
std::ostream *dout_server_ptr = &dstream;
|
||||
std::ostream *derr_server_ptr = &dstream;
|
||||
std::ostream *dout_server_ptr = &infostream;
|
||||
std::ostream *derr_server_ptr = &errorstream;
|
||||
|
||||
// Client
|
||||
std::ostream *dout_client_ptr = &dstream;
|
||||
std::ostream *derr_client_ptr = &dstream;
|
||||
std::ostream *dout_client_ptr = &infostream;
|
||||
std::ostream *derr_client_ptr = &errorstream;
|
||||
|
||||
/*
|
||||
gettime.h implementation
|
||||
|
@ -583,7 +580,6 @@ public:
|
|||
}
|
||||
else
|
||||
{
|
||||
//dstream<<"MyEventReceiver: mouse input"<<std::endl;
|
||||
left_active = event.MouseInput.isLeftPressed();
|
||||
middle_active = event.MouseInput.isMiddlePressed();
|
||||
right_active = event.MouseInput.isRightPressed();
|
||||
|
@ -1026,7 +1022,7 @@ void SpeedTests()
|
|||
|
||||
u32 dtime = timer.stop();
|
||||
u32 per_ms = n / dtime;
|
||||
std::cout<<"Done. "<<dtime<<"ms, "
|
||||
dstream<<"Done. "<<dtime<<"ms, "
|
||||
<<per_ms<<"/ms"<<std::endl;
|
||||
}
|
||||
}
|
||||
|
@ -1078,12 +1074,37 @@ void drawMenuBackground(video::IVideoDriver* driver)
|
|||
}
|
||||
}
|
||||
|
||||
class DstreamLogOutput: public ILogOutput
|
||||
{
|
||||
public:
|
||||
/* line: Full line with timestamp, level and thread */
|
||||
void printLog(const std::string &line)
|
||||
{
|
||||
dstream<<line<<std::endl;
|
||||
}
|
||||
} main_dstream_log_out;
|
||||
|
||||
class DstreamNoStderrLogOutput: public ILogOutput
|
||||
{
|
||||
public:
|
||||
/* line: Full line with timestamp, level and thread */
|
||||
void printLog(const std::string &line)
|
||||
{
|
||||
dstream_no_stderr<<line<<std::endl;
|
||||
}
|
||||
} main_dstream_no_stderr_log_out;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
/*
|
||||
Initialization
|
||||
*/
|
||||
|
||||
log_add_output_maxlev(&main_dstream_log_out, LMT_ACTION);
|
||||
log_add_output_all_levs(&main_dstream_no_stderr_log_out);
|
||||
|
||||
log_register_thread("main");
|
||||
|
||||
// Set locale. This is for forcing '.' as the decimal point.
|
||||
std::locale::global(std::locale("C"));
|
||||
// This enables printing all characters in bitmap font
|
||||
|
@ -1110,6 +1131,7 @@ int main(int argc, char *argv[])
|
|||
allowed_options.insert("dstream-on-stderr", ValueSpec(VALUETYPE_FLAG));
|
||||
#endif
|
||||
allowed_options.insert("speedtests", ValueSpec(VALUETYPE_FLAG));
|
||||
allowed_options.insert("info-on-stderr", ValueSpec(VALUETYPE_FLAG));
|
||||
|
||||
Settings cmd_args;
|
||||
|
||||
|
@ -1151,6 +1173,9 @@ int main(int argc, char *argv[])
|
|||
if(cmd_args.getFlag("dstream-on-stderr") == false)
|
||||
disable_stderr = true;
|
||||
#endif
|
||||
|
||||
if(cmd_args.getFlag("info-on-stderr"))
|
||||
log_add_output(&main_dstream_log_out, LMT_INFO);
|
||||
|
||||
porting::signal_handler_init();
|
||||
bool &kill = *porting::signal_handler_killstatus();
|
||||
|
@ -1182,7 +1207,7 @@ int main(int argc, char *argv[])
|
|||
BEGIN_DEBUG_EXCEPTION_HANDLER
|
||||
|
||||
// Print startup message
|
||||
dstream<<DTIME<<PROJECT_NAME
|
||||
actionstream<<PROJECT_NAME<<
|
||||
" with SER_FMT_VER_HIGHEST="<<(int)SER_FMT_VER_HIGHEST
|
||||
<<", "<<BUILD_INFO
|
||||
<<std::endl;
|
||||
|
@ -1210,7 +1235,7 @@ int main(int argc, char *argv[])
|
|||
bool r = g_settings->readConfigFile(cmd_args.get("config").c_str());
|
||||
if(r == false)
|
||||
{
|
||||
dstream<<"Could not read configuration from \""
|
||||
errorstream<<"Could not read configuration from \""
|
||||
<<cmd_args.get("config")<<"\""<<std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
@ -1356,7 +1381,7 @@ int main(int argc, char *argv[])
|
|||
driverType = video::EDT_OPENGL;
|
||||
else
|
||||
{
|
||||
dstream<<"WARNING: Invalid video_driver specified; defaulting "
|
||||
errorstream<<"WARNING: Invalid video_driver specified; defaulting "
|
||||
"to opengl"<<std::endl;
|
||||
driverType = video::EDT_OPENGL;
|
||||
}
|
||||
|
@ -1427,14 +1452,14 @@ int main(int argc, char *argv[])
|
|||
if(font)
|
||||
skin->setFont(font);
|
||||
else
|
||||
dstream<<"WARNING: Font file was not found."
|
||||
errorstream<<"WARNING: Font file was not found."
|
||||
" Using default font."<<std::endl;
|
||||
// If font was not found, this will get us one
|
||||
font = skin->getFont();
|
||||
assert(font);
|
||||
|
||||
u32 text_height = font->getDimension(L"Hello, world!").Height;
|
||||
dstream<<"text_height="<<text_height<<std::endl;
|
||||
infostream<<"text_height="<<text_height<<std::endl;
|
||||
|
||||
//skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,0,0,0));
|
||||
skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255,255,255,255));
|
||||
|
@ -1522,7 +1547,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
if(error_message != L"")
|
||||
{
|
||||
dstream<<"WARNING: error_message = "
|
||||
errorstream<<"error_message = "
|
||||
<<wide_to_narrow(error_message)<<std::endl;
|
||||
|
||||
GUIMessageMenu *menu2 =
|
||||
|
@ -1534,7 +1559,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
video::IVideoDriver* driver = device->getVideoDriver();
|
||||
|
||||
dstream<<"Created main menu"<<std::endl;
|
||||
infostream<<"Created main menu"<<std::endl;
|
||||
|
||||
while(device->run() && kill == false)
|
||||
{
|
||||
|
@ -1559,7 +1584,7 @@ int main(int argc, char *argv[])
|
|||
if(device->run() == false || kill == true)
|
||||
break;
|
||||
|
||||
dstream<<"Dropping main menu"<<std::endl;
|
||||
infostream<<"Dropping main menu"<<std::endl;
|
||||
|
||||
menu->drop();
|
||||
|
||||
|
@ -1576,7 +1601,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
password = translatePassword(playername, menudata.password);
|
||||
|
||||
//dstream<<"Main: password hash: '"<<password<<"'"<<std::endl;
|
||||
//infostream<<"Main: password hash: '"<<password<<"'"<<std::endl;
|
||||
|
||||
address = wide_to_narrow(menudata.address);
|
||||
int newport = stoi(wide_to_narrow(menudata.port));
|
||||
|
@ -1643,12 +1668,12 @@ int main(int argc, char *argv[])
|
|||
} //try
|
||||
catch(con::PeerNotFoundException &e)
|
||||
{
|
||||
dstream<<DTIME<<"Connection error (timed out?)"<<std::endl;
|
||||
errorstream<<"Connection error (timed out?)"<<std::endl;
|
||||
error_message = L"Connection error (timed out?)";
|
||||
}
|
||||
catch(SocketException &e)
|
||||
{
|
||||
dstream<<DTIME<<"Socket error (port already in use?)"<<std::endl;
|
||||
errorstream<<"Socket error (port already in use?)"<<std::endl;
|
||||
error_message = L"Socket error (port already in use?)";
|
||||
}
|
||||
#ifdef NDEBUG
|
||||
|
@ -1657,7 +1682,7 @@ int main(int argc, char *argv[])
|
|||
std::string narrow_message = "Some exception, what()=\"";
|
||||
narrow_message += e.what();
|
||||
narrow_message += "\"";
|
||||
dstream<<DTIME<<narrow_message<<std::endl;
|
||||
errorstream<<narrow_message<<std::endl;
|
||||
error_message = narrow_to_wide(narrow_message);
|
||||
}
|
||||
#endif
|
||||
|
@ -1671,7 +1696,7 @@ int main(int argc, char *argv[])
|
|||
*/
|
||||
device->drop();
|
||||
|
||||
END_DEBUG_EXCEPTION_HANDLER
|
||||
END_DEBUG_EXCEPTION_HANDLER(errorstream)
|
||||
|
||||
debugstreams_deinit();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue