diff --git a/README.md b/README.md index 2a875ad..bb3f354 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,57 @@ -# cct -Common C Tools +# cct (Common C Tools) + +This is a collection of useful and common C tools that can be installed and used in any C project using C99 or higher. The goal of this project is to provide a set of reusable and well-tested functions that can be easily integrated into various C projects. + +## Library Structure + +The CCT library is compiled into a static library, which includes several header files. The main header files are: + +- [log.h](./log.h): Provides logging functionality with customizable log levels and output streams + +## Installation + +To install the CCT library, follow these steps: + +1. Clone the repository: + +```bash +git clone https://github.com/vas-dav/cct.git +``` + +2. Build the library: + +```bash +cd cct && make +``` + +3. Install the library: + +```bash +make install +``` + +## Using the library + +> This example is trivial only created to get started. +> More diverse use cases and documentation is available in [docs](./docs/). + +Once the library is installed, it can be used in any source file as follows: + +```c +#include + +int main(int argc, char **argv) { + cct_log("Hello from CCT!"); + return 0; +} +``` + +And compiled inlcuding the library: + +```bash + hello.c -lcct +``` + +## Documentation + +All of the documentation can be found [here](./docs/). diff --git a/docs/log/README.md b/docs/log/README.md new file mode 100644 index 0000000..df8f9d3 --- /dev/null +++ b/docs/log/README.md @@ -0,0 +1,60 @@ +# CCT Logging API + +This document provides a comprehensive overview of the logging API offered by the CCT library. The API encompasses various logging functions that facilitate the logging of messages at different severity levels. + +## Macros + +### #inlcude + +### `cct_log` + +Logs a plain message utilizing the specified format string and arguments. + +- **Parameters:** + - `fmt`: The format string for the log message. + - `...`: The arguments to be utilized in the format string. + +### `cct_info` + +Logs an informational message utilizing the specified format string and arguments. This macro additionally traces the log line, function name, and file name. + +- **Parameters:** + - `fmt`: The format string for the log message. + - `...`: The arguments to be utilized in the format string. + +### `cct_warning` + +Logs a warning message utilizing the specified format string and arguments. This macro also traces the log line, function name, and file name. + +- **Parameters:** + - `fmt`: The format string for the log message. + - `...`: The arguments to be utilized in the format string. + +### `cct_error` + +Logs an error message utilizing the specified format string and arguments, and subsequently terminates the program. This macro traces the log line, function name, and file name. + +- **Parameters:** + - `fmt`: The format string for the log message. + - `...`: The arguments to be utilized in the format string. + +### `cct_debug` + +Logs a debug message utilizing the specified format string and arguments. This macro also traces the log line, function name, and file name. + +- **Parameters:** + - `fmt`: The format string for the log message. + - `...`: The arguments to be utilized in the format string. + +## Features & Limitations + +- All logging macros, with the exception of `cct_log`, will trace the log line, function name, and file name. +- The total length of the message for any of the logging macros must not exceed 256 bytes. + +## Usage + +Check example in [here](./main.c). + +## Conclusion + +The CCT Logging API provides a straightforward and effective mechanism for logging messages of differing severity levels. By employing these macros, developers can efficiently monitor the execution flow of their applications and manage errors in a systematic manner. diff --git a/docs/log/main.c b/docs/log/main.c new file mode 100644 index 0000000..ebd51f9 --- /dev/null +++ b/docs/log/main.c @@ -0,0 +1,20 @@ +#include + +int main() { + // Log a plain message + cct_log("This is a plain log message.\n"); + + // Log an info message + cct_info("The value of pi is approximately %f.\n", 3.14159); + + // Log a warning message + cct_warning("The system is running low on memory.\n"); + + // Log an error message and exit the program + cct_error("The system has encountered a fatal error.\n"); + + // Log a debug message + cct_debug("Unreachable code"); + + return 0; +}