DynuIPRefresher/src/Logger.cpp

50 lines
942 B
C++
Raw Normal View History

2019-05-05 14:35:38 +00:00
//
// Created by lukas on 05.05.19.
//
#include <fstream>
#include <ctime>
#include <iostream>
#include <sstream>
#include "Logger.h"
void Logger::safeip(std::string ip) {
std::ofstream out;
2019-05-08 17:31:49 +00:00
out.open("ip.txt", std::ios::out);
2019-05-05 14:35:38 +00:00
out << ip;
out.close();
}
std::string Logger::readip() {
std::ifstream in;
2019-05-08 17:31:49 +00:00
in.open("ip.txt", std::ios::in);
2019-05-05 14:35:38 +00:00
std::string ip;
in >> ip;
return ip;
}
void Logger::logToLogfile(std::string text) {
std::ofstream out;
2019-05-08 17:31:49 +00:00
out.open("dynurefresher.log", std::ios::out | std::ios::app);
2019-05-05 14:35:38 +00:00
std::time_t t = std::time(0); // get time now
2019-05-08 17:31:49 +00:00
std::tm *now = std::localtime(&t);
2019-05-05 14:35:38 +00:00
std::stringstream logline;
2019-05-08 17:31:49 +00:00
logline << "[ " << (now->tm_year + 1900) << '-' << (now->tm_mon + 1) << '-' << now->tm_mday
<< "_" << now->tm_hour << ":" << now->tm_min << ":" << now->tm_sec << " ] " << '\t' << text << std::endl;
2019-05-05 14:35:38 +00:00
out << logline.str();
out.close();
}