summaryrefslogtreecommitdiffhomepage
path: root/windows/libshared
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2020-01-20 13:29:21 +0100
committerDavid Lönnhager <david.l@mullvad.net>2020-01-20 17:04:56 +0100
commite6ea3bd0d617a91645d96e89459f988bd67b4117 (patch)
treefe7fa25de9f95c66b1da8e2730fdfcb253f6cd31 /windows/libshared
parentc0833b0589424bf21e14afec6b57ab742886a763 (diff)
downloadmullvadvpn-e6ea3bd0d617a91645d96e89459f988bd67b4117.tar.xz
mullvadvpn-e6ea3bd0d617a91645d96e89459f988bd67b4117.zip
Refactor ValueMapper
Diffstat (limited to 'windows/libshared')
-rw-r--r--windows/libshared/src/libshared/logging/logsinkadapter.cpp32
1 files changed, 9 insertions, 23 deletions
diff --git a/windows/libshared/src/libshared/logging/logsinkadapter.cpp b/windows/libshared/src/libshared/logging/logsinkadapter.cpp
index f506aba096..03244cb423 100644
--- a/windows/libshared/src/libshared/logging/logsinkadapter.cpp
+++ b/windows/libshared/src/libshared/logging/logsinkadapter.cpp
@@ -1,4 +1,5 @@
#include "stdafx.h"
+#include <libcommon/valuemapper.h>
#include "logsinkadapter.h"
namespace shared::logging
@@ -19,30 +20,15 @@ common::logging::LogTarget LogSinkAdapter::MakeAdapter(MullvadLogSink target, vo
return;
}
- //
- // TODO: Replace manual mapping with ValueMapper once the updated
- // ValueMapper reaches libcommon.
- //
+ const std::optional<MULLVAD_LOG_LEVEL> translatedLevel = common::ValueMapper::TryMap<>(level, {
+ std::make_pair(common::logging::LogLevel::Warning, MULLVAD_LOG_LEVEL_WARNING),
+ std::make_pair(common::logging::LogLevel::Info, MULLVAD_LOG_LEVEL_INFO),
+ std::make_pair(common::logging::LogLevel::Trace, MULLVAD_LOG_LEVEL_TRACE),
+ std::make_pair(common::logging::LogLevel::Debug, MULLVAD_LOG_LEVEL_DEBUG),
+ std::make_pair(common::logging::LogLevel::Error, MULLVAD_LOG_LEVEL_ERROR),
+ });
- const MULLVAD_LOG_LEVEL translatedLevel = [level]()
- {
- switch (level)
- {
- case common::logging::LogLevel::Warning:
- return MULLVAD_LOG_LEVEL_WARNING;
- case common::logging::LogLevel::Info:
- return MULLVAD_LOG_LEVEL_INFO;
- case common::logging::LogLevel::Trace:
- return MULLVAD_LOG_LEVEL_TRACE;
- case common::logging::LogLevel::Debug:
- return MULLVAD_LOG_LEVEL_DEBUG;
- case common::logging::LogLevel::Error:
- default:
- return MULLVAD_LOG_LEVEL_ERROR;
- }
- }();
-
- target(translatedLevel, msg, context);
+ target(translatedLevel.value_or(MULLVAD_LOG_LEVEL_ERROR), msg, context);
};
}