remove logging to file
added some doc
This commit is contained in:
parent
7cf8e965b0
commit
9d33964b93
@ -1,17 +1,13 @@
|
|||||||
//
|
//
|
||||||
// Created by lukas on 05.05.19.
|
// Created by lukas on 05.05.19.
|
||||||
//
|
//
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class FileLogger {
|
class FileLogger {
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* log messages to logfile
|
|
||||||
* @param text message
|
|
||||||
*/
|
|
||||||
void logToLogfile(std::string text);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* safe ip to temp file
|
* safe ip to temp file
|
||||||
* @param ip ip address to save
|
* @param ip ip address to save
|
||||||
|
@ -12,5 +12,11 @@ public:
|
|||||||
void checkIPAdress(bool force);
|
void checkIPAdress(bool force);
|
||||||
|
|
||||||
IPRefresher();
|
IPRefresher();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* start the service in loop mode
|
||||||
|
* every 5 minutes the ip is checked an refreshed (needed for .service)
|
||||||
|
* @param loop true->loopmode on
|
||||||
|
*/
|
||||||
explicit IPRefresher(bool loop);
|
explicit IPRefresher(bool loop);
|
||||||
};
|
};
|
||||||
|
@ -13,7 +13,7 @@ public:
|
|||||||
static void warning(std::string message);
|
static void warning(std::string message);
|
||||||
static void error(std::string message);
|
static void error(std::string message);
|
||||||
|
|
||||||
static void log(std::string &message, int level);
|
static void log(const std::string &message, int level);
|
||||||
|
|
||||||
static const int Debug;
|
static const int Debug;
|
||||||
static const int Message;
|
static const int Message;
|
||||||
|
@ -48,5 +48,6 @@ bool Credentials::readCredentials() {
|
|||||||
std::cerr << "No '" << nfex.getPath() << "' setting in configuration file." << std::endl;
|
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());
|
return !(Credentials::dynuapikey.empty() || Credentials::domainid.empty() || Credentials::domainname.empty());
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <ctime>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include "FileLogger.h"
|
#include "FileLogger.h"
|
||||||
|
|
||||||
@ -28,22 +26,3 @@ std::string FileLogger::readip() {
|
|||||||
|
|
||||||
return ip;
|
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()) {
|
if (ip.empty()) {
|
||||||
//no internet connection (or other error)
|
//no internet connection (or other error)
|
||||||
logger.logToLogfile("[WARNING] no internet connection");
|
|
||||||
Logger::warning("no internet connection");
|
Logger::warning("no internet connection");
|
||||||
} else {
|
} else {
|
||||||
std::string oldip = logger.readip();
|
std::string oldip = logger.readip();
|
||||||
|
|
||||||
if (oldip == ip && !force) {
|
if (oldip == ip && !force) {
|
||||||
Logger::message("no change -- ip: " + ip);
|
Logger::message("no change -- ip: " + ip);
|
||||||
logger.logToLogfile(" [INFO] no change -- ip: " + ip);
|
|
||||||
} else {
|
} else {
|
||||||
logger.logToLogfile(" [INFO] ip changed! -- from :" + oldip + "to: " + ip);
|
|
||||||
Logger::message("ip changed! -- from :" + oldip + "to: " + ip);
|
Logger::message("ip changed! -- from :" + oldip + "to: " + ip);
|
||||||
|
|
||||||
DynuAPI dynu;
|
DynuAPI dynu;
|
||||||
@ -45,7 +42,6 @@ void IPRefresher::checkIPAdress(bool force) {
|
|||||||
tele.sendMessage(oldip + " moved to " + ip);
|
tele.sendMessage(oldip + " moved to " + ip);
|
||||||
} else {
|
} else {
|
||||||
//error
|
//error
|
||||||
logger.logToLogfile(" [ERROR] failed to write ip to dynu api!");
|
|
||||||
Logger::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() {
|
IPRefresher::IPRefresher() = default;
|
||||||
// default constructor
|
|
||||||
}
|
|
||||||
|
|
||||||
IPRefresher::IPRefresher(bool loop) {
|
IPRefresher::IPRefresher(bool loop) {
|
||||||
if (Credentials::readCredentials()) {
|
if (Credentials::readCredentials()) {
|
||||||
|
@ -13,23 +13,23 @@ const int Logger::Debug = 2;
|
|||||||
const int Logger::Message = 3;
|
const int Logger::Message = 3;
|
||||||
const int Logger::Error = 4;
|
const int Logger::Error = 4;
|
||||||
|
|
||||||
void Logger::debug(std::string message) {
|
void Logger::debug(const std::string message) {
|
||||||
log(message, Logger::Debug);
|
log(message, Logger::Debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::message(std::string message) {
|
void Logger::message(const std::string message) {
|
||||||
log(message, Logger::Message);
|
log(message, Logger::Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::warning(std::string message) {
|
void Logger::warning(const std::string message) {
|
||||||
log(message, Logger::Warning);
|
log(message, Logger::Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::error(std::string message) {
|
void Logger::error(const std::string message) {
|
||||||
log(message, Logger::Error);
|
log(message, Logger::Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::log(std::string &message, int level) {
|
void Logger::log(const std::string &message, int level) {
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
out << "[";
|
out << "[";
|
||||||
switch (level) {
|
switch (level) {
|
||||||
|
Loading…
Reference in New Issue
Block a user