Skip to content

Commit e63c8c5

Browse files
authored
Merge pull request #292 from microsoft/apilogerrorsnocond
Process plog severity correctly from CLI11 flag
2 parents ae379ec + f560f3d commit e63c8c5

File tree

5 files changed

+40
-15
lines changed

5 files changed

+40
-15
lines changed

src/common/server/NetRemoteServerConfiguration.cxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ ConfigureCliAppOptions(CLI::App& app, NetRemoteServerConfiguration& config)
2727
"The address to listen on for incoming connections");
2828

2929
app.add_flag(
30-
"-v,--verbosity",
31-
config.LogVerbosity,
32-
"The log verbosity level. Supply multiple times to increase verbosity (0=warnings, errors, and fatal messages, 1=info messages, 2=debug messages, 3=verbose messages)");
30+
"-v,--verbosity",
31+
config.LogVerbosity,
32+
"The log verbosity level. Supply multiple times to increase verbosity (0=fatal, 1=errors, 2=warnings, 3=info, 4=debug, 5+=verbose)")
33+
->default_val(NetRemoteServerConfiguration::LogVerbosityDefault);
3334

3435
app.add_flag(
3536
"--enable-file-logging",

src/common/server/include/microsoft/net/remote/service/NetRemoteServerConfiguration.hxx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ namespace Microsoft::Net::Remote::Service
1818
*/
1919
struct NetRemoteServerConfiguration
2020
{
21+
/**
22+
* @brief Default log verbosity.
23+
*/
24+
static constexpr auto LogVerbosityDefault = 3;
25+
2126
/**
2227
* @brief Create a NetRemoteServerConfiguration object from command-line
2328
* arguments.
@@ -52,12 +57,21 @@ struct NetRemoteServerConfiguration
5257
bool RunInBackground{ false };
5358

5459
/**
55-
* @brief How verbose log output should be. The default level is 0, which
56-
* will show all warnings, errors, and fatal messages. A level of 1 will
57-
* show all info messages, and a level of 2 will show all debug messages,
58-
* and a level of 3 or above will show all verbose messages.
60+
* @brief Log verbosity threshold. The default level is 'info' (3) which will print all log messages with verbosity
61+
* level info, warning, error, and fatal.
62+
*
63+
* --------------------
64+
* | level | severity |
65+
* | ----- | -------- |
66+
* | 0 | fatal |
67+
* | 1 | error |
68+
* | 2 | warning |
69+
* | 3 | info |
70+
* | 4 | debug |
71+
* | 5+ | verbose |
72+
* --------------------
5973
*/
60-
uint32_t LogVerbosity{ 0 };
74+
uint32_t LogVerbosity{ LogVerbosityDefault };
6175

6276
/**
6377
* @brief Whether to enable logging to file or not.

src/common/shared/logging/LogUtils.cxx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ logging::LogVerbosityToPlogSeverity(uint32_t verbosity) noexcept
3131
{
3232
switch (verbosity) {
3333
case 0:
34-
return plog::warning;
34+
return plog::fatal;
3535
case 1:
36-
return plog::info;
36+
return plog::error;
3737
case 2:
38-
return plog::debug;
38+
return plog::warning;
3939
case 3:
40+
return plog::info;
41+
case 4:
42+
return plog::debug;
43+
case 5:
4044
default:
4145
return plog::verbose;
4246
}

src/linux/server/Main.cxx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <utility>
1010

1111
#include <logging/LogUtils.hxx>
12+
#include <magic_enum.hpp>
1213
#include <microsoft/net/NetworkManager.hxx>
1314
#include <microsoft/net/NetworkOperationsLinux.hxx>
1415
#include <microsoft/net/remote/service/NetRemoteServer.hxx>
@@ -102,6 +103,8 @@ main(int argc, char *argv[])
102103
plog::init(logSeverity).addAppender(plog::get<std::to_underlying(LogInstanceId::File)>());
103104
}
104105

106+
LOGN << std::format("Netremote server starting (log level={})", magic_enum::enum_name(logSeverity));
107+
105108
// Create an access point manager and discovery agent.
106109
auto accessPointManager = AccessPointManager::Create();
107110
auto accessPointControllerFactory = std::make_unique<AccessPointControllerLinuxFactory>();
@@ -125,7 +128,6 @@ main(int argc, char *argv[])
125128
NetRemoteServer server{ configuration };
126129

127130
// Start the server.
128-
LOGI << "Netremote server starting";
129131
server.Run();
130132

131133
// If running in the background, daemonize the process.
@@ -149,13 +151,13 @@ main(int argc, char *argv[])
149151
});
150152
}
151153

152-
LOGI << "Netremote server stopping";
154+
LOGN << "Netremote server stopping";
153155
auto &grpcServer = server.GetGrpcServer();
154156
grpcServer->Shutdown();
155157
grpcServer->Wait();
156158
}
157159

158-
LOGI << "Netremote server stopped";
160+
LOGN << "Netremote server stopped";
159161

160162
return 0;
161163
}

src/linux/wifi/apmanager/AccessPointDiscoveryAgentOperationsNetlink.cxx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,11 @@ void
272272
AccessPointDiscoveryAgentOperationsNetlink::ProcessNetlinkMessagesThread(NetlinkSocket netlinkSocket, std::stop_token stopToken)
273273
// NOLINTEND(performance-unnecessary-value-param)
274274
{
275+
LOGD << "Netlink message processing thread started";
276+
auto logOnExit = notstd::ScopeExit([] {
277+
LOGD << "Netlink message processing thread stopped";
278+
});
279+
275280
// Disable sequence number checking since it is not required for event notifications.
276281
nl_socket_disable_seq_check(netlinkSocket);
277282

@@ -394,7 +399,6 @@ AccessPointDiscoveryAgentOperationsNetlink::ProcessNetlinkMessagesThread(Netlink
394399
}
395400
}
396401

397-
LOGI << "Netlink message processing thread has exited";
398402
}
399403

400404
/* static */

0 commit comments

Comments
 (0)