log-cpp is a simple log header for debug, support log output to stderr, file, console and IDE(only win32). Log will auto be removed in release mode before source compile for performance.
You just need download log.h and log.cpp files then add into your C++ project.
Include log.h header file in your source code then using macro such as:
- LOG_D: for debug tag
- LOG_E: for error tag
- LOG_I: for infor tag
- LOG_W: for warning tag
- LOG: default tag, current version equals LOG_D
Each log line will separate in 5 parts are: tag, file name, lines number, function name and message content.
You can use standard output format like printf function for show message in log like this:
LOG("number is %d, string is %s", yourNumber, yourString);
This is a simple demo for using the log header:
#include "log.h"
int main()
{
LOG("this is a simple log");
}
Then output could like this:
Current version support output to stderr, file, console(simple messge) and IDE(just win32). Above example show you ouput in IDE(Visual Studio). If you want to switch output to other, you just change define line in log.h like this:
#define DEBUG_OUTPUT_MODE DEBUG_OUTPUT_IDE
Log output in stderr: change DEBUG_OUTPUT_MODE to this
#define DEBUG_OUTPUT_MODE DEBUG_OUTPUT_STREAM
In fact, your log will be shown in console but we use stderr instead of stdout. Output like this:
Log output in file: change DEBUG_OUTPUT_MODE to this
#define DEBUG_OUTPUT_MODE DEBUG_OUTPUT_FILE
Log file will be written in current directory with file name is debug.log which has been defined:
#define DEBUG_FILENAME "debug.log"
When you write a log message to log file, the log file will be opened to write a log line then close. Log file like this:
Log output in console: change DEBUG_OUTPUT_MODE to this
#define DEBUG_OUTPUT_MODE DEBUG_OUTPUT_CON
Like Log output in stderr but only tag and message content will be shown.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
##Dependencies This project not required the dependencies, just get log.h and log.cpp.
Version 1.0.0 support log output to stderr, file, console and IDE(just win32). Provides LOG, LOG_D, LOG_E, LOG_I and LOG_W for different purposes.
Developed by sontx/noem, some useful information:
- Home: www.sontx.in
- My blog: www.blog.sontx.in
- Email: xuanson33bk@gmail.com
- Facebook: No Em
Copyright 2016 Tran Xuan Son