-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.cpp
More file actions
52 lines (38 loc) · 912 Bytes
/
Logger.cpp
File metadata and controls
52 lines (38 loc) · 912 Bytes
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
#include "Logger.hpp"
#include <iostream>
#include <fstream>
#include <ctime>
#include <iomanip>
#include <sstream>
std::string const Logger::_filename = "log.txt";
Logger::Logger(){
}
Logger::Logger(Logger const & src) {
*this = src;
}
Logger::~Logger() {
}
Logger & Logger::operator=(Logger const & rhs) {
if (this != &rhs) {
}
return *this;
}
void Logger::LogToFile(int message)
{
std::ofstream ofs(_filename, std::ofstream::app);
ofs << message << std::endl;
ofs.close();
}
void Logger::LogToFile(const std::string &message)
{
std::ofstream ofs(_filename, std::ofstream::app);
ofs << Logger::MakeLogEntry(message);
ofs.close();
}
std::string Logger::MakeLogEntry(const std::string &message)
{
std::time_t result = std::time(nullptr);
std::stringstream ss;
ss << "[" << std::put_time(std::localtime(&result), "%d %B %H:%M:%S") << "] " << message << std::endl;
return ss.str();
}