// Your code
#include <elephantlogger/log.h>
int main(int argc, char** argv) {
elephantlogger::init();
LOG_WTF("Log WTF");
LOG_ERROR("Log error");
LOG_WARNING("Log warning");
LOG_CONFIG("Log config");
LOG_INFO("Log info");
LOG_TRACE("Log trace");
LOG_DEBUG("Log debug");
LOG_DEBUG("Integer value: %d", 42);
LOG_DEBUG("Float value: %f", 31.9);
LOG_DEBUG("Bool value (true): %d", true);
LOG_DEBUG("NULL (Using d): %d", NULL);
LOG_DEBUG("NULL (Using s): %s", NULL);
LOG_DEBUG("String: %s / Integer: %d / Float: %f / Char: %c", "Hello", 2, 7.1, 'c');
int counter = 0;
while(counter < 12) {
counter++;
LOG_DEBUG("Log in loop (counter: %d)", counter);
}
return 0;
}
Easy to use and flexible C++ logger with support for custom outputs and filters. The goal is to easily filter and show the logs on several outputs.
- API may change.
- Warning: max log size is 255 chars (truncated if higher).
- No Windows support tested.
- Add color console output.
- Outputs
- Builtin outputs
LogOutput_File
LogOutput_Console
- Custom outputs
- Implement
LogOutput
interface - Add
LogOutput
in the logger
- Implement
- Builtin outputs
- Categories
- Default category for easy usage
- Up to 64 categories
- User defined categories
- Filters
- Category filters (global and output specific)
- Log level filters (global and output specific)
- Filters can be changed at runtime
- Enable / disable
- Enable logger
- Disable logger
- Enable a specific output
- Disable a specific output
- Default logging macros
LOG_WTF(msg, ...)
LOG_ERROR(msg, ...)
LOG_WARNING(msg, ...)
LOG_CONFIG(msg, ...)
LOG_INFO(msg, ...)
LOG_TRACE(msg, ...)
LOG_DEBUG(msg, ...)
- Category logging macros
LOG_WTF_IN(categoryID, msg, ...)
LOG_ERROR_IN(categoryID, msg, ...)
LOG_WARNING_IN(categoryID, msg, ...)
LOG_CONFIG_IN(categoryID, msg, ...)
LOG_INFO_IN(categoryID, msg, ...)
LOG_TRACE_IN(categoryID, msg, ...)
LOG_DEBUG_IN(categoryID, msg, ...)
- Configuration macros
ELEPHANTLOGGER_DISABLED
Totally disable the logger if definedELEPHANTLOGGER_MACROS_DISABLED
Remove the macro definitions (useelephantlogger::log()
instead)ELEPHANTLOGGER_ASSERT_ENABLED
Enable internal assert for debug
- Printf like log format
- Add the
include/
folder in your project's include paths. - Add
#include <elephantlogger/log.h>
in your code. - Call
elephantlogger::init()
in your main. - Log using
LOG_DBG("msg")
macro (change DGB with any other log levels). - Logs are sent to the default output.
#include <elephantlogger/log.h>
int main(int argc, char** argc) {
elephantlogger::init();
// Your code
return 0;
}
#include <string>
#include <elephantlogger/log.h>
#include <elephantlogger/outputs/LogOutput_File.h>
// Initialize the logger with custom outputs and categories.
static void elephant_customInit() {
static elephantlogger::LogOutput_File filelog("elephant.log");
elephantlogger::init();
elephantlogger::addOutput(&filelog, elephantlogger::LogLevel::Debug);
}
int main(int argc, char** argv) {
elephant_customInit();
LOG_WARNING("Some warning log");
LOG_DEBUG("Some debug log");
LOG_ERROR("Some error log");
LOG_CONFIG("Some config log");
LOG_TRACE("Some trace log");
LOG_INFO("Some information log");
return 0;
}
- C++11
- pragma support (pragma once)
mkdir build
cd build
cmake -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Release ..
make -j2
make run_ex_simple_usage
DCMAKE_BUILD_TYPE
options: Debug / Release / RelWithDebInfo / MinSizeRel
The autoformat uses clang-format
to apply the rules.
You can autoformat the whole code with the following command:
clang-format -i -style=file include/**/*.h
Several examples are available in the examples
directory.
- In the root folder, run
doxygen Doxyfile
- Documentation generated in
build/doxygen
folder.
See the github issues-section
Warning: in case of wrong log format (e.g., %s instead of %d), you will get weird errors without nice warning information (segfault in the worst case).
- Constantin Masson (GeekyMoose)
- Logo made by Marie-Pier Bouffard (www.artstation.com/mariepierbouffard)