/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
 * Copyright (c) 2014,  Regents of the University of California,
 *                      Arizona Board of Regents,
 *                      Colorado State University,
 *                      University Pierre & Marie Curie, Sorbonne University,
 *                      Washington University in St. Louis,
 *                      Beijing Institute of Technology,
 *                      The University of Memphis
 *
 * This file is part of NFD (Named Data Networking Forwarding Daemon).
 * See AUTHORS.md for complete list of NFD authors and contributors.
 *
 * NFD is free software: you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * NFD, e.g., in COPYING.md file.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef NFD_ANDROID_CUSTOM_LOGGER_HPP
#define NFD_ANDROID_CUSTOM_LOGGER_HPP

#include "common.hpp"
#include <android/log.h>

namespace nfd {

/** \brief indicates a log level
 *  \note This type is internal. Logger should be accessed through NFD_LOG_* macros.
 */
enum LogLevel {
  LOG_FATAL          = -1, // fatal (will be logged unconditionally)
  LOG_NONE           = 0, // no messages
  LOG_ERROR          = 1, // serious error messages
  LOG_WARN           = 2, // warning messages
  LOG_INFO           = 3, // informational messages
  LOG_DEBUG          = 4, // debug messages
  LOG_TRACE          = 5, // trace messages (most verbose)
  LOG_ALL            = 255 // all messages
};

/** \brief provides logging for a module
 *  \note This type is internal. Logger should be accessed through NFD_LOG_* macros.
 *  \note This type is copyable because logger can be declared as a field of
 *        (usually template) classes, and shouldn't prevent those classes to be copyable.
 */
class Logger
{
public:
  Logger(const std::string& name, LogLevel level);

  bool
  isEnabled(LogLevel level) const
  {
    return m_enabledLogLevel >= level;
  }

  void
  setLogLevel(LogLevel level)
  {
    m_enabledLogLevel = level;
  }

  const std::string&
  getName() const
  {
    return m_moduleName;
  }

  void
  setName(const std::string& name)
  {
    m_moduleName = name;
  }

private:
  std::string m_moduleName;
  LogLevel    m_enabledLogLevel;
};

inline std::ostream&
operator<<(std::ostream& output, const Logger& logger)
{
  output << logger.getName();
  return output;
}

} // namespace nfd

#include "core/logger-factory.hpp"

namespace nfd {

#define NFD_LOG_INIT(name) \
static nfd::Logger& g_logger = nfd::LoggerFactory::create(name)

#define NFD_LOG_INCLASS_DECLARE() \
static nfd::Logger& g_logger

#define NFD_LOG_INCLASS_DEFINE(cls, name) \
nfd::Logger& cls::g_logger = nfd::LoggerFactory::create(name)

#define NFD_LOG_INCLASS_TEMPLATE_DEFINE(cls, name) \
template<class T>                                  \
nfd::Logger& cls<T>::g_logger = nfd::LoggerFactory::create(name)

#define NFD_LOG_INCLASS_TEMPLATE_SPECIALIZATION_DEFINE(cls, specialization, name) \
template<>                                                                        \
nfd::Logger& cls<specialization>::g_logger = nfd::LoggerFactory::create(name)

#define NFD_LOG_INCLASS_2TEMPLATE_SPECIALIZATION_DEFINE(cls, s1, s2, name) \
template<>                                                                 \
nfd::Logger& cls<s1, s2>::g_logger = nfd::LoggerFactory::create(name)

#define NFD_LOG(nfdLevel, androidLevel, msg, expression)                \
do {                                                                    \
  if (g_logger.isEnabled(::nfd::LOG_##nfdLevel)) {                      \
    std::ostringstream os;                                              \
    os << expression;                                                   \
    __android_log_print(ANDROID_LOG_##androidLevel,                     \
                        g_logger.getName().c_str(), "%s", os.str().c_str()); \
  }                                                                     \
} while (false)

#define NFD_LOG_TRACE(expression) NFD_LOG(TRACE, VERBOSE, TRACE, expression)
#define NFD_LOG_DEBUG(expression) NFD_LOG(DEBUG, DEBUG, DEBUG,   expression)
#define NFD_LOG_INFO(expression)  NFD_LOG(INFO,  INFO,  INFO,    expression)
#define NFD_LOG_WARN(expression)  NFD_LOG(WARN,  WARN,  WARNING, expression)
#define NFD_LOG_ERROR(expression) NFD_LOG(ERROR, ERROR, ERROR,   expression)
#define NFD_LOG_FATAL(expression) NFD_LOG(FATAL, FATAL, FATAL,   expression)

} // namespace nfd

#endif // NFD_ANDROID_CUSTOM_LOGGER_HPP
