Skip to content
/ log-cpp Public

A simple log header for debug, support log output to stderr, file, console and IDE(only win32)

License

Notifications You must be signed in to change notification settings

sontx/log-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Installation

You just need download log.h and log.cpp files then add into your C++ project.

Usage

Include log.h header file in your source code then using macro such as:

  1. LOG_D: for debug tag
  2. LOG_E: for error tag
  3. LOG_I: for infor tag
  4. LOG_W: for warning tag
  5. 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.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

##Dependencies This project not required the dependencies, just get log.h and log.cpp.

History

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.

Author

Developed by sontx/noem, some useful information:

License

Copyright 2016 Tran Xuan Son

About

A simple log header for debug, support log output to stderr, file, console and IDE(only win32)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published