[an error occurred while processing this directive] [an error occurred while processing this directive]
How to write a Logging System (c++)
You might be asking yourself, (1) what is a logging system, (2) what can it do for me, and (3) why should I care? Well, to answer your questions.
  1. A logging system can be used to print information to a text file.

  2. Log files are typically used to print out the current status of the application as well as any errors that occur.

  3. You should care because it can save you time! Rather then having to step through your program line by line, you can just check the log file and spot rigtht away if any errors have occured.

Now, having read the above, you might be asking yourself: "why not just use printf to log the current status of the program. " That might sound reasonable at first, and for small projects, you might be able to get away with it. But if you plan on working on a project with more then 200 lines of code, you may consider using a log file.
Unlike printf, a log file can be accessed without having to compile your program with a console window. Also, most applications arn't distributed with a console window hanging in the background, so your user has no way of seeing the output. However, the user does have access to the log file. A log file cannot only help you, but if a user runs your program and it hangs on them, they can consult the log file as well as send you the log file for further study.
Enought theory, time to get your hands dirty!

The code snippet below is going to be the layout for our logger class.



As you can see, our Logger class uses a singleton implemenation. This is good, because it's not like we need to create more then one log.

Below is the test program for our logger.


You can get the code below.

Get the source code.


[an error occurred while processing this directive]