Created
January 23, 2016 07:46
-
-
Save LiamKarlMitchell/80f1e463c7fe1c23b969 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I license this as MIT do whatever you want with it basically. | |
// I can't be assed including the header you know what it is. | |
// If you don't want Mutex.h comment it out, check out my other gists for it if you need it. | |
#ifndef __CLOG_H | |
#define __CLOG_H | |
#include "Mutex.h" | |
#include <fstream> | |
using namespace std; | |
class CLog | |
{ | |
private: | |
HANDLE LogMutex; | |
public: | |
char * LogFile; | |
//std::list <std::string> history; | |
CLog(char* FileName = "Log.txt") | |
{ | |
LogFile=FileName; | |
} | |
void Write(const char *fmt, ...) | |
{ | |
Mutex m(&LogMutex); | |
// Could we dynamically set buffer here there has to be a way to find what the total length can be? | |
char buf[1024] = {'\0'}; | |
va_list va_alist; | |
va_start(va_alist, fmt); | |
vsprintf_s(buf, fmt, va_alist); | |
va_end(va_alist); | |
//history.push_back(buf); | |
ofstream myfile; | |
myfile.open (LogFile,ios::app); // Open LogFile append to end | |
myfile << buf << endl; // Write out the message | |
myfile.close(); // Close LogFile | |
} | |
void Write_String(const char *msg) | |
{ | |
Mutex m(&LogMutex); | |
// Could we dynamically set buffer here there has to be a way to find what the total length can be? | |
//history.push_back(buf); | |
ofstream myfile; | |
myfile.open (LogFile,ios::app); // Open LogFile append to end | |
myfile << msg << endl; // Write out the message | |
myfile.close(); // Close LogFile | |
} | |
void Remove() | |
{ | |
Mutex m(&LogMutex); | |
remove(LogFile); | |
} | |
void SetFile(char* FileName) | |
{ | |
Mutex m(&LogMutex); | |
LogFile=FileName; | |
} | |
}; | |
#endif // __CLOG_H | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment