FlexiLog is a lightweight, high-performance C++ logging library designed to facilitate efficient debugging and monitoring. Unlike other popular logging libraries, FlexiLog offers compile-time log control with zero-overhead disabling, rich enumeration options for detailed debug information, customizable print restrictions, and operates independently without any external dependencies.
- Template-Based Log Control: Enable or disable logging at compile time with zero runtime overhead.
- Rich Enumeration Options: Choose from a variety of debug information such as line number, filename, CPU usage, and more.
- Customizable Print Restrictions: Limit the number of log prints, control print frequency, and set complex conditions to manage log output effectively.
- User-Defined Debug Information: Extend the library with custom debug details tailored to your project's needs.
- No External Dependencies: Pure C++ implementation ensuring easy integration into any project without additional library requirements.
- High Performance: Optimized for minimal impact on application performance, especially when logging is disabled.
- C++17 or later
- Compatible with major compilers like GCC, Clang, and MSVC
-
Clone the Repository
git clone https://github.com/yourusername/FlexiLog.git cd FlexiLog
-
Build and Install
mkdir build cd build cmake .. make sudo make install
-
Download Source Files
Download the
FlexiLog.hpp
header file from the repository. -
Include in Your Project
Place the
FlexiLog.hpp
file into your project's include directory and include it in your source files:#include "FlexiLog.hpp"
#include "FlexiLog.hpp"
int main() {
FlexiLog::log(FlexiLog::LogLevel::INFO, "Application started.");
FlexiLog::log(FlexiLog::LogLevel::DEBUG, "Debugging value: {}", 42);
FlexiLog::log(FlexiLog::LogLevel::ERROR, "An error occurred: {}", "Out of memory");
return 0;
}
Enable or disable logging at compile time by defining or undefining the ENABLE_FLEXILOG
macro.
// To enable logging
#define ENABLE_FLEXILOG
#include "FlexiLog.hpp"
// To disable logging
// #define ENABLE_FLEXILOG
#include "FlexiLog.hpp"
When logging is disabled, all FlexiLog::log
calls are removed at compile time, ensuring no performance overhead.
Choose the debug information to include in your logs using enumerations.
#include "FlexiLog.hpp"
int main() {
FlexiLog::setDetails({
FlexiLog::LogDetail::LineNumber,
FlexiLog::LogDetail::FileName,
FlexiLog::LogDetail::CPUUsage
});
FlexiLog::log(FlexiLog::LogLevel::INFO, "Detailed log entry.");
return 0;
}
Control the number of times a log message is printed and its frequency.
#include "FlexiLog.hpp"
int main() {
FlexiLog::setMaxPrintCount(5); // Maximum 5 prints
FlexiLog::setPrintFrequency(10); // Maximum 10 prints per second
for(int i = 0; i < 100; ++i) {
FlexiLog::log(FlexiLog::LogLevel::DEBUG, "This will be printed up to 5 times at 10 prints per second.");
}
return 0;
}
Add your own debug information by registering custom functions.
#include "FlexiLog.hpp"
std::string getCustomInfo() {
// Implement your custom info retrieval
return "CustomInfo";
}
int main() {
FlexiLog::addCustomDetail(getCustomInfo);
FlexiLog::log(FlexiLog::LogLevel::INFO, "Log with custom info.");
return 0;
}
Enumerates the severity levels of logs.
TRACE
DEBUG
INFO
WARN
ERROR
FATAL
Enumerates the types of debug information available.
LineNumber
FileName
FunctionName
Timestamp
CPUUsage
MemoryUsage
Custom
Logs a message with the specified log level.
template<typename... Args>
static void log(LogLevel level, const std::string& message, Args&&... args);
Sets the details to include in each log entry.
static void setDetails(const std::vector<LogDetail>& details);
Registers a custom function to retrieve additional debug information.
static void addCustomDetail(std::function<std::string()> customFunc);
Sets the maximum number of times a specific log message can be printed.
static void setMaxPrintCount(int count);
Sets the maximum number of log prints allowed per second.
static void setPrintFrequency(int maxPerSecond);
Sets a custom condition that must be met for a log to be printed.
static void setPrintCondition(std::function<bool()> condition);
#include "FlexiLog.hpp"
int main() {
FlexiLog::log(FlexiLog::LogLevel::INFO, "Starting the application...");
FlexiLog::log(FlexiLog::LogLevel::DEBUG, "Variable x = {}", 10);
FlexiLog::log(FlexiLog::LogLevel::ERROR, "Failed to load resource: {}", "config.yaml");
return 0;
}
#include "FlexiLog.hpp"
int main() {
FlexiLog::setDetails({
FlexiLog::LogDetail::Timestamp,
FlexiLog::LogDetail::FileName,
FlexiLog::LogDetail::LineNumber,
FlexiLog::LogDetail::CPUUsage
});
FlexiLog::log(FlexiLog::LogLevel::INFO, "Application initialized with detailed debug info.");
return 0;
}
#include "FlexiLog.hpp"
int main() {
FlexiLog::setMaxPrintCount(3);
FlexiLog::setPrintFrequency(2); // 2 prints per second
for(int i = 0; i < 10; ++i) {
FlexiLog::log(FlexiLog::LogLevel::DEBUG, "This debug message will be limited.");
}
return 0;
}
#include "FlexiLog.hpp"
std::string getUserID() {
// Assume we retrieve a user ID from somewhere
return "User123";
}
int main() {
FlexiLog::addCustomDetail(getUserID);
FlexiLog::log(FlexiLog::LogLevel::INFO, "User action logged.");
return 0;
}
Contributions are welcome! Whether it's reporting bugs, suggesting features, or submitting pull requests, your input helps make FlexiLog better.
-
Fork the Repository
Click the "Fork" button at the top right of the repository page.
-
Clone Your Fork
git clone https://github.com/yourusername/FlexiLog.git cd FlexiLog
-
Create a New Branch
git checkout -b feature/YourFeatureName
-
Make Your Changes
Implement your feature or fix bugs.
-
Commit Your Changes
git commit -m "Add feature: YourFeatureName"
-
Push to Your Fork
git push origin feature/YourFeatureName
-
Create a Pull Request
Go to the original repository and create a pull request from your fork.
- Follow C++ best practices and coding standards.
- Ensure code is well-documented and readable.
- Write unit tests for new features or bug fixes.
- Update the
README.md
if necessary.
This project is licensed under the MIT License.
FlexiLog aims to provide developers with a powerful yet simple logging solution tailored for high-performance C++ applications. By focusing on flexibility, efficiency, and ease of use, FlexiLog stands out as a reliable tool for debugging and monitoring your projects.
For any questions, issues, or contributions, feel free to open an issue or submit a pull request on GitHub.