Skip to content

Commit de73f98

Browse files
authoredApr 8, 2020
Overall improvements to log messages (#9598)
Hide some unnecessarily verbose ones behind --trace or disable them entirely. Remove duplicate ones. Improve their contents in some places.
1 parent 3494475 commit de73f98

22 files changed

+87
-111
lines changed
 

‎src/client/client.cpp

+28-12
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
6060

6161
extern gui::IGUIEnvironment* guienv;
6262

63+
/*
64+
Utility classes
65+
*/
66+
67+
void PacketCounter::print(std::ostream &o) const
68+
{
69+
for (const auto &it : m_packets) {
70+
auto name = it.first >= TOCLIENT_NUM_MSG_TYPES ? "?"
71+
: toClientCommandTable[it.first].name;
72+
o << "cmd " << it.first << " (" << name << ") count "
73+
<< it.second << std::endl;
74+
}
75+
}
76+
6377
/*
6478
Client
6579
*/
@@ -336,12 +350,12 @@ void Client::step(float dtime)
336350
{
337351
float &counter = m_packetcounter_timer;
338352
counter -= dtime;
339-
if(counter <= 0.0)
353+
if(counter <= 0.0f)
340354
{
341-
counter = 20.0;
355+
counter = 30.0f;
342356

343357
infostream << "Client packetcounter (" << m_packetcounter_timer
344-
<< "):"<<std::endl;
358+
<< "s):"<<std::endl;
345359
m_packetcounter.print(infostream);
346360
m_packetcounter.clear();
347361
}
@@ -621,14 +635,17 @@ void Client::step(float dtime)
621635

622636
m_mod_storage_save_timer -= dtime;
623637
if (m_mod_storage_save_timer <= 0.0f) {
624-
verbosestream << "Saving registered mod storages." << std::endl;
625638
m_mod_storage_save_timer = g_settings->getFloat("server_map_save_interval");
639+
int n = 0;
626640
for (std::unordered_map<std::string, ModMetadata *>::const_iterator
627641
it = m_mod_storages.begin(); it != m_mod_storages.end(); ++it) {
628642
if (it->second->isModified()) {
629643
it->second->save(getModStoragePath());
644+
n++;
630645
}
631646
}
647+
if (n > 0)
648+
infostream << "Saved " << n << " modified mod storages." << std::endl;
632649
}
633650

634651
// Write server map
@@ -653,8 +670,8 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
653670
};
654671
name = removeStringEnd(filename, image_ext);
655672
if (!name.empty()) {
656-
verbosestream<<"Client: Attempting to load image "
657-
<<"file \""<<filename<<"\""<<std::endl;
673+
TRACESTREAM(<< "Client: Attempting to load image "
674+
<< "file \"" << filename << "\"" << std::endl);
658675

659676
io::IFileSystem *irrfs = RenderingEngine::get_filesystem();
660677
video::IVideoDriver *vdrv = RenderingEngine::get_video_driver();
@@ -687,10 +704,9 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
687704
};
688705
name = removeStringEnd(filename, sound_ext);
689706
if (!name.empty()) {
690-
verbosestream<<"Client: Attempting to load sound "
691-
<<"file \""<<filename<<"\""<<std::endl;
692-
m_sound->loadSoundData(name, data);
693-
return true;
707+
TRACESTREAM(<< "Client: Attempting to load sound "
708+
<< "file \"" << filename << "\"" << std::endl);
709+
return m_sound->loadSoundData(name, data);
694710
}
695711

696712
const char *model_ext[] = {
@@ -714,8 +730,8 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
714730
};
715731
name = removeStringEnd(filename, translate_ext);
716732
if (!name.empty()) {
717-
verbosestream << "Client: Loading translation: "
718-
<< "\"" << filename << "\"" << std::endl;
733+
TRACESTREAM(<< "Client: Loading translation: "
734+
<< "\"" << filename << "\"" << std::endl);
719735
g_translations->loadTranslation(data);
720736
return true;
721737
}

‎src/client/client.h

+4-15
Original file line numberDiff line numberDiff line change
@@ -82,30 +82,19 @@ class PacketCounter
8282

8383
void add(u16 command)
8484
{
85-
std::map<u16, u16>::iterator n = m_packets.find(command);
86-
if(n == m_packets.end())
87-
{
85+
auto n = m_packets.find(command);
86+
if (n == m_packets.end())
8887
m_packets[command] = 1;
89-
}
9088
else
91-
{
9289
n->second++;
93-
}
9490
}
9591

9692
void clear()
9793
{
98-
for (auto &m_packet : m_packets) {
99-
m_packet.second = 0;
100-
}
94+
m_packets.clear();
10195
}
10296

103-
void print(std::ostream &o)
104-
{
105-
for (const auto &m_packet : m_packets) {
106-
o << "cmd "<< m_packet.first <<" count "<< m_packet.second << std::endl;
107-
}
108-
}
97+
void print(std::ostream &o) const;
10998

11099
private:
111100
// command, count

‎src/client/content_cao.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -576,9 +576,10 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
576576

577577
m_visuals_expired = false;
578578

579-
if (!m_prop.is_visible) {
579+
if (!m_prop.is_visible)
580580
return;
581-
}
581+
582+
infostream << "GenericCAO::addToScene(): " << m_prop.visual << std::endl;
582583

583584
if (m_enable_shaders) {
584585
IShaderSource *shader_source = m_client->getShaderSource();
@@ -593,7 +594,6 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
593594
}
594595

595596
auto grabMatrixNode = [this] {
596-
infostream << "GenericCAO::addToScene(): " << m_prop.visual << std::endl;
597597
m_matrixnode = RenderingEngine::get_scene_manager()->
598598
addDummyTransformationSceneNode();
599599
m_matrixnode->grab();

‎src/client/fontengine.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ void FontEngine::updateSkin()
239239
FATAL_ERROR_IF(font == NULL, "Could not create/get font");
240240

241241
u32 text_height = font->getDimension(L"Hello, world!").Height;
242-
infostream << "text_height=" << text_height << std::endl;
242+
infostream << "FontEngine: measured text_height=" << text_height << std::endl;
243243
}
244244

245245
/******************************************************************************/

‎src/client/game.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -2010,7 +2010,6 @@ void Game::processItemSelection(u16 *new_playeritem)
20102010
for (u16 i = 0; i <= max_item; i++) {
20112011
if (wasKeyDown((GameKeyType) (KeyType::SLOT_1 + i))) {
20122012
*new_playeritem = i;
2013-
infostream << "Selected item: " << new_playeritem << std::endl;
20142013
break;
20152014
}
20162015
}
@@ -2039,7 +2038,7 @@ void Game::openInventory()
20392038
if (!player || !player->getCAO())
20402039
return;
20412040

2042-
infostream << "the_game: " << "Launching inventory" << std::endl;
2041+
infostream << "Game: Launching inventory" << std::endl;
20432042

20442043
PlayerInventoryFormSource *fs_src = new PlayerInventoryFormSource(client);
20452044

‎src/client/renderingengine.cpp

+2-18
Original file line numberDiff line numberDiff line change
@@ -226,27 +226,17 @@ bool RenderingEngine::setupTopLevelWindow(const std::string &name)
226226
{
227227
// FIXME: It would make more sense for there to be a switch of some
228228
// sort here that would call the correct toplevel setup methods for
229-
// the environment Minetest is running in but for now not deviating
230-
// from the original pattern.
229+
// the environment Minetest is running in.
231230

232231
/* Setting Xorg properties for the top level window */
233232
setupTopLevelXorgWindow(name);
234-
/* Done with Xorg properties */
235233

236234
/* Setting general properties for the top level window */
237235
verbosestream << "Client: Configuring general top level"
238236
<< " window properties"
239237
<< std::endl;
240-
241238
bool result = setWindowIcon();
242239

243-
verbosestream << "Client: Finished configuring general top level"
244-
<< " window properties"
245-
<< std::endl;
246-
/* Done with general properties */
247-
248-
// FIXME: setWindowIcon returns a bool result but it is unused.
249-
// For now continue to return this result.
250240
return result;
251241
}
252242

@@ -262,7 +252,7 @@ void RenderingEngine::setupTopLevelXorgWindow(const std::string &name)
262252
return;
263253
}
264254

265-
verbosestream << "Client: Configuring Xorg specific top level"
255+
verbosestream << "Client: Configuring X11-specific top level"
266256
<< " window properties"
267257
<< std::endl;
268258

@@ -309,8 +299,6 @@ void RenderingEngine::setupTopLevelXorgWindow(const std::string &name)
309299
Atom NET_WM_PID = XInternAtom(x11_dpl, "_NET_WM_PID", false);
310300

311301
pid_t pid = getpid();
312-
infostream << "Client: PID is '" << static_cast<long>(pid) << "'"
313-
<< std::endl;
314302

315303
XChangeProperty(x11_dpl, x11_win, NET_WM_PID,
316304
XA_CARDINAL, 32, PropModeReplace,
@@ -327,10 +315,6 @@ void RenderingEngine::setupTopLevelXorgWindow(const std::string &name)
327315
XChangeProperty (x11_dpl, x11_win, WM_CLIENT_LEADER,
328316
XA_WINDOW, 32, PropModeReplace,
329317
reinterpret_cast<unsigned char *>(&x11_win), 1);
330-
331-
verbosestream << "Client: Finished configuring Xorg specific top level"
332-
<< " window properties"
333-
<< std::endl;
334318
#endif
335319
}
336320

‎src/client/sound_openal.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ SoundBuffer *load_opened_ogg_file(OggVorbis_File *oggFile,
165165
<< "preparing sound buffer" << std::endl;
166166
}
167167

168-
infostream << "Audio file "
169-
<< filename_for_logging << " loaded" << std::endl;
168+
//infostream << "Audio file "
169+
// << filename_for_logging << " loaded" << std::endl;
170170

171171
// Clean up!
172172
ov_clear(oggFile);
@@ -498,9 +498,11 @@ class OpenALSoundManager: public ISoundManager
498498
// Remove stopped sounds
499499
void maintain()
500500
{
501-
verbosestream<<"OpenALSoundManager::maintain(): "
502-
<<m_sounds_playing.size()<<" playing sounds, "
503-
<<m_buffers.size()<<" sound names loaded"<<std::endl;
501+
if (!m_sounds_playing.empty()) {
502+
verbosestream << "OpenALSoundManager::maintain(): "
503+
<< m_sounds_playing.size() <<" playing sounds, "
504+
<< m_buffers.size() <<" sound names loaded"<<std::endl;
505+
}
504506
std::unordered_set<int> del_list;
505507
for (const auto &sp : m_sounds_playing) {
506508
int id = sp.first;
@@ -530,7 +532,7 @@ class OpenALSoundManager: public ISoundManager
530532
SoundBuffer *buf = load_ogg_from_file(filepath);
531533
if (buf)
532534
addBuffer(name, buf);
533-
return false;
535+
return !!buf;
534536
}
535537

536538
bool loadSoundData(const std::string &name,
@@ -539,7 +541,7 @@ class OpenALSoundManager: public ISoundManager
539541
SoundBuffer *buf = load_ogg_from_buffer(filedata, name);
540542
if (buf)
541543
addBuffer(name, buf);
542-
return false;
544+
return !!buf;
543545
}
544546

545547
void updateListener(const v3f &pos, const v3f &vel, const v3f &at, const v3f &up)

‎src/client/tile.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,8 @@ TextureSource::~TextureSource()
471471
driver->removeTexture(t);
472472
}
473473

474-
infostream << "~TextureSource() "<< textures_before << "/"
475-
<< driver->getTextureCount() << std::endl;
474+
infostream << "~TextureSource() before cleanup: "<< textures_before
475+
<< " after: " << driver->getTextureCount() << std::endl;
476476
}
477477

478478
u32 TextureSource::getTextureId(const std::string &name)
@@ -763,6 +763,9 @@ void TextureSource::rebuildImagesAndTextures()
763763
video::IVideoDriver *driver = RenderingEngine::get_video_driver();
764764
sanity_check(driver);
765765

766+
infostream << "TextureSource: recreating " << m_textureinfo_cache.size()
767+
<< " textures" << std::endl;
768+
766769
// Recreate textures
767770
for (TextureInfo &ti : m_textureinfo_cache) {
768771
video::IImage *img = generateImage(ti.name);
@@ -1270,8 +1273,6 @@ bool TextureSource::generateImagePart(std::string part_of_name,
12701273
video::IImage *img = generateImage(filename);
12711274
if (img) {
12721275
core::dimension2d<u32> dim = img->getDimension();
1273-
infostream<<"Size "<<dim.Width
1274-
<<"x"<<dim.Height<<std::endl;
12751276
core::position2d<s32> pos_base(x, y);
12761277
video::IImage *img2 =
12771278
driver->createImage(video::ECF_A8R8G8B8, dim);

‎src/content/subgames.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ std::vector<WorldSpec> getAvailableWorlds()
253253
worldspaths.insert(porting::path_user + DIR_DELIM + "worlds");
254254
infostream << "Searching worlds..." << std::endl;
255255
for (const std::string &worldspath : worldspaths) {
256-
infostream << " In " << worldspath << ": " << std::endl;
256+
infostream << " In " << worldspath << ": ";
257257
std::vector<fs::DirListNode> dirvector = fs::GetDirListing(worldspath);
258258
for (const fs::DirListNode &dln : dirvector) {
259259
if (!dln.dir)

‎src/content_sao.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -711,13 +711,11 @@ float LuaEntitySAO::getMinimumSavedMovement()
711711

712712
std::string LuaEntitySAO::getDescription()
713713
{
714-
std::ostringstream os(std::ios::binary);
715-
os<<"LuaEntitySAO at (";
716-
os<<(m_base_position.X/BS)<<",";
717-
os<<(m_base_position.Y/BS)<<",";
718-
os<<(m_base_position.Z/BS);
719-
os<<")";
720-
return os.str();
714+
std::ostringstream oss;
715+
oss << "LuaEntitySAO \"" << m_init_name << "\" ";
716+
auto pos = floatToInt(m_base_position, BS);
717+
oss << "at " << PP(pos);
718+
return oss.str();
721719
}
722720

723721
void LuaEntitySAO::setHP(s32 hp, const PlayerHPChangeReason &reason)

‎src/craftdef.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1066,8 +1066,8 @@ class CCraftDefManager: public IWritableCraftDefManager
10661066
}
10671067
virtual void registerCraft(CraftDefinition *def, IGameDef *gamedef)
10681068
{
1069-
verbosestream << "registerCraft: registering craft definition: "
1070-
<< def->dump() << std::endl;
1069+
TRACESTREAM(<< "registerCraft: registering craft definition: "
1070+
<< def->dump() << std::endl);
10711071
m_craft_defs[(int) CRAFT_HASH_TYPE_UNHASHED][0].push_back(def);
10721072

10731073
CraftInput input;

‎src/emerge.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ EmergeManager::EmergeManager(Server *server)
136136
nthreads = Thread::getNumberOfProcessors() - 2;
137137
if (nthreads < 1)
138138
nthreads = 1;
139-
verbosestream << "Using " << nthreads << " emerge threads." << std::endl;
140139

141140
m_qlimit_total = g_settings->getU16("emergequeue_limit_total");
142141
if (!g_settings->getU16NoEx("emergequeue_limit_diskonly", m_qlimit_diskonly))

‎src/itemdef.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ class CItemDefManager: public IWritableItemDefManager
463463
}
464464
virtual void registerItem(const ItemDefinition &def)
465465
{
466-
verbosestream<<"ItemDefManager: registering \""<<def.name<<"\""<<std::endl;
466+
TRACESTREAM(<< "ItemDefManager: registering " << def.name << std::endl);
467467
// Ensure that the "" item (the hand) always has ToolCapabilities
468468
if (def.name.empty())
469469
FATAL_ERROR_IF(!def.tool_capabilities, "Hand does not have ToolCapabilities");
@@ -490,8 +490,8 @@ class CItemDefManager: public IWritableItemDefManager
490490
const std::string &convert_to)
491491
{
492492
if (m_item_definitions.find(name) == m_item_definitions.end()) {
493-
verbosestream<<"ItemDefManager: setting alias "<<name
494-
<<" -> "<<convert_to<<std::endl;
493+
TRACESTREAM(<< "ItemDefManager: setting alias " << name
494+
<< " -> " << convert_to << std::endl);
495495
m_aliases[name] = convert_to;
496496
}
497497
}

0 commit comments

Comments
 (0)
Please sign in to comment.