// Logger.cpp #include <iostream> #include <string> #include "Logger.h" namespace math1d_cl { /// /// Default Logger ctor sets logging to the console. /// Logger::Logger():m_logTarget(0) {} Logger::Logger(Logger &origin) { m_logFilePath = origin.m_logFilePath; m_logTarget = origin.m_logTarget; } Logger::Logger(int logTarget, std::string logFilePath):m_logTarget(logTarget),m_logFilePath(logFilePath) { if(m_logTarget == 1) { m_logFile.open(logFilePath); if(m_logFile.is_open()) { time_t now; time(&now); m_logFile << "Log file created at " << ctime(&now) << std::endl; } } } Logger::~Logger() { if(m_logFile.is_open()) { m_logFile.close(); } } void Logger::log(const std::string& text) { if(m_logTarget == 0) { std::cout << text << std::endl; } else if(m_logTarget == 1) { m_logFile << text << std::endl; } // no operations for m_logTarget == 2 } }