about summary refs log blame commit diff stats
path: root/src/logger.cpp
blob: 4b722c823d4409473cbea5f10ff49a98c7a52e34 (plain) (tree)
1
2
3
4
5
6
7
8




                   
                   


              
                                                      

















                                                                       
#include "logger.h"

#include <chrono>
#include <fstream>
#include <mutex>

#include "global.h"

namespace {

class Logger {
 public:
  Logger() : logfile_(GetAbsolutePath("debug.log")) {}

  void LogLine(const std::string& text) {
    std::lock_guard guard(file_mutex_);
    logfile_ << "[" << std::chrono::system_clock::now() << "] " << text
             << std::endl;
    logfile_.flush();
  }

 private:
  std::ofstream logfile_;
  std::mutex file_mutex_;
};

}  // namespace

void TrackerLog(const std::string& text) {
  static Logger* instance = new Logger();
  instance->LogLine(text);
}