Skip to content

Commit 115401d

Browse files
Adding ability to set runtime log level
1 parent 019983c commit 115401d

File tree

6 files changed

+55
-14
lines changed

6 files changed

+55
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Builds/
4343
Build/
4444
v0.*/
4545
*.bak
46+
*.runcpp2/
4647
Releases/
4748
Resources/embed
4849
Resources/embed.exe

Include/runcpp2/runcpp2.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace runcpp2
2323
WATCH,
2424
BUILD,
2525
VERSION,
26+
LOG_LEVEL,
2627
COUNT
2728
};
2829

Src/runcpp2/Data/StageInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,8 @@ bool runcpp2::Data::StageInfo::ConstructCommand(const SubstitutionMap& substitut
326326

327327
for(int i = 0; i < currentRunParts.size(); ++i)
328328
{
329-
ssLOG_INFO("Parsing run part at index: " << i);
330-
ssLOG_INFO("Which is: \"" << currentRunParts.at(i).CommandPart << "\"");
329+
ssLOG_DEBUG("Parsing run part at index: " << i);
330+
ssLOG_DEBUG("Which is: \"" << currentRunParts.at(i).CommandPart << "\"");
331331

332332
std::string currentEscapedPart;
333333
std::vector<std::string> substitutionsInCurrentPart;

Src/runcpp2/PlatformUtil.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@ bool runcpp2::RunCommandAndGetOutput( const std::string& command,
118118
return false;
119119
}
120120

121+
ssLOG_DEBUG("outOutput: \n" << outOutput.c_str());
122+
121123
if(outReturnCode != 0)
122124
{
123-
ssLOG_DEBUG("Failed when running command");
124-
ssLOG_DEBUG("outOutput: \n" << outOutput.c_str());
125+
ssLOG_DEBUG("Failed when running command with return code: " << outReturnCode);
125126
return false;
126127
}
127128

Src/runcpp2/main.cpp

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,13 @@ bool GenerateScriptTemplate(const std::string& outputFilePathStr)
169169

170170
int main(int argc, char* argv[])
171171
{
172+
ssLOG_SET_CURRENT_THREAD_TARGET_LEVEL(ssLOG_LEVEL_WARNING);
173+
172174
//Parse command line options
173175
int currentArgIndex = 0;
174176
std::unordered_map<runcpp2::CmdOptions, std::string> currentOptions;
175-
176177
{
177-
static_assert(static_cast<int>(runcpp2::CmdOptions::COUNT) == 12, "Update this");
178+
static_assert(static_cast<int>(runcpp2::CmdOptions::COUNT) == 13, "Update this");
178179
std::unordered_map<std::string, runcpp2::OptionInfo> longOptionsMap =
179180
{
180181
{
@@ -220,10 +221,14 @@ int main(int argc, char* argv[])
220221
{
221222
"--version",
222223
runcpp2::OptionInfo(runcpp2::CmdOptions::VERSION, false)
224+
},
225+
{
226+
"--log-level",
227+
runcpp2::OptionInfo(runcpp2::CmdOptions::LOG_LEVEL, true)
223228
}
224229
};
225230

226-
static_assert(static_cast<int>(runcpp2::CmdOptions::COUNT) == 12, "Update this");
231+
static_assert(static_cast<int>(runcpp2::CmdOptions::COUNT) == 13, "Update this");
227232
std::unordered_map<std::string, const runcpp2::OptionInfo&> shortOptionsMap =
228233
{
229234
{"-r", longOptionsMap.at("--reset-cache")},
@@ -253,7 +258,7 @@ int main(int argc, char* argv[])
253258
//Help message
254259
if(currentOptions.count(runcpp2::CmdOptions::HELP))
255260
{
256-
static_assert(static_cast<int>(runcpp2::CmdOptions::COUNT) == 12, "Update this");
261+
static_assert(static_cast<int>(runcpp2::CmdOptions::COUNT) == 13, "Update this");
257262
ssLOG_BASE("Usage: runcpp2 [options] [input_file]");
258263
ssLOG_BASE("Options:");
259264
ssLOG_BASE(" -r, --[r]eset-cache Deletes all cache and build everything from scratch");
@@ -266,11 +271,33 @@ int main(int argc, char* argv[])
266271
ssLOG_BASE(" -t, --create-script-[t]emplate <file> Creates/prepend runcpp2 script info template");
267272
ssLOG_BASE(" -w, --[w]atch Watch script changes and output any compiling errors");
268273
ssLOG_BASE(" -b, --[b]uild Build the script and copy output files to the working directory");
269-
ssLOG_BASE(" -v, --[v]ersion Show the version of runcpp2");
274+
ssLOG_BASE(" -v, --[v]ersion Show the version of runcpp2");
275+
ssLOG_BASE(" --log-level <level> Sets the log level (Normal, Info, Debug) for runcpp2.");
270276

271277
return 0;
272278
}
273279

280+
//Set Log level
281+
if(currentOptions.count(runcpp2::CmdOptions::LOG_LEVEL))
282+
{
283+
std::string level = currentOptions.at(runcpp2::CmdOptions::LOG_LEVEL);
284+
runcpp2::Trim(level);
285+
for(int i = 0; i < level.size(); ++i)
286+
level[i] = std::tolower(level[i]);
287+
288+
if(level == "info")
289+
ssLOG_SET_CURRENT_THREAD_TARGET_LEVEL(ssLOG_LEVEL_INFO);
290+
else if(level == "debug")
291+
ssLOG_SET_CURRENT_THREAD_TARGET_LEVEL(ssLOG_LEVEL_DEBUG);
292+
else if(level == "normal")
293+
ssLOG_SET_CURRENT_THREAD_TARGET_LEVEL(ssLOG_LEVEL_WARNING);
294+
else
295+
{
296+
ssLOG_ERROR("Invalid level: " << level);
297+
return -1;
298+
}
299+
}
300+
274301
//Show user config path
275302
if(currentOptions.count(runcpp2::CmdOptions::SHOW_USER_CONFIG))
276303
{
@@ -294,7 +321,7 @@ int main(int argc, char* argv[])
294321
ssLOG_ERROR("Failed reset user config");
295322
return -1;
296323
}
297-
324+
ssLOG_BASE("User config reset successful");
298325
return 0;
299326
}
300327

@@ -304,7 +331,10 @@ int main(int argc, char* argv[])
304331
if(!GenerateScriptTemplate(currentOptions.at(runcpp2::CmdOptions::SCRIPT_TEMPLATE)))
305332
return -1;
306333
else
334+
{
335+
ssLOG_BASE("Script template generated");
307336
return 0;
337+
}
308338
}
309339

310340
std::vector<runcpp2::Data::Profile> profiles;
@@ -388,17 +418,19 @@ int main(int argc, char* argv[])
388418
return -1;
389419

390420
case runcpp2::PipelineResult::UNEXPECTED_FAILURE:
391-
case runcpp2::PipelineResult::SUCCESS:
392421
case runcpp2::PipelineResult::INVALID_BUILD_DIR:
393422
case runcpp2::PipelineResult::INVALID_SCRIPT_INFO:
394423
case runcpp2::PipelineResult::NO_AVAILABLE_PROFILE:
395424
case runcpp2::PipelineResult::DEPENDENCIES_FAILED:
396425
case runcpp2::PipelineResult::COMPILE_LINK_FAILED:
397426
case runcpp2::PipelineResult::INVALID_PROFILE:
398427
case runcpp2::PipelineResult::RUN_SCRIPT_FAILED:
428+
ssLOG_BASE("Watching...");
429+
break;
430+
case runcpp2::PipelineResult::SUCCESS:
431+
ssLOG_BASE("No error. Watching...");
399432
break;
400433
}
401-
ssLOG_BASE("No error. Watching...");
402434
}
403435

404436
lastScriptWriteTime = ghc::filesystem::last_write_time(script, e);

Src/runcpp2/runcpp2.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,14 @@ namespace
264264

265265
if(compileFiles == nullptr)
266266
{
267-
ssLOG_ERROR("Failed to get compile files for current platform");
268-
return false;
267+
ssLOG_INFO("No other files to be compiled files current platform");
268+
269+
if(!scriptInfo.OtherFilesToBeCompiled.empty())
270+
{
271+
ssLOG_WARNING( "Other source files are present, "
272+
"but none are included for current configuration. Is this intended?");
273+
}
274+
return true;
269275
}
270276

271277
std::string foundProfileName;

0 commit comments

Comments
 (0)