blob: 41cae15d2ba9be9d8e8cc830d934fc8d7d81d52f [file] [log] [blame]
Alexander Afanasyeva8d404b2016-11-05 10:07:08 -06001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2016 Regents of the University of California.
4 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#include "ndn-cxx-custom-logger.hpp"
23#include "ndn-cxx-custom-logging.hpp"
24
25#include <cinttypes>
26#include <stdio.h>
27#include <type_traits>
28
29namespace ndn {
30namespace util {
31
32std::ostream&
33operator<<(std::ostream& os, LogLevel level)
34{
35 switch (level) {
36 case LogLevel::FATAL:
37 return os << "FATAL";
38 case LogLevel::NONE:
39 return os << "NONE";
40 case LogLevel::ERROR:
41 return os << "ERROR";
42 case LogLevel::WARN:
43 return os << "WARN";
44 case LogLevel::INFO:
45 return os << "INFO";
46 case LogLevel::DEBUG:
47 return os << "DEBUG";
48 case LogLevel::TRACE:
49 return os << "TRACE";
50 case LogLevel::ALL:
51 return os << "ALL";
52 }
53
54 BOOST_THROW_EXCEPTION(std::invalid_argument("unknown log level " + to_string(static_cast<int>(level))));
55}
56
57LogLevel
58parseLogLevel(const std::string& s)
59{
60 if (s == "FATAL")
61 return LogLevel::FATAL;
62 else if (s == "NONE")
63 return LogLevel::NONE;
64 else if (s == "ERROR")
65 return LogLevel::ERROR;
66 else if (s == "WARN")
67 return LogLevel::WARN;
68 else if (s == "INFO")
69 return LogLevel::INFO;
70 else if (s == "DEBUG")
71 return LogLevel::DEBUG;
72 else if (s == "TRACE")
73 return LogLevel::TRACE;
74 else if (s == "ALL")
75 return LogLevel::ALL;
76
77 BOOST_THROW_EXCEPTION(std::invalid_argument("unrecognized log level '" + s + "'"));
78}
79
80Logger::Logger(const std::string& name)
81 : m_moduleName(name)
82{
83 this->setLevel(LogLevel::NONE);
84 Logging::addLogger(*this);
85}
86
87} // namespace util
88} // namespace ndn