remove logging to file
added some doc
This commit is contained in:
		@@ -48,5 +48,6 @@ bool Credentials::readCredentials() {
 | 
			
		||||
            std::cerr << "No '" << nfex.getPath() << "' setting in configuration file." << std::endl;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    // check if needed values aren't empty
 | 
			
		||||
    return !(Credentials::dynuapikey.empty() || Credentials::domainid.empty() || Credentials::domainname.empty());
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,9 +3,7 @@
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <ctime>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <sstream>
 | 
			
		||||
 | 
			
		||||
#include "FileLogger.h"
 | 
			
		||||
 | 
			
		||||
@@ -28,22 +26,3 @@ std::string FileLogger::readip() {
 | 
			
		||||
 | 
			
		||||
    return ip;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void FileLogger::logToLogfile(std::string text) {
 | 
			
		||||
    std::ofstream out;
 | 
			
		||||
    out.open("dynurefresher.log", std::ios::out | std::ios::app);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    std::time_t t = std::time(0);   // get time now
 | 
			
		||||
    std::tm *now = std::localtime(&t);
 | 
			
		||||
 | 
			
		||||
    std::stringstream logline;
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    out << logline.str();
 | 
			
		||||
 | 
			
		||||
    out.close();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -24,16 +24,13 @@ void IPRefresher::checkIPAdress(bool force) {
 | 
			
		||||
 | 
			
		||||
    if (ip.empty()) {
 | 
			
		||||
        //no internet connection (or other error)
 | 
			
		||||
        logger.logToLogfile("[WARNING] no internet connection");
 | 
			
		||||
        Logger::warning("no internet connection");
 | 
			
		||||
    } else {
 | 
			
		||||
        std::string oldip = logger.readip();
 | 
			
		||||
 | 
			
		||||
        if (oldip == ip && !force) {
 | 
			
		||||
            Logger::message("no change -- ip: " + ip);
 | 
			
		||||
            logger.logToLogfile(" [INFO] no change -- ip: " + ip);
 | 
			
		||||
        } else {
 | 
			
		||||
            logger.logToLogfile(" [INFO] ip changed! -- from :" + oldip + "to: " + ip);
 | 
			
		||||
            Logger::message("ip changed! -- from :" + oldip + "to: " + ip);
 | 
			
		||||
 | 
			
		||||
            DynuAPI dynu;
 | 
			
		||||
@@ -45,7 +42,6 @@ void IPRefresher::checkIPAdress(bool force) {
 | 
			
		||||
                tele.sendMessage(oldip + " moved to " + ip);
 | 
			
		||||
            } else {
 | 
			
		||||
                //error
 | 
			
		||||
                logger.logToLogfile(" [ERROR] failed to write ip to dynu api!");
 | 
			
		||||
                Logger::error("failed to write ip to dynu api!");
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@@ -54,9 +50,7 @@ void IPRefresher::checkIPAdress(bool force) {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
IPRefresher::IPRefresher() {
 | 
			
		||||
    // default constructor
 | 
			
		||||
}
 | 
			
		||||
IPRefresher::IPRefresher() = default;
 | 
			
		||||
 | 
			
		||||
IPRefresher::IPRefresher(bool loop) {
 | 
			
		||||
    if (Credentials::readCredentials()) {
 | 
			
		||||
 
 | 
			
		||||
@@ -13,23 +13,23 @@ const int Logger::Debug = 2;
 | 
			
		||||
const int Logger::Message = 3;
 | 
			
		||||
const int Logger::Error = 4;
 | 
			
		||||
 | 
			
		||||
void Logger::debug(std::string message) {
 | 
			
		||||
void Logger::debug(const std::string message) {
 | 
			
		||||
    log(message, Logger::Debug);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Logger::message(std::string message) {
 | 
			
		||||
void Logger::message(const std::string message) {
 | 
			
		||||
    log(message, Logger::Message);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Logger::warning(std::string message) {
 | 
			
		||||
void Logger::warning(const std::string message) {
 | 
			
		||||
    log(message, Logger::Warning);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Logger::error(std::string message) {
 | 
			
		||||
void Logger::error(const std::string message) {
 | 
			
		||||
    log(message, Logger::Error);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Logger::log(std::string &message, int level) {
 | 
			
		||||
void Logger::log(const std::string &message, int level) {
 | 
			
		||||
    std::stringstream out;
 | 
			
		||||
    out << "[";
 | 
			
		||||
    switch (level) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user