Home

Awesome

ahxrlogger - Light C++ Logger Library

#include "ahxrlogger.h"

using namespace std;

char * s_file_name = "dummyfile.txt";

int main() {

	LOG("Creating dummy file '%s'", s_file_name );

	fstream
		fstr_test
	;
	fstr_test.open(s_file_name, ios::out);

	if (fstr_test.is_open()) {
		IMPORTANT("File stream created!");

		for (int i = 0; i < 10; i++) {
			fstr_test << i << endl;
			LOG("[COLOR:GREEN]%i was written in the dummy file", i);
		}
		LOG("Writing finished! Now closing!");
		fstr_test.close();
	}
	else ERROR("Couldn't open stream!");
	system("pause");
}

Install (Windows)

Simply copy the header files to your project's build directory.


Console Logging

ahxrlogger provides 4 logging levels. Each level provides a threaded and non-threaded variant.

ERROR( const char * format, ... );
ERROR_THREAD( const char * format, ... );
WARNING( const char * format, ... );
WARNING_THREAD( const char * format, ... );
IMPORTANT( const char * format, ... );
IMPORTANT_THREAD( const char * format, ... );
LOG( const char * format, ... );
LOG_THREAD( const char * format, ... );

As you can see from the example earlier, its a very simple concept. If these names conflict with your project, define AHXRLOGGER_DISABLE_QUICK_SHORTCUTS on top of your project. If you wish to define your own macros to call your logging functions, refer to your define to the following functions:

LevelFunctionThread
Errorlogger_eNo
Errorlogger_t_eYes
Warninglogger_wNo
Warninglogger_t_wYes
Importantlogger_iNo
Importantlogger_t_iYes
GeneralloggerNo
Generallogger_tYes

By default, ahxrlogger will automatically create a new line whenever a log is printed. To remove this feature undefine AHXRLOGGER_CONSOLE_LINE after you've included ahxrlogger.h.

If you want to specify a console handle you want the logging to show up on, the following function is available:

ahxrlogger_handle( HANDLE consoleHandle )

Console Color Logging

If you wish to log something with a specific color scheme, place the following markdown anywhere in the string:

[COLOR:MYCOLOR]

Replace MYCOLOR with any of the colors listed below:

By default, the color will automatically reset itself back to BLACK & WHITE after the log is printed. To remove this feature, undefine AHXRLOGGER_CONSOLE_RESET_COLOR after including ahxrlogger.h


File Logging

File logging can be managed with the following functions. The macros are pretty self-explanatory:

ahxrlogger_error_logging( bool toggle );
ahxrlogger_warning_logging( bool toggle );
ahxrlogger_important_logging( bool toggle );
ahxrlogger_general_logging( bool toggle );
ahxrlogger_toggle_logging( bool toggle );

ahxrlogger_file_general( const char * filePath );
ahxrlogger_file_error( const char * filePath );
ahxrlogger_file_warning( const char * filePath );
ahxrlogger_file_important( const char * filePath );

As you can see, you can change the file path you want a certain level to log at. ahxrlogger_toggle_logging will toggle logs on/off for ALL levels.

Notable Macros

MacroPurpose
AHXRLOGGER_DEFAULT_THREADSSet to true or false. This controls where logs will automatically thread. This is false by default.
AHXRLOGGER_LEVEL_PFX_ERRORContains the prefix of the error level
AHXRLOGGER_LEVEL_PFX_WARNINGContains the prefix of the warning level
AHXRLOGGER_LEVEL_PFX_IMPORTANTContains the prefix of the important level
COLOR_ERRORContains the color code for the error level
COLOR_WARNINGContains the color code for the error level
COLOR_IMPORTANTContains the color code for the error level
AHXRLOGGER_CONSOLE_REMOVE_COLOR_CODEIf you want the [COLOR:MYCOLOR] removed from your log. This is enabled by default!
MAX_PREFIX_SIZEMaximum Prefix size
ahxrlogger_flushFlushes the logging system