Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// 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
}
}