I am trying to code a simple log file writer that will be used in many .cpp files in one project. So far this is the code:
enter code here
#include"log.h"
logger::logger()
{
m_outStream.open("LogFile");
m_outStream<<"********** LOG ENTRY STARTED **********"<<endl;
}
logger::~logger()
{
m_outStream.close();
}
void logger::logEntry(const char* filename, const unsigned long lineno, const char* str)
{
m_outStream<<"--> NAME: "<<filename<<" | LINE NUMBER : "<<lineno<<" | "<<str<<endl;
}
Main can be something like
main()
{
func1();
func2();
.
.
.
}
The functions called from main may make other function calls in their bodies. Now, how or where do i declare a logObject to make sure inside every function, i will have a logObject available that will facilitate my call to logEntry().
I thought making it public somewhere, and i think it makes sense for my case, but i am not sure if that is a good practice. Should the objects that work on log files be public? Any insights?