2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Jan Olszak <j.olszak@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
22 * @author Jan Olszak (j.olszak@samsung.com)
23 * @brief Main file for the Vasum Daemon
26 // Always log to console in DEBUG mode
27 #if !defined(LOG_TO_CONSOLE) && !defined(NDEBUG)
28 #define LOG_TO_CONSOLE
33 #include "exception.hpp"
36 #include "logger/logger.hpp"
37 #include "logger/backend-stderr.hpp"
38 #include "logger/backend-journal.hpp"
39 #include "utils/typeinfo.hpp"
41 #include <boost/program_options.hpp>
44 using namespace logger;
45 using namespace vasum;
47 namespace po = boost::program_options;
52 const std::string PROGRAM_NAME_AND_VERSION =
53 "Vasum Zones Daemon " PROGRAM_VERSION;
58 int main(int argc, char* argv[])
61 po::options_description desc("Allowed options");
64 ("help,h", "print this help")
65 ("version,v", "show application version")
66 ("log-level,l", po::value<std::string>()->default_value("DEBUG"), "set log level")
70 po::basic_parsed_options< char > parsed =
71 po::command_line_parser(argc, argv).options(desc).allow_unregistered().run();
73 std::vector<std::string> unrecognized_options =
74 po::collect_unrecognized(parsed.options, po::include_positional);
76 if (!unrecognized_options.empty()) {
77 std::cerr << "Unrecognized options: ";
79 for (auto& uo : unrecognized_options) {
80 std::cerr << ' ' << uo;
83 std::cerr << std::endl << std::endl;
84 std::cerr << desc << std::endl;
89 po::store(parsed, vm);
92 if (vm.count("help")) {
93 std::cout << desc << std::endl;
95 } else if (vm.count("version")) {
96 std::cout << PROGRAM_NAME_AND_VERSION << std::endl;
100 Logger::setLogLevel(vm["log-level"].as<std::string>());
101 #ifdef LOG_TO_CONSOLE
102 Logger::setLogBackend(new StderrBackend());
104 Logger::setLogBackend(new SystemdJournalBackend());
108 } catch (std::exception& e) {
109 std::cerr << e.what() << std::endl;
114 zone_daemon::Runner daemon;
117 } catch (std::exception& e) {
118 LOGE("Unexpected: " << utils::getTypeName(e) << ": " << e.what());