NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
logger.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2019 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/util/logger.hpp"
24 
25 namespace ndn {
26 namespace util {
27 
28 std::ostream&
29 operator<<(std::ostream& os, LogLevel level)
30 {
31  switch (level) {
32  case LogLevel::FATAL:
33  return os << "FATAL";
34  case LogLevel::NONE:
35  return os << "NONE";
36  case LogLevel::ERROR:
37  return os << "ERROR";
38  case LogLevel::WARN:
39  return os << "WARN";
40  case LogLevel::INFO:
41  return os << "INFO";
42  case LogLevel::DEBUG:
43  return os << "DEBUG";
44  case LogLevel::TRACE:
45  return os << "TRACE";
46  case LogLevel::ALL:
47  return os << "ALL";
48  }
49 
50  NDN_THROW(std::invalid_argument("unknown log level " + to_string(to_underlying(level))));
51 }
52 
54 parseLogLevel(const std::string& s)
55 {
56  if (s == "FATAL")
57  return LogLevel::FATAL;
58  else if (s == "NONE")
59  return LogLevel::NONE;
60  else if (s == "ERROR")
61  return LogLevel::ERROR;
62  else if (s == "WARN")
63  return LogLevel::WARN;
64  else if (s == "INFO")
65  return LogLevel::INFO;
66  else if (s == "DEBUG")
67  return LogLevel::DEBUG;
68  else if (s == "TRACE")
69  return LogLevel::TRACE;
70  else if (s == "ALL")
71  return LogLevel::ALL;
72 
73  NDN_THROW(std::invalid_argument("unrecognized log level '" + s + "'"));
74 }
75 
76 } // namespace util
77 } // namespace ndn
Copyright (c) 2011-2015 Regents of the University of California.
trace messages (most verbose)
std::string to_string(const T &val)
Definition: backports.hpp:86
serious error messages
std::ostream & operator<<(std::ostream &os, LogLevel level)
Output LogLevel as a string.
Definition: logger.cpp:29
informational messages
#define NDN_THROW(e)
Definition: exception.hpp:61
LogLevel
Indicates the severity level of a log message.
Definition: logger.hpp:32
Common includes and macros used throughout the library.
NDN_CXX_NODISCARD constexpr std::underlying_type_t< T > to_underlying(T val) noexcept
Definition: backports.hpp:125
LogLevel parseLogLevel(const std::string &s)
Parse LogLevel from a string.
Definition: logger.cpp:54
warning messages
fatal (will be logged unconditionally)
uint32_t level
Type of a channel package.
Definition: levels.hpp:37