A high-performance, thread-safe logging library for C applications, designed to provide reliable and concurrent log handling with minimal performance overhead.
- Multi-threaded Logging: Efficiently handles log writing in a separate thread, ensuring minimal impact on application performance.
- Thread Safety: Synchronized access to log files, making it safe for use in multi-threaded applications.
- In-memory Queueing: Queues log messages in memory for efficient batch processing.
- Reverse Order Log Reading: Provides functionality to read logs in reverse order, showing the most recent entries first.
- Customizable Log Levels: Supports different log levels (DEBUG, INFO, WARN, ERROR) for detailed logging control.
- GCC compiler or any standard C compiler with support for the POSIX Threads (pthreads) library.
- Basic knowledge of C programming and multi-threaded concepts.
Clone the repository to your local machine:
git clone https://github.com/harshithsunku/ThreadSafeCLogger.gitNavigate to the cloned directory:
cd ThreadSafeCLoggerCompile the library:
gcc -o logger main.c logger.c -lpthreadYou can build the project using the provided Makefile:
makeThis will create an executable named logger.
To clean up the build (remove the compiled output), run:
make cleanHere's a simple example of how to use ThreadSafeCLogger in your C application:
#include "logger.h"
int main() {
// Initialize the logger
log_init("log.txt", LOG_LEVEL_DEBUG);
// Write log messages
log_write(LOG_LEVEL_INFO, "Application started");
// Your application code here
log_write(LOG_LEVEL_INFO, "Application ending");
// Close the logger
log_close();
return 0;
}log_init: Initializes the logging system.log_write: Writes a log message to the queue.log_close: Closes the logging system, ensuring all messages are processed.
For more detailed documentation, see docs/documentation.md.
Contributions to ThreadSafeCLogger are welcome! Please read our Contributing Guidelines for more information on how to contribute.
This project is licensed under the GNU General Public License v3 (GPLv3).
- Thanks to all contributors who have helped with the development and improvement of ThreadSafeCLogger.