Skip to content

Commit 2aadd5d

Browse files
committed
Use log_* functions for tools
Replace all remaining uses of `dbg_msg` function in tools with `log_*` functions. Add and consistently use `TOOL_NAME` constant for each tool.
1 parent 54e695b commit 2aadd5d

21 files changed

Lines changed: 165 additions & 151 deletions

‎src/tools/config_common.h‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <base/dbg.h>
21
#include <base/fs.h>
32
#include <base/logger.h>
43
#include <base/os.h>
@@ -19,20 +18,20 @@ inline void ProcessItem(const char *pItemName, IStorage *pStorage)
1918
size_t Len = (size_t)str_length(pItemName) + 1; // including '\0'
2019
if(Len > sizeof(aConfig))
2120
{
22-
dbg_msg("config_common", "can't process overlong filename '%s'", pItemName);
21+
log_error(TOOL_NAME, "can't process overlong filename '%s'", pItemName);
2322
return;
2423
}
2524

2625
if(!str_endswith(pItemName, ".map"))
2726
{
28-
dbg_msg("config_common", "can't process non-map file '%s'", pItemName);
27+
log_error(TOOL_NAME, "can't process non-map file '%s'", pItemName);
2928
return;
3029
}
3130

3231
str_copy(aConfig, pItemName);
3332
aConfig[Len - sizeof(".map")] = 0;
3433
str_append(aConfig, ".cfg");
35-
dbg_msg("config_common", "processing '%s'", pItemName);
34+
log_info(TOOL_NAME, "processing '%s'", pItemName);
3635
Process(pStorage, pItemName, aConfig);
3736
}
3837

@@ -57,14 +56,14 @@ int main(int argc, const char **argv) // NOLINT(misc-definitions-in-headers)
5756
std::unique_ptr<IStorage> pStorage = CreateLocalStorage();
5857
if(!pStorage)
5958
{
60-
log_error("config_common", "Error creating local storage");
59+
log_error(TOOL_NAME, "Error creating local storage");
6160
return -1;
6261
}
6362

6463
if(argc == 1)
6564
{
66-
dbg_msg("usage", "%s FILE1 [ FILE2... ]", argv[0]);
67-
dbg_msg("usage", "%s DIRECTORY", argv[0]);
65+
log_error(TOOL_NAME, "Usage: %s FILE1 [ FILE2... ]", argc > 0 ? argv[0] : TOOL_NAME);
66+
log_error(TOOL_NAME, "Usage: %s DIRECTORY", argc > 0 ? argv[0] : TOOL_NAME);
6867
return -1;
6968
}
7069
else if(argc == 2 && fs_is_dir(argv[1]))

‎src/tools/config_retrieve.cpp‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
#include <base/dbg.h>
21
#include <base/fs.h>
32
#include <base/io.h>
3+
#include <base/log.h>
44
#include <base/str.h>
55

66
#include <engine/shared/datafile.h>
77
#include <engine/storage.h>
88

99
#include <game/mapitems.h>
1010

11+
static constexpr const char *const TOOL_NAME = "config_retrieve";
12+
1113
static void Process(IStorage *pStorage, const char *pMapName, const char *pConfigName)
1214
{
1315
CDataFileReader Reader;
1416
if(!Reader.Open(pStorage, pMapName, IStorage::TYPE_ABSOLUTE))
1517
{
16-
dbg_msg("config_retrieve", "error opening map '%s'", pMapName);
18+
log_error(TOOL_NAME, "Failed to open map '%s' for reading", pMapName);
1719
return;
1820
}
1921
bool ConfigFound = false;
@@ -36,7 +38,7 @@ static void Process(IStorage *pStorage, const char *pMapName, const char *pConfi
3638
IOHANDLE Config = pStorage->OpenFile(pConfigName, IOFLAG_WRITE, IStorage::TYPE_ABSOLUTE);
3739
if(!Config)
3840
{
39-
dbg_msg("config_retrieve", "error opening config for writing '%s'", pConfigName);
41+
log_error(TOOL_NAME, "Failed to open config '%s' for writing", pConfigName);
4042
Reader.Close();
4143
return;
4244
}

‎src/tools/config_store.cpp‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
#include <algorithm>
1313
#include <vector>
1414

15+
static constexpr const char *const TOOL_NAME = "config_store";
16+
1517
static void Process(IStorage *pStorage, const char *pMapName, const char *pConfigName)
1618
{
1719
CLineReader LineReader;
1820
if(!LineReader.OpenFile(pStorage->OpenFile(pConfigName, IOFLAG_READ, IStorage::TYPE_ABSOLUTE)))
1921
{
20-
log_error("config_store", "Failed to import settings from '%s': could not open config for reading", pConfigName);
22+
log_error(TOOL_NAME, "Failed to import settings from '%s': failed to open config for reading", pConfigName);
2123
return;
2224
}
2325

@@ -32,7 +34,7 @@ static void Process(IStorage *pStorage, const char *pMapName, const char *pConfi
3234
CDataFileReader Reader;
3335
if(!Reader.Open(pStorage, pMapName, IStorage::TYPE_ABSOLUTE))
3436
{
35-
log_error("config_store", "Failed to import settings from '%s': failed to open map '%s' for reading", pConfigName, pMapName);
37+
log_error(TOOL_NAME, "Failed to import settings from '%s': failed to open map '%s' for reading", pConfigName, pMapName);
3638
return;
3739
}
3840

@@ -71,7 +73,7 @@ static void Process(IStorage *pStorage, const char *pMapName, const char *pConfi
7173
int DataSize = Reader.GetDataSize(SettingsIndex);
7274
if(DataSize == TotalLength && mem_comp(pSettings, pMapSettings, DataSize) == 0)
7375
{
74-
log_info("config_store", "Configs coincide, not updating map");
76+
log_info(TOOL_NAME, "Configs coincide, not updating map");
7577
free(pSettings);
7678
return;
7779
}
@@ -125,10 +127,10 @@ static void Process(IStorage *pStorage, const char *pMapName, const char *pConfi
125127
Reader.Close();
126128
if(!Writer.Open(pStorage, pMapName))
127129
{
128-
log_error("config_store", "Failed to import settings from '%s': failed to open map '%s' for writing", pConfigName, pMapName);
130+
log_error(TOOL_NAME, "Failed to import settings from '%s': failed to open map '%s' for writing", pConfigName, pMapName);
129131
return;
130132
}
131133
Writer.Finish();
132-
log_info("config_store", "Imported settings from '%s' into '%s'", pConfigName, pMapName);
134+
log_info(TOOL_NAME, "Imported settings from '%s' into '%s'", pConfigName, pMapName);
133135
}
134136
#include "config_common.h"

‎src/tools/crapnet.cpp‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
22
/* If you are missing that file, acquire a complete release at teeworlds.com. */
3-
#include <base/dbg.h>
3+
44
#include <base/logger.h>
55
#include <base/mem.h>
66
#include <base/net.h>
@@ -11,6 +11,8 @@
1111
#include <iterator> // std::size
1212
#include <thread>
1313

14+
static constexpr const char *const TOOL_NAME = "crapnet";
15+
1416
struct SPacket
1517
{
1618
SPacket *m_pPrev;
@@ -64,7 +66,7 @@ static void Run(unsigned short Port, NETADDR Dest)
6466
SPingConfig Ping = g_aConfigPings[n];
6567

6668
if(n != s_Lastcfg)
67-
dbg_msg("crapnet", "cfg = %d", n);
69+
log_info(TOOL_NAME, "cfg = %d", n);
6870
s_Lastcfg = n;
6971

7072
// handle incoming packets
@@ -81,7 +83,7 @@ static void Run(unsigned short Port, NETADDR Dest)
8183
if((rand() % 100) < Ping.m_Loss) // drop the packet
8284
{
8385
if(g_ConfigLog)
84-
dbg_msg("crapnet", "dropped packet");
86+
log_info(TOOL_NAME, "dropped packet");
8587
continue;
8688
}
8789

@@ -137,7 +139,7 @@ static void Run(unsigned short Port, NETADDR Dest)
137139
{
138140
char aAddrStr[NETADDR_MAXSTRSIZE];
139141
net_addr_str(&From, aAddrStr, sizeof(aAddrStr), true);
140-
dbg_msg("crapnet", "<< %08d %s (%d)", p->m_Id, aAddrStr, p->m_DataSize);
142+
log_info(TOOL_NAME, "<< %08d %s (%d)", p->m_Id, aAddrStr, p->m_DataSize);
141143
}
142144
}
143145

@@ -189,7 +191,7 @@ static void Run(unsigned short Port, NETADDR Dest)
189191
{
190192
char aAddrStr[NETADDR_MAXSTRSIZE];
191193
net_addr_str(&p->m_SendTo, aAddrStr, sizeof(aAddrStr), true);
192-
dbg_msg("crapnet", ">> %08d %s (%d) %s", p->m_Id, aAddrStr, p->m_DataSize, aFlags);
194+
log_info(TOOL_NAME, ">> %08d %s (%d) %s", p->m_Id, aAddrStr, p->m_DataSize, aFlags);
193195
}
194196

195197
free(p);

‎src/tools/demo_extract_chat.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#include <memory>
1717

18-
static const char *TOOL_NAME = "demo_extract_chat";
18+
static constexpr const char *const TOOL_NAME = "demo_extract_chat";
1919

2020
class CClientSnapshotHandler
2121
{
@@ -282,7 +282,7 @@ int main(int argc, const char *argv[])
282282

283283
if(argc != 2)
284284
{
285-
log_error(TOOL_NAME, "Usage: %s <demo_filename>", TOOL_NAME);
285+
log_error(TOOL_NAME, "Usage: %s <demo_filename>", argc > 0 ? argv[0] : TOOL_NAME);
286286
return -1;
287287
}
288288

‎src/tools/dilate.cpp‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <engine/gfx/image_loader.h>
1010
#include <engine/gfx/image_manipulation.h>
1111

12+
static constexpr const char *const TOOL_NAME = "dilate";
13+
1214
static bool DilateFile(const char *pFilename, bool DryRun)
1315
{
1416
CImageInfo Image;
@@ -18,7 +20,7 @@ static bool DilateFile(const char *pFilename, bool DryRun)
1820

1921
if(Image.m_Format != CImageInfo::FORMAT_RGBA)
2022
{
21-
log_error("dilate", "ERROR: only RGBA PNG images are supported");
23+
log_error(TOOL_NAME, "Only RGBA PNG images are supported");
2224
Image.Free();
2325
return false;
2426
}
@@ -30,7 +32,7 @@ static bool DilateFile(const char *pFilename, bool DryRun)
3032
const bool EqualImages = Image.DataEquals(OldImage);
3133
Image.Free();
3234
OldImage.Free();
33-
log_info("dilate", "'%s' is %sdilated", pFilename, EqualImages ? "" : "NOT ");
35+
log_info(TOOL_NAME, "'%s' is %sdilated", pFilename, EqualImages ? "" : "NOT ");
3436
return EqualImages;
3537
}
3638
else
@@ -49,14 +51,14 @@ int main(int argc, const char **argv)
4951

5052
if(argc == 1)
5153
{
52-
log_error("dilate", "Usage: %s [--dry-run] <image1.png> [<image2.png> ...]", argv[0]);
54+
log_error(TOOL_NAME, "Usage: %s [--dry-run] <image1.png> [<image2.png> ...]", argc > 0 ? argv[0] : TOOL_NAME);
5355
return -1;
5456
}
5557

5658
const bool DryRun = str_comp(argv[1], "--dry-run") == 0;
5759
if(DryRun && argc < 3)
5860
{
59-
log_error("dilate", "Usage: %s [--dry-run] <image1.png> [<image2.png> ...]", argv[0]);
61+
log_error(TOOL_NAME, "Usage: %s [--dry-run] <image1.png> [<image2.png> ...]", argc > 0 ? argv[0] : TOOL_NAME);
6062
return -1;
6163
}
6264

‎src/tools/dummy_map.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <base/dbg.h>
21
#include <base/hash.h>
32
#include <base/logger.h>
43
#include <base/os.h>
@@ -11,7 +10,7 @@
1110

1211
#include <zlib.h>
1312

14-
static const char *TOOL_NAME = "dummy_map";
13+
static constexpr const char *const TOOL_NAME = "dummy_map";
1514

1615
static void CreateEmptyMap(IStorage *pStorage)
1716
{

‎src/tools/map_convert_07.cpp‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* (c) DDNet developers. See licence.txt in the root of the distribution for more information. */
22
/* If you are missing that file, acquire a complete release at teeworlds.com. */
33

4-
#include <base/dbg.h>
54
#include <base/fs.h>
65
#include <base/io.h>
76
#include <base/logger.h>
@@ -17,9 +16,7 @@
1716

1817
#include <utility>
1918

20-
/*
21-
Usage: map_convert_07 <source map filepath> <dest map filepath>
22-
*/
19+
static constexpr const char *const TOOL_NAME = "map_convert_07";
2320

2421
static CDataFileReader g_DataReader;
2522
static CDataFileWriter g_DataWriter;
@@ -59,7 +56,7 @@ static bool CheckImageDimensions(void *pLayerItem, int LayerType, const char *pF
5956
IntsToStr(pTMap->m_aName, std::size(pTMap->m_aName), aTileLayerName, std::size(aTileLayerName));
6057

6158
const char *pName = g_DataReader.GetDataString(pImgItem->m_ImageName);
62-
dbg_msg("map_convert_07", "%s: Tile layer \"%s\" uses image \"%s\" with width %d, height %d, which is not divisible by 16. This is not supported in Teeworlds 0.7. Please scale the image and replace it manually.", pFilename, aTileLayerName, pName == nullptr ? "(error)" : pName, pImgItem->m_Width, pImgItem->m_Height);
59+
log_error(TOOL_NAME, "%s: Tile layer \"%s\" uses image \"%s\" with width %d, height %d, which is not divisible by 16. This is not supported in Teeworlds 0.7. Please scale the image and replace it manually.", pFilename, aTileLayerName, pName == nullptr ? "(error)" : pName, pImgItem->m_Width, pImgItem->m_Height);
6360
return false;
6461
}
6562

@@ -71,11 +68,11 @@ static void *ReplaceImageItem(int Index, CMapItemImage *pImgItem, CMapItemImage
7168
const char *pName = g_DataReader.GetDataString(pImgItem->m_ImageName);
7269
if(pName == nullptr || pName[0] == '\0')
7370
{
74-
dbg_msg("map_convert_07", "failed to load name of image %d", Index);
71+
log_error(TOOL_NAME, "failed to load name of image %d", Index);
7572
return pImgItem;
7673
}
7774

78-
dbg_msg("map_convert_07", "embedding image '%s'", pName);
75+
log_info(TOOL_NAME, "embedding image '%s'", pName);
7976

8077
char aStr[IO_MAX_PATH_LENGTH];
8178
str_format(aStr, sizeof(aStr), "data/mapres/%s.png", pName);
@@ -88,7 +85,7 @@ static void *ReplaceImageItem(int Index, CMapItemImage *pImgItem, CMapItemImage
8885
const size_t MaxImageDimension = 1 << 13;
8986
if(ImgInfo.m_Format != CImageInfo::FORMAT_RGBA || ImgInfo.m_Width > MaxImageDimension || ImgInfo.m_Height > MaxImageDimension)
9087
{
91-
dbg_msg("map_convert_07", "ERROR: only RGBA PNG images with maximum width/height %" PRIzu " are supported", MaxImageDimension);
88+
log_error(TOOL_NAME, "only RGBA PNG images with maximum width/height %" PRIzu " are supported", MaxImageDimension);
9289
ImgInfo.Free();
9390
return pImgItem;
9491
}
@@ -113,15 +110,15 @@ int main(int argc, const char **argv)
113110

114111
if(argc < 2 || argc > 3)
115112
{
116-
dbg_msg("map_convert_07", "Invalid arguments");
117-
dbg_msg("map_convert_07", "Usage: map_convert_07 <source map filepath> [<dest map filepath>]");
113+
log_error(TOOL_NAME, "Invalid arguments");
114+
log_error(TOOL_NAME, "Usage: %s <source map filepath> [<dest map filepath>]", argc > 0 ? argv[0] : TOOL_NAME);
118115
return -1;
119116
}
120117

121118
std::unique_ptr<IStorage> pStorage = std::unique_ptr<IStorage>(CreateStorage(IStorage::EInitializationType::BASIC, argc, argv));
122119
if(!pStorage)
123120
{
124-
log_error("map_convert_07", "Error creating basic storage");
121+
log_error(TOOL_NAME, "Error creating basic storage");
125122
return -1;
126123
}
127124

@@ -139,26 +136,26 @@ int main(int argc, const char **argv)
139136
str_format(aDestFilename, sizeof(aDestFilename), "data/maps7/%s.map", aBuf);
140137
if(fs_makedir("data") != 0)
141138
{
142-
dbg_msg("map_convert_07", "failed to create data directory");
139+
log_error(TOOL_NAME, "failed to create data directory");
143140
return -1;
144141
}
145142

146143
if(fs_makedir("data/maps7") != 0)
147144
{
148-
dbg_msg("map_convert_07", "failed to create data/maps7 directory");
145+
log_error(TOOL_NAME, "failed to create data/maps7 directory");
149146
return -1;
150147
}
151148
}
152149

153150
if(!g_DataReader.Open(pStorage.get(), pSourceFilename, IStorage::TYPE_ABSOLUTE))
154151
{
155-
dbg_msg("map_convert_07", "failed to open source map. filename='%s'", pSourceFilename);
152+
log_error(TOOL_NAME, "failed to open source map. filename='%s'", pSourceFilename);
156153
return -1;
157154
}
158155

159156
if(!g_DataWriter.Open(pStorage.get(), aDestFilename, IStorage::TYPE_ABSOLUTE))
160157
{
161-
dbg_msg("map_convert_07", "failed to open destination map. filename='%s'", aDestFilename);
158+
log_error(TOOL_NAME, "failed to open destination map. filename='%s'", aDestFilename);
162159
return -1;
163160
}
164161

@@ -173,7 +170,7 @@ int main(int argc, const char **argv)
173170
{
174171
if(i >= MAX_MAPIMAGES)
175172
{
176-
dbg_msg("map_convert_07", "map uses more images than the client maximum of %" PRIzu ". filename='%s'", MAX_MAPIMAGES, pSourceFilename);
173+
log_warn(TOOL_NAME, "map uses more images than the client maximum of %" PRIzu ". filename='%s'", MAX_MAPIMAGES, pSourceFilename);
177174
break;
178175
}
179176
g_aImageIds[i] = Index;

0 commit comments

Comments
 (0)