Skip to content

Latest commit

 

History

History
56 lines (50 loc) · 3.58 KB

README.md

File metadata and controls

56 lines (50 loc) · 3.58 KB

Log Wrapper

Usage of this wrapper is free to use, just give me credit for it if you use it. Enjoy to your hearts content and feel free to let me know if you have suggestions to upgrade it.

This log wrapper is simple to use and makes logging events easier. I got tired of rewriting code to make logs, so I made this to make my life easier.

If you are programming sockets, logging what you send and what you recieve helps with finding errors and problems you won't generally see using the debugger. If my program requires logging events like server, I will create a class for the general logging of events. A second class though I will create for debugging problem. I will use a define to enable a second logging class / file for the events that normal users would not need. For instance

#ifdef DEBUGLOG
   Debug("Data to send out!");
#endif

This way to disable the code, you just comment out (// in front) of the

#define DEBUGLOG
and you disable the code that helps you find errors without having to remove anything. A simple trick to help you know what data is going through sockets and anything else the debugger won't help you with.

Now this log wrapper doesn't have levels in it because I wrote it 10 to 15 years ago, it wasn't something I was thinking about at the time. I might add it later if people want it.

To use this, all you need to do is declare your variable, open it, and then start logging. Don't forget to close it when you are done.

LOG Log("Log File.log");
Log.open();

...

Log.Log("Data to log");

...

Log.close();

Now to go over all the functions and what they do.

bool Open();

This opens the file for writing. Returns true if it opens properly and false if something went wrong.

void Close();

This closes the file once you are done.

bool Log(string, bool);

This is your Log function which is the whole point of the class. the bool is for creating a new line, the default is true (creates a new line) and you don't need to use it if you are creating a new line.

void SetFilename(string);

This sets the filename for your log (Default is Log.txt").

SetDateTime(bool Date, bool Time);

This function tells the log whether you want to include a datestamp and/or a timestamp with each log.

void SetMode(ios_base::openmode);

This is for changing the mode of the file when opening it up (Default is std::ios::app for appending).

void UseUTCTime();

This function tells the class to use UTC time (Local is default).

void UseLocalTime();

This function tells the class to use local time (DEFAULT SETTING).

void UseDayCutter(bool);

This feature will slice the log file based on days. So each day, a new log file will be created with the date stamped in the file name at the end. (This is default).

void UseSpaces(bool);

This allows you to decide if you want to use spaces in the filename or an underscore '_' for old school DOS like filenames.

void EraseFile();

***DANGER*** Use this function at your own risk because it will clear out the file leaving it empty. I would only use this for DEBUGGING purposes.

void ClearFile();

***DANGER*** Use this function at your own risk because using it means the file is gone forever! This will completely delete the file. I would only use this for DEBUGGING purposes.



  William Glenn Ward
  Computer Programmer / Graphic Designer
  [email protected]
  programming since 1998