Skip to content

Commit

Permalink
Merge pull request #310 from microsoft/user/corbinphipps/setup-audit-log
Browse files Browse the repository at this point in the history
Setup skeleton audit log
  • Loading branch information
abeltrano authored Jul 15, 2024
2 parents ee6cc1f + 4351cc6 commit a0c7540
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
15 changes: 15 additions & 0 deletions src/common/shared/logging/include/logging/LogUtils.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@

#include <plog/Severity.h>

enum class LogInstanceId : int {
// Default logger is 0 and is omitted from this enumeration.
Console = 1,
File = 2,
Audit = 3,
};

#define AUDITN LOG_(static_cast<int>(LogInstanceId::Audit), plog::none)
#define AUDITF LOG_(static_cast<int>(LogInstanceId::Audit), plog::fatal)
#define AUDITE LOG_(static_cast<int>(LogInstanceId::Audit), plog::error)
#define AUDITW LOG_(static_cast<int>(LogInstanceId::Audit), plog::warning)
#define AUDITI LOG_(static_cast<int>(LogInstanceId::Audit), plog::info)
#define AUDITD LOG_(static_cast<int>(LogInstanceId::Audit), plog::debug)
#define AUDITV LOG_(static_cast<int>(LogInstanceId::Audit), plog::verbose)

namespace logging
{
/**
Expand Down
17 changes: 10 additions & 7 deletions src/linux/server/Main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ using namespace Microsoft::Net::Remote;
using namespace Microsoft::Net::Remote::Service;
using namespace Microsoft::Net::Wifi;

enum class LogInstanceId : int {
// Default logger is 0 and is omitted from this enumeration.
Console = 1,
File = 2,
};

namespace
{
/**
Expand Down Expand Up @@ -89,7 +83,14 @@ main(int argc, char *argv[])

// Create file and console log appenders.
static plog::ColorConsoleAppender<plog::MessageOnlyFormatter> colorConsoleAppender{};
static plog::RollingFileAppender<plog::TxtFormatter> rollingFileAppender(logging::GetLogName("server").c_str());
std::string logFilePath = "/var/log/";
logFilePath += logging::GetLogName("server");
static plog::RollingFileAppender<plog::TxtFormatter> rollingFileAppender(logFilePath.c_str());

// Create the audit log file appender.
std::string auditLogFilePath = "/var/log/";
auditLogFilePath += logging::GetLogName("audit");
static plog::RollingFileAppender<plog::TxtFormatter> auditLogRollingFileAppender(auditLogFilePath.c_str());

// Parse command line arguments.
auto configuration = NetRemoteServerConfiguration::FromCommandLineArguments(argc, argv);
Expand All @@ -102,8 +103,10 @@ main(int argc, char *argv[])
plog::init<std::to_underlying(LogInstanceId::File)>(logSeverity, &rollingFileAppender);
plog::init(logSeverity).addAppender(plog::get<std::to_underlying(LogInstanceId::File)>());
}
plog::init<std::to_underlying(LogInstanceId::Audit)>(logSeverity, &auditLogRollingFileAppender);

LOGN << std::format("Netremote server starting (log level={})", magic_enum::enum_name(logSeverity));
AUDITN << std::format("Netremote server starting (log level={})", magic_enum::enum_name(logSeverity));

// Create an access point manager and discovery agent.
auto accessPointManager = AccessPointManager::Create();
Expand Down

0 comments on commit a0c7540

Please sign in to comment.