Simple Log/Config Manager for hacks! [C++]

Posts 12 of 2 · Page 1 of 1
Simple Log/Config Manager for hacks! [C++]
This is no tutorial, but it is well commented and easy to understand, it is very basic, I would suggest re-writing the code to fit your needs, especially since this has hardcoded config loading/saving.
This is very simple to recreate, trust me, it took me ~30 mins, the commenting took longer tbh xD


How to use logging:
 
Logging

Code:
// Include CLogger to your header/cpp where ever you want to log basically.
#include "CLogger.h"

// You must first initalize everything needed to log, only do this once.
std::string logName = cLog->GetCurrentDate(); // This will return a [yyyy-mm-dd - hour-min] string
cLog->SetLogName(logName);
cLog->Open(); // then you must open the file, remember you must set the log name before you open it!

// Then you can start logging messages:
// To actually log a normal message:
cLog->Msg("A log! :)"); // This will log a normal message without any prefix.
// A normal log with %s/i/f ..etc arguments:
cLog->MsgArg("A log with a integer %i", myInt);
// A normal Warning log
cLog->WarnMsg("Warning log!");
// When calling WarnMsg you can also log arguments to your string, by doing the same as MsgArg
cLog->WarnMsg("A log with a integer %i", myInt);
// Its the same for Error logs, you call a error log by
cLog->ErrorMsg("String %s", myString); // Works just as WarnMsg, you can call it without including
// more arguments.
cLog->ErrorMsg("String!");


How to use the config manager:
 
Configs

Code:
//You must first include CConfig to your cpp/header file to be able to use it.

//To initalize everything you need to do the following
Config->SetName("MyConfig.ini"); // Obviously the .ini can be changed to any file extension you wish.

// To load a config you call (AFter the name has been set!):
Config->LoadConfig();

// To save a config you call (after the name has been set!):
Config->SaveConfig();

// To edit what it saves/loads you must go into CConfig.cpp and go into the LoadConfig/SaveConfig functions
// I recommend you to read up on what you're doing, as this is needed to be hardcoded atm.
// It is as well commented as I could have done.


Example of how a log may look:
 
How a log may look!

LogName (If you've set it to the current date..):
"[2015-6-15 - 1-24]" the log file does NOT need to have a extension, it is already added by default when initializing everything.

How a log may look:
Code:
[LOG] Psycho's Log Manager! :) [2015-6-15 | 1:24]
[LOG] [WARNING] A Warning log! [2015-6-15 | 1:24]
[LOG] [ERROR] A error log! [2015-6-15 | 1:24]


Full pastebin source:
Main.cpp http://pastebin.com/VPs616Cx

CConfig.h http://pastebin.com/HLPQnpEQ
CConvert.h http://pastebin.com/bp6m1C0a
CCLogger.h http://pastebin.com/w1MTYz2D

CConfig.cpp http://pastebin.com/nVtjKGW8
CCLogger.cpp http://pastebin.com/XXRSYC7b
very nice.
Posts 12 of 2 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?