//
// Created by rhetenor on 13.09.18.
//

#include "LoggerFactory.h"

#ifndef EASYLOGGING_IS_INITIALIZED
#define EASYLOGGING_IS_INITIALIZED
INITIALIZE_EASYLOGGINGPP
#endif

namespace flippR_driver
{
namespace utility
{
namespace LoggerFactory
{

void CreateInputTestLogger(el::Level level)
{
  el::Loggers::getLogger(INPUT_LOGGER);
  el::Configurations conf;

  conf.setToDefault();

  conf.set(level, el::ConfigurationType::ToFile, "false");
  conf.set(level, el::ConfigurationType::Format, "%datetime [%level] [%fbase] : %msg");

  el::Loggers::reconfigureAllLoggers(conf);
}

el::Configurations createConfig(std::string logger)
{
  el::Configurations conf;
  conf.setToDefault();

  conf.setGlobally(el::ConfigurationType::ToStandardOutput, "false");
  conf.setGlobally(el::ConfigurationType::MaxLogFileSize, "1500000"); //~1.5MB

  if (debug_log)
  {
    conf.set(el::Level::Debug, el::ConfigurationType::ToStandardOutput, "true");
    conf.set(el::Level::Debug, el::ConfigurationType::ToFile, "true");
    conf.set(el::Level::Debug, el::ConfigurationType::Format, "%datetime [%level] [%fbase] : %msg");
    conf.set(el::Level::Debug, el::ConfigurationType::Filename, LOGGER_FILE);
  }

  conf.set(el::Level::Info, el::ConfigurationType::ToStandardOutput, "true");
  conf.set(el::Level::Info, el::ConfigurationType::ToFile, "true");
  conf.set(el::Level::Info, el::ConfigurationType::Filename, LOGGER_FILE);
  conf.set(el::Level::Info, el::ConfigurationType::Format, "%datetime [%level] [%fbase] : %msg");

  conf.set(el::Level::Warning, el::ConfigurationType::ToStandardOutput, "true");
  conf.set(el::Level::Warning, el::ConfigurationType::ToFile, "true");
  conf.set(el::Level::Warning, el::ConfigurationType::Filename, LOGGER_FILE);
  conf.set(el::Level::Warning, el::ConfigurationType::Format, "%datetime [%level] [%fbase] : %msg");

  conf.set(el::Level::Verbose, el::ConfigurationType::ToStandardOutput, "true");
  conf.set(el::Level::Verbose, el::ConfigurationType::ToFile, "true");
  conf.set(el::Level::Verbose, el::ConfigurationType::Filename, LOGGER_FILE);
  conf.set(el::Level::Verbose, el::ConfigurationType::Format, "%datetime [%level] [%fbase] : %msg");

  return conf;
}

void CreateInputLogger()
{
  el::Loggers::getLogger(INPUT_LOGGER);
  el::Configurations conf = createConfig(INPUT_LOGGER);
  el::Loggers::reconfigureLogger(INPUT_LOGGER, conf);
}

void CreateOutputLogger()
{
  el::Loggers::getLogger(OUTPUT_LOGGER);
  el::Configurations conf = createConfig(OUTPUT_LOGGER);
  el::Loggers::reconfigureLogger(OUTPUT_LOGGER, conf);
}

void ActivateDebugLog()
{
  debug_log = true;
}

}

}
}