Václav Kubernát | 6018f08 | 2021-02-11 01:32:18 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2021 CESNET, https://photonics.cesnet.cz/ |
| 3 | * |
| 4 | * Written by Václav Kubernát <kubernat@cesnet.cz> |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include <docopt.h> |
| 9 | #include "log.h" |
| 10 | |
| 11 | spdlog::level::level_enum parseLogLevel(const std::string& name, const docopt::value& option) |
| 12 | { |
| 13 | long x; |
| 14 | try { |
| 15 | x = option.asLong(); |
| 16 | } catch (std::invalid_argument&) { |
| 17 | throw std::runtime_error(name + " log level: expecting integer"); |
| 18 | } |
| 19 | static_assert(spdlog::level::trace < spdlog::level::off, "spdlog::level levels have changed"); |
| 20 | static_assert(spdlog::level::off == 6, "spdlog::level levels have changed"); |
| 21 | if (x < 0 || x > 5) |
| 22 | throw std::runtime_error(name + " log level invalid or out-of-range"); |
| 23 | |
| 24 | return static_cast<spdlog::level::level_enum>(5 - x); |
| 25 | } |