I have a custom logging system that allows me to send information to the log file and console, depending on the verbosity currently selected. Right now, the problem that I encountered is related to the output to the file, to the output to the console, which works fine.
Here is an example:
ilra_talk << "Local IP: " << systemIP() << " | Hostname: " << systemhostname() << endl;
This should cause the current local IP and hostname of the system to be printed to a file. However, this only leads to the fact that information is displayed on the console, despite the fact that the function is overloaded, which leads to its printing on both.
I set out the code below. Any help is appreciated (as always).
There is currently a definition for ilra_talk, which creates a new class object:
#define ilra_talk ilra(__FUNCTION__,0)
Class definition:
class ilra
{
static int ilralevel_set;
static int ilralevel_passed;
static bool relay_enabled;
static bool log_enabled;
static ofstream logfile;
public:
ilra(const std::string &funcName, int toset)
{
ilralevel_passed = toset;
}
~ilra(){};
static void ilra_verbose_level(int toset){
ilralevel_set = toset;
}
static void ilra_log_enabled(bool toset){
log_enabled = toset;
if (log_enabled == true){
time_t rawtime;
time ( &rawtime );
stringstream logname_s;
string logname = "rclient-";
logname_s << rawtime;
logname.append(logname_s.str());
logfile.open(logname.c_str());
}
}
template <class T>
ilra &operator<<(const T &v)
{
if(log_enabled == true){
logfile << v;
logfile << "Test" << endl;
}
if(ilralevel_passed <= ilralevel_set)
std::cout << v;
return *this;
}
ilra &operator<<(std::ostream&(*f)(std::ostream&))
{
if(log_enabled == true)
logfile << *f;
if(ilralevel_passed <= ilralevel_set)
std::cout << *f;
return *this;
}
};