H
Harry
Hi all,
I am writing a logger program which can take any datatype.
namespace recordLog {
enum Debug_Level {low, midium, high};
class L {
std:fstream os;
Debug_Level cdl;
const Debug_Level ddl;
public:
L(std::string filename, const Debug_Level& desired)
: ddl(desired)
{
std::string fname=log_path+filename;
if(!os)
exit(EXIT_FAILURE);
os.open(fname.c_str(),std::ios:ut|std::ios::app);
os<<"START TIME :" <<__DATE__<<" "<<__TIME__<<"\n";
}
template<typename T> friend std:stream& operator << (L&
lstrm, const T& t);
friend std:stream& operator << (L& lstrm,const Debug_Level&
l);
~L(){os<<"\n\nEND TIME :"<<__DATE__<<" "<< __TIME__;}
};
L& initL(std::string str)
{
//static L ls(str,high);
int dl=atoi(d_level.c_str());
static L ls(str,static_cast<Debug_Level>(dl));
return ls;
}
/*
template<typename T> std:stream& operator << (L& lstrm, const T&
t)
{
if(lstrm.cdl <= lstrm.ddl)
lstrm.os << t;
return lstrm.os;
}
*/
std:stream& operator << (L& lstrm,const Debug_Level& l)
{
std::cout<<"I AM LOG"<<std::endl;
lstrm.cdl = l;
return lstrm.os;
}
class E {
std:fstream os;
Debug_Level cdl;
const Debug_Level ddl;
public:
E(std::string filename, const Debug_Level& desired)
: ddl(desired)
{
std::string fname=error_path+filename;
if(!os)
exit(EXIT_FAILURE);
os.open(fname.c_str(),std::ios::app);
os<<"START TIME :" <<__DATE__<<" "<<__TIME__<<"\n";
}
template<typename T> friend std:stream& operator << (E& lstrm,
const T& t);
friend std:stream& operator << (E& lstrm,const Debug_Level&
l);
~E(){ os<<"\n\nEND TIME :"<<__DATE__<<" "<< __TIME__; }
};
E& initE(std::string str)
{
static E ls(str,high);
return ls;
}
/*
template<typename T> std:stream& operator << (E& lstrm, const T&
t)
{
std::cout<<typeid(T).name()<<std::endl;
lstrm.os << t;
return lstrm.os;
}
*/
std:stream& operator << (E& lstrm,const Debug_Level& l)
{
lstrm.cdl = l;
return lstrm.os;
}
}
int main()
{
using namespace recordLog;
L& l=initL("harilogger.txt");
E& elog=initE("errorlog.txt");
l<< high <<"test" << 45;
elog<<low<<"Error in this line"<<56;
}
My question is still I commented out the template part..
My program is still writing to the files harilogger.txt and
errorlog.txt.My program will be such as that I will set a debug level
based on which data's will be displayed.
if(lstrm.cdl <= lstrm.ddl)
lstrm.os << t;
if current debug level is less then or equal to desired debug level it
should write the data else it should not.
elog<<low<<"Error in this line"<<56;
Here first I am setting the debug level i,e low and based on which data
<<"Error in this line"<<56;
will be written..
Thanks in advance..
Cheer's
HPS
I am writing a logger program which can take any datatype.
namespace recordLog {
enum Debug_Level {low, midium, high};
class L {
std:fstream os;
Debug_Level cdl;
const Debug_Level ddl;
public:
L(std::string filename, const Debug_Level& desired)
: ddl(desired)
{
std::string fname=log_path+filename;
if(!os)
exit(EXIT_FAILURE);
os.open(fname.c_str(),std::ios:ut|std::ios::app);
os<<"START TIME :" <<__DATE__<<" "<<__TIME__<<"\n";
}
template<typename T> friend std:stream& operator << (L&
lstrm, const T& t);
friend std:stream& operator << (L& lstrm,const Debug_Level&
l);
~L(){os<<"\n\nEND TIME :"<<__DATE__<<" "<< __TIME__;}
};
L& initL(std::string str)
{
//static L ls(str,high);
int dl=atoi(d_level.c_str());
static L ls(str,static_cast<Debug_Level>(dl));
return ls;
}
/*
template<typename T> std:stream& operator << (L& lstrm, const T&
t)
{
if(lstrm.cdl <= lstrm.ddl)
lstrm.os << t;
return lstrm.os;
}
*/
std:stream& operator << (L& lstrm,const Debug_Level& l)
{
std::cout<<"I AM LOG"<<std::endl;
lstrm.cdl = l;
return lstrm.os;
}
class E {
std:fstream os;
Debug_Level cdl;
const Debug_Level ddl;
public:
E(std::string filename, const Debug_Level& desired)
: ddl(desired)
{
std::string fname=error_path+filename;
if(!os)
exit(EXIT_FAILURE);
os.open(fname.c_str(),std::ios::app);
os<<"START TIME :" <<__DATE__<<" "<<__TIME__<<"\n";
}
template<typename T> friend std:stream& operator << (E& lstrm,
const T& t);
friend std:stream& operator << (E& lstrm,const Debug_Level&
l);
~E(){ os<<"\n\nEND TIME :"<<__DATE__<<" "<< __TIME__; }
};
E& initE(std::string str)
{
static E ls(str,high);
return ls;
}
/*
template<typename T> std:stream& operator << (E& lstrm, const T&
t)
{
std::cout<<typeid(T).name()<<std::endl;
lstrm.os << t;
return lstrm.os;
}
*/
std:stream& operator << (E& lstrm,const Debug_Level& l)
{
lstrm.cdl = l;
return lstrm.os;
}
}
int main()
{
using namespace recordLog;
L& l=initL("harilogger.txt");
E& elog=initE("errorlog.txt");
l<< high <<"test" << 45;
elog<<low<<"Error in this line"<<56;
}
My question is still I commented out the template part..
My program is still writing to the files harilogger.txt and
errorlog.txt.My program will be such as that I will set a debug level
based on which data's will be displayed.
if(lstrm.cdl <= lstrm.ddl)
lstrm.os << t;
if current debug level is less then or equal to desired debug level it
should write the data else it should not.
elog<<low<<"Error in this line"<<56;
Here first I am setting the debug level i,e low and based on which data
<<"Error in this line"<<56;
will be written..
Thanks in advance..
Cheer's
HPS