Having problems with a custom logging system I've made. I am declaring an ofstream within my main file so that it is accessible by static functions within my class. This works for my static function (ilra_log_enabled
). However, this does not work on my overloaded function for the class. I receive a undefined reference to "logfile" error.
Any ideas?
#ifndef ILRA_H_
#define ILRA_H_
// System libraries
#include <iostream>
#include <ostream>
#include <sstream>
#include <iomanip>
#include <fstream>
// Namespace
using namespace std;
// Classes
class ilra
{
static int ilralevel_set;
static int ilralevel_passed;
static bool relay_enabled;
static bool log_enabled;
static ofstream logfile;
public:
// constructor / destructor
ilra(const std::string &funcName, int toset)
{
// we got passed a loglevel!
ilralevel_passed = toset;
}
~ilra(){};
static void ilra_log_enabled(bool toset){
log_enabled = toset;
if (log_enabled == true){
// get current time
time_t rawtime;
time ( &rawtime );
// name of log file
string logname = "rclient-";
logname.append(rawtime + ".txt");
// open a log file
logfile.open(logname.c_str());
}
}
// output
template <class T>
ilra &operator<<(const T &v)
{
if(ilralevel_passed <= ilralevel_set)
std::cout << v;
if(log_enabled == true)
logfile << "Test"; // undefined reference to ilra::logfile
return *this;
}
}; // end of the class
#endif /* ILRA_H_ */