Skip to content

Commit c1ac864

Browse files
PetarKirovmonyarm
authored andcommitted
feat(mcl): Allow adjusting the loglevel with via command-line args
1 parent d2cf3d2 commit c1ac864

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

packages/mcl/src/main.d

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import std.stdio : writefln, writeln, stderr;
22
import std.array : replace;
33
import std.getopt : getopt;
4-
import std.logger : info, errorf;
4+
import std.logger : info, errorf, LogLevel;
55

66
import cmds = mcl.commands;
77

@@ -22,10 +22,10 @@ int main(string[] args)
2222
return wrongUsage("no command selected");
2323

2424
string command = args[1];
25-
bool quiet = false;
26-
args.getopt("q|quiet", &quiet);
25+
LogLevel logLevel = LogLevel.info;
26+
args.getopt("log-level", &logLevel);
2727

28-
if (quiet) disableLogging();
28+
setLogLevel(logLevel);
2929

3030
try switch (args[1])
3131
{
@@ -50,10 +50,11 @@ int main(string[] args)
5050
}
5151
}
5252

53-
void disableLogging()
53+
void setLogLevel(LogLevel l)
5454
{
55-
import std.logger : sharedLog, LogLevel, NullLogger;
56-
sharedLog = cast(shared)new NullLogger(LogLevel.all);
55+
import std.logger : globalLogLevel, sharedLog;
56+
globalLogLevel = l;
57+
(cast()sharedLog()).logLevel = l;
5758
}
5859

5960
int wrongUsage(string error)

0 commit comments

Comments
 (0)