summaryrefslogtreecommitdiffhomepage
path: root/windows/libshared
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2020-01-20 19:03:48 +0100
committerDavid Lönnhager <david.l@mullvad.net>2020-01-20 19:03:48 +0100
commitfeaff7f3e7585f073b241eb87e31740b138dc714 (patch)
tree67353ac90f69ea7bf810c0c7b341f8f77867be4a /windows/libshared
parentb746ee3c93454482d02fb8f64393350a79587b99 (diff)
parenta64020b195a83b0960fe79ff11904c4f35348ec8 (diff)
downloadmullvadvpn-feaff7f3e7585f073b241eb87e31740b138dc714.tar.xz
mullvadvpn-feaff7f3e7585f073b241eb87e31740b138dc714.zip
Merge branch 'win-refactor'
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);
};
}