#include "nlsr_logger.hpp"

namespace nlsr
{

  string
  NlsrLogger::getEpochTime()
  {
    std::stringstream ss;
    boost::posix_time::ptime time_t_epoch(boost::gregorian::date(1970,1,1));
    boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
    boost::posix_time::time_duration diff = now - time_t_epoch;
    ss<<diff.total_seconds()<<"."<<boost::format("%06i")%(diff.total_microseconds()
        %1000000);
    return ss.str();
  }

  string
  NlsrLogger::getUserHomeDirectory()
  {
    string homeDirPath(getpwuid(getuid())->pw_dir);
    if( homeDirPath.empty() )
    {
      homeDirPath = getenv("HOME");
    }
    return homeDirPath;
  }

  void
  NlsrLogger::initNlsrLogger(std::string dirPath)
  {
    string logDirPath(dirPath);
    if( dirPath.empty() )
    {
      logDirPath=getUserHomeDirectory()+"/nlsrLog";
    }
    cout<<"Log Dir Path: "<< logDirPath<<endl;
    typedef sinks::synchronous_sink< sinks::text_file_backend > file_sink;
    shared_ptr< file_sink > sink(new file_sink(
                                   keywords::file_name = logDirPath
                                       +"/NLSR%Y%m%d%H%M%S_%3N.log",
                                   keywords::rotation_size = 16 * 1024 * 1024,
                                   keywords::time_based_rotation = sinks::file::rotation_at_time_point(12, 0, 0),
                                   keywords::auto_flush = true
                                 ));
    sink->locked_backend()->set_file_collector(sinks::file::make_collector(
          keywords::target = logDirPath,
          //keywords::max_size =  512 * 1024 * 1024,
          keywords::min_free_space = 64 * 1024 * 1024
        ));
    sink->set_formatter(
      expr::format("%1%: %2%")
      % getEpochTime()
      % expr::smessage
    );
    logging::core::get()->add_sink(sink);
  }

}//namespace nlsr
