diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1d72404 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.h linguist-language=c \ No newline at end of file diff --git a/.gitignore b/.gitignore index c6127b3..7d4d5c4 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ *.i*86 *.x86_64 *.hex +*out # Debug files *.dSYM/ @@ -50,3 +51,42 @@ modules.order Module.symvers Mkfile.old dkms.conf + +build/ +*build/ +*/build/ + +dist/ +*dist/ +*/dist/ + +# CMake +*/CMakeFiles/ +*CMakeCache.txt +*CMakeFiles/ +*.vcx* +*.sln +*CMakeCache* +*.cmake +*Makefile* + +# IDE Folders +*.vscode/ +*.vs/ + +# Others +*.tmp +*/expand +*expand.* +*installscripts/include* +*result.txt +*.swb +*.swp +*.swo + +*.xml +*.tap +*.tmp + +out +*.DS_Store* \ No newline at end of file diff --git a/include/exotic/logax.h b/include/exotic/logax.h new file mode 100644 index 0000000..9ccb351 --- /dev/null +++ b/include/exotic/logax.h @@ -0,0 +1,343 @@ + +/** + \copyright MIT License Copyright (c) 2021, Adewale Azeez + \author Adewale Azeez + \date 18 Nov 2021 + \file logax.h +*/ + +#ifndef EXOTIC_LOGAX_H +#define EXOTIC_LOGAX_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#ifndef LOGAX_NO_TIME +#include +#endif + +/** + The inline keyword to optimize the function. In + C89 and C90 the inline keyword semantic is + different from current C standard semantic hence + for compilation targeting C89 or C99 the inline + keyword is ommited. +*/ +#ifdef __STDC_VERSION__ + #define __LOGAX_STDC_VERSION__ __STDC_VERSION__ +#else + #ifdef __cplusplus + #if __cplusplus > 199711L + #define __LOGAX_STDC_VERSION__ __cplusplus + #endif + #endif +#endif +#ifndef __LOGAX_STDC_VERSION__ + #ifdef __FUNCTION__ + #define __LOGAX_FUNCTION__ __FUNCTION__ + #else + #define __LOGAX_FUNCTION__ "" + #endif + #define CESTER_NULL 0L +#else + #define __LOGAX_FUNCTION__ __func__ + #define CESTER_NULL NULL +#endif + +#if defined(_WIN32) && defined(LOGAX_USE_OLD_CONSOLE_MODE) + +#define LOGAX_RESET_TERMINAL 15 /**< reset the terminal color //Nothing */ +#define LOGAX_FOREGROUND_TRACE 11 /**< trace terminal foreground color - cyan */ +#define LOGAX_FOREGROUND_DEBUG 2 /**< debug terminal foreground color - green */ +#define LOGAX_FOREGROUND_INFO 5 /**< info terminal foreground color - magenta */ +#define LOGAX_FOREGROUND_WARN 6 /**< warn terminal foreground color - yellow */ +#define LOGAX_FOREGROUND_ERROR 4 /**< error terminal foreground color - red */ +#define LOGAX_FOREGROUND_FATAL 4 /**< fatal terminal foreground color - red */ +#define LOGAX_RESET_TERMINAL_ATTR() SetConsoleTextAttribute(hConsole, default_color); /**< reset the terminal color */ + +#else + +#define LOGAX_RESET_TERMINAL "\x1B[0m" /**< reset the terminal color */ +#define LOGAX_FOREGROUND_TRACE "\x1B[36m" /**< trace terminal foreground color - cyan */ +#define LOGAX_FOREGROUND_DEBUG "\x1B[32m" /**< debug terminal foreground color - green */ +#define LOGAX_FOREGROUND_INFO "\x1B[35m" /**< info terminal foreground color - magenta */ +#define LOGAX_FOREGROUND_WARN "\x1B[33m" /**< warn terminal foreground color - yellow */ +#define LOGAX_FOREGROUND_ERROR "\x1B[31m" /**< error terminal foreground color - red */ +#define LOGAX_FOREGROUND_FATAL "\x1B[31m" /**< fatal terminal foreground color - red */ +#define LOGAX_RESET_TERMINAL_ATTR() /**< reset the terminal color */ + +#endif + +#ifndef LOGAX_NO_CALLBACK +/** + +*/ +#define LOGAX_MAX_CALLBACKS 20 + +/* + +*/ +typedef void (*logax_callback)(int level, const char *file_path, size_t line, const char *data); +#endif + +/** + +*/ +enum LogaxOption +{ + LOGAX_OPTION_QUITE = 1 << 1, /**< binary 0010 */ +#ifndef LOGAX_NO_TIME + LOGAX_OPTION_DATE = 1 << 2, /**< binary 0100 */ + LOGAX_OPTION_TIME = 1 << 3, /**< binary 1000 */ + LOGAX_OPTION_DATE_TIME = 1 << 4, +#endif + LOGAX_OPTION_FILE_PATH = 1 << 5, + LOGAX_OPTION_FILE_NAME_ONLY = 1 << 6, + LOGAX_OPTION_LINE_NUMBER = 1 << 7, + LOGAX_OPTION_COLORED = 1 << 8, + LOGAX_OPTION_FUNCTION = 1 << 9 +}; + +/** + +*/ +enum LogaxLevel +{ + LOGAX_LEVEL_TRACE = 1 << 10, /**< ? */ + LOGAX_LEVEL_DEBUG = 1 << 11, /**< ? */ + LOGAX_LEVEL_INFO = 1 << 12, /**< ? */ + LOGAX_LEVEL_WARN = 1 << 13, + LOGAX_LEVEL_ERROR = 1 << 14, + LOGAX_LEVEL_FATAL = 1 << 15 +}; + +/** + +*/ +enum LogaxFormatter +{ + LOGAX_FORMATTER_PLAIN_TEXT = 1 << 20, /**< ? */ + LOGAX_FORMATTER_TEXT = 1 << 21, /**< ? */ + LOGAX_FORMATTER_JSON = 1 << 23 /**< ? */ +}; + +/** + +*/ +struct logax_logger_s { + int level; /**< ? */ + int options; /**< ? */// use bitwize for options like quiet, time, long date, shortdate, e.t.c + int formatter; /**< ? */// external formatter should begin from 100 +#if !defined(LOGAX_NO_OUTPUT_STREAM) + FILE *output_stream; /**< ? */ +#endif +#ifndef LOGAX_NO_CALLBACK + logax_callback callbacks[LOGAX_MAX_CALLBACKS]; +#endif +#ifndef LOGAX_FUNCTIONAL_LOGGING_ONLY + void (*write) (const char *fmt, ...); + void (*trace) (const char *fmt, ...); + void (*debug) (const char *fmt, ...); + void (*info) (const char *fmt, ...); + void (*warn) (const char *fmt, ...); + void (*error) (const char *fmt, ...); + void (*fatal) (const char *fmt, ...); +#endif +}; + +/** + +*/ +typedef struct logax_logger_s LogaxLogger; + +/** + +*/ +static void logax_init_logger(LogaxLogger *logax_logger) { + logax_logger->level = 0; + logax_logger->options = 0; + logax_logger->formatter = LOGAX_FORMATTER_PLAIN_TEXT; +#if defined(stdout) && !defined(LOGAX_NO_OUTPUT_STREAM) + logax_logger->output_stream = stdout; +#endif +} + +#if !defined(LOGAX_NO_OUTPUT_STREAM) +/** + +*/ +static void logax_init_logger_ws(LogaxLogger *logax_logger, FILE *output_stream) { + logax_logger->level = 0; + logax_logger->options = 0; + logax_logger->formatter = LOGAX_FORMATTER_PLAIN_TEXT; + logax_logger->output_stream = output_stream; +} +#endif + +/* + +*/ +static size_t logax_cstr_length(char char_array[]) { + size_t length = 0; + if (char_array == NULL) { return length; } + while(char_array[length] != '\0') { + length++; + } + return length; +} + +/** + +*/ +static void logax_extract_name_only(char const* const file_path, char file_name_only[]) { + unsigned i = 0, j = -1; + while (file_path[i] != '\0') { + if (file_path[i] == '\\' || file_path[i] == '/') { + j = 0; + } else if (j != -1) { + file_name_only[j] = file_path[i]; + j++; + } + ++i; + } + file_name_only[j] = '\0'; +} + +#if defined(_WIN32) && defined(LOGAX_USE_OLD_CONSOLE_MODE) +/** + +*/ +#define LOGAX_WRITE_LEVEL_COLOR__INTERNALL__(options) +#else +/** + +*/ +#define LOGAX_WRITE_LEVEL_COLOR__INTERNALL__(prefix_spaces, level) if (is_colored) fprintf(stream, "%s%s%s", prefix_spaces, LOGAX_FOREGROUND_##level, #level);\ + else fprintf(stream, "%s%s", prefix_spaces, #level); +#endif + +/** + +*/ +static void logax_write_plaintext_format_to_stream__internal__(FILE *stream, int options, const char *file_path, const size_t line_number, const char *function_name, const char *fmt, ...) { + va_list va_arg; + if (options & LOGAX_OPTION_QUITE) return; + unsigned is_colored = (options & LOGAX_OPTION_COLORED); + /* date and time */ +#ifndef LOGAX_NO_TIME + time_t current_time = time(NULL); + current_time = localtime(¤t_time); + if ((options & LOGAX_OPTION_DATE_TIME) || (options & LOGAX_OPTION_DATE)) { + char date_buffer[16]; + date_buffer[strftime(date_buffer, sizeof(date_buffer), "%Y-%m-%d", current_time)] = '\0'; + fprintf(stream, "%s", date_buffer); + } + if ((options & LOGAX_OPTION_DATE_TIME) || (options & LOGAX_OPTION_TIME)) { + char time_buffer[16]; + time_buffer[strftime(time_buffer, sizeof(time_buffer), "%H:%M:%S", current_time)] = '\0'; + if ((options & LOGAX_OPTION_DATE_TIME) || (options & LOGAX_OPTION_DATE)) { + fprintf(stream, " "); + } + fprintf(stream, "%s", time_buffer); + } +#endif + /* logging level */ + if (options & LOGAX_LEVEL_TRACE) { + LOGAX_WRITE_LEVEL_COLOR__INTERNALL__(" ", TRACE); + } else if (options & LOGAX_LEVEL_DEBUG) { + LOGAX_WRITE_LEVEL_COLOR__INTERNALL__(" ", DEBUG); + } else if (options & LOGAX_LEVEL_INFO) { + LOGAX_WRITE_LEVEL_COLOR__INTERNALL__(" ", INFO); + } else if (options & LOGAX_LEVEL_WARN) { + LOGAX_WRITE_LEVEL_COLOR__INTERNALL__(" ", WARN); + } else if (options & LOGAX_LEVEL_ERROR) { + LOGAX_WRITE_LEVEL_COLOR__INTERNALL__(" ", ERROR); + } else if (options & LOGAX_LEVEL_FATAL) { + LOGAX_WRITE_LEVEL_COLOR__INTERNALL__(" ", FATAL); + } + if (is_colored) fprintf(stream, "%s", LOGAX_RESET_TERMINAL); + /* file path and line number */ + if ((options & LOGAX_OPTION_FILE_PATH) || (options & LOGAX_OPTION_FILE_NAME_ONLY)) { + if (options & LOGAX_OPTION_FILE_PATH) { + fprintf(stream, " %s", file_path); + } else { + char file_name_only[logax_cstr_length((char *)file_path)]; + logax_extract_name_only(file_path, file_name_only); + fprintf(stream, " %s", file_name_only); + } + } + if (options & LOGAX_OPTION_LINE_NUMBER) { + if (!((options & LOGAX_OPTION_FILE_PATH) || (options & LOGAX_OPTION_FILE_NAME_ONLY))) { + fprintf(stream, " "); + } + fprintf(stream, ":%lld", line_number); + } + if (options & LOGAX_OPTION_FUNCTION) { + fprintf(stream, " --- [%s\t]", function_name); + } + fprintf(stream, " "); + va_start(va_arg, fmt); + vfprintf(stream, fmt, va_arg); + va_end(va_arg); + fprintf(stream, "\n"); +} + +/** + +*/ +#define logax_write_plaintext_format_to_stream(stream, options, fmt, ...) logax_write_plaintext_format_to_stream__internal__(stream, options, __FILE__, __LINE__, __LOGAX_FUNCTION__, fmt, __VA_ARGS__) + +#define logax_write_text_format_to_stream + +/** + +*/ +#ifndef LOGAX_NO_FUNCTIONAL_LOGGING + +/** + +*/ +static void logax_log_write(LogaxLogger logax_logger, const char *fmt, ...) { + +} +#endif + +// log_trace(const char *fmt, ...); +// log_debug(const char *fmt, ...); +// log_info(const char *fmt, ...); +// log_warn(const char *fmt, ...); +// log_error(const char *fmt, ...); +// log_fatal(const char *fmt, ...); + +/** + +*/ +#ifndef LOGAX_DEBUG +/** + +*/ +static void logax_print_logger_info_internal__(FILE *stream, LogaxLogger logax_logger, const char *file_path, const size_t line_number) { + fprintf(stream, "LOGAX_LOGGER %s:%d\n", file_path, line_number); + fprintf(stream, " output_stream=%p, level=%d, options=%d\n", logax_logger.output_stream, logax_logger.level, logax_logger.options); +} + +/** + +*/ +#define logax_print_logger_info(stream, logax_logger) logax_print_logger_info_internal__(stream, logax_logger, __FILE__, __LINE__) +#else +/** + +*/ +#define logax_print_logger_info(stream, logax_logger) +#endif + + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..c688268 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,59 @@ +#!cmake CMakeLists.txt -G"Unix Makefiles"; make +cmake_minimum_required(VERSION 3.17) +project(libfio_tests VERSION 1.0) + +set(FILE_EXT "") +set(INCLUDE_PATHS -I${PWD}/../../include/ -I${PWD}/../include/ -I../../include/ -I../include/) +include_directories(${PWD}/../../include/ ${PWD}/../include/ ../../include/ ../include/) +add_executable(logax_test ./empty_c_file.c) +set_target_properties(logax_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ./build/ ) + +IF (WIN32) + set(FILE_EXT ".exe") +ENDIF() + +# build and run the tests +file(GLOB files "./*/test_*.c" "./*/*/test_*.c") +foreach(filepath ${files}) + message(STATUS "FilePath: " ${filepath} ) + get_filename_component(filename ${filepath} NAME) + get_filename_component(filenameonly ${filepath} NAME_WLE) + + add_custom_target(${filenameonly}__ + + COMMAND echo ------------------------------------------- + COMMAND echo Compiling ${filenameonly} + COMMAND echo ------------------------------------------- + + # clang + #COMMAND clang -I. ${INCLUDE_PATHS} ${filepath} -o ./build/${filenameonly}_clang${FILE_EXT} + #COMMAND clang -ansi -pedantic-errors -I. ${INCLUDE_PATHS} ${filepath} -o ./build/${filenameonly}_clang_ansi${FILE_EXT} + #COMMAND clang++ -I. ${INCLUDE_PATHS} ${filepath} -o ./build/${filenameonly}_clang_cpp${FILE_EXT} + + # gcc + COMMAND gcc -I. ${INCLUDE_PATHS} ${filepath} -o ./build/${filenameonly}_gcc${FILE_EXT} + COMMAND gcc -ansi -pedantic-errors -I. ${INCLUDE_PATHS} ${filepath} -o ./build/${filenameonly}_gcc_ansi${FILE_EXT} + COMMAND g++ -I. ${INCLUDE_PATHS} ${filepath} -o ./build/${filenameonly}_gcc_cpp${FILE_EXT} + ) + + add_custom_command(TARGET logax_test + POST_BUILD + + COMMAND echo ------------------------------------------- + COMMAND echo Running ${filenameonly} + COMMAND echo ------------------------------------------- + + # clang + #COMMAND ./build/${filenameonly}_clang${FILE_EXT} + #COMMAND ./build/${filenameonly}_clang_ansi${FILE_EXT} --logax-output=junitxml + #COMMAND ./build/${filenameonly}_clang_cpp${FILE_EXT} --logax-output=tap + + # gcc + COMMAND ./build/${filenameonly}_gcc${FILE_EXT} + COMMAND ./build/${filenameonly}_gcc_ansi${FILE_EXT} --logax-output=junitxml + COMMAND ./build/${filenameonly}_gcc_cpp${FILE_EXT} --logax-output=tapV13 + ) + + add_dependencies(logax_test ${filenameonly}__) +endforeach() + diff --git a/test/crash_test.c b/test/crash_test.c new file mode 100644 index 0000000..df13718 --- /dev/null +++ b/test/crash_test.c @@ -0,0 +1,17 @@ +/*!gcc {0} -I. -I../include/ -o out; ./out --cester-verbose */ + +#include +#include + +CESTER_TEST(test_stdout, test_inst, + //CESTER_CAPTURE_STDOUT(); + + int options = 0; + //options = LOGAX_OPTION_DATE_TIME >> options; + options = LOGAX_OPTION_DATE | LOGAX_OPTION_TIME; + + //printf("%d->%d\n", options, options & LOGAX_OPTION_DATE); + //logax_write_to_stream(stdout, options, "Log%s\n", "Yahoo"); + + //CESTER_RELEASE_STDOUT(); +) diff --git a/test/empty_c_file.c b/test/empty_c_file.c new file mode 100644 index 0000000..131fde4 --- /dev/null +++ b/test/empty_c_file.c @@ -0,0 +1,9 @@ + +#ifndef EMPTY_FOR_CMAKE +#define EMPTY_FOR_CMAKE + +int main(int argc, char** argv) { + return 0; +} + +#endif diff --git a/test/test_init_logax.c b/test/test_init_logax.c new file mode 100644 index 0000000..7b78a5c --- /dev/null +++ b/test/test_init_logax.c @@ -0,0 +1,37 @@ +/*!gcc {0} -I. -I../../include/ -I../../libxtd/include/ -I../include/ -I../../../libcester/include -o out; ./out */ +/*!g++ -ansi -pedantic-errors {0} -I. -I../../include/ -I../../../libxtd/include/ -I../include/ -I../../../libcester/include -o out; ./out */ +/*!gcc {0} -I. -I../../include/ -I../../../libcester/include -I../include/ -o out; ./out */ +/*!g++ -std=c++11 {0} -I. -I../../include/ -I../include/ -I../../../libcester/include -o out; ./out */ + +#include +#include + +CESTER_TEST(init_logax_default_stdout, test_inst, { + LogaxLogger logax_logger; + logax_init_logger(&logax_logger); + + cester_assert_int_eq(logax_logger.level, 0); + cester_assert_int_eq(logax_logger.options, 0); + cester_assert_int_eq(logax_logger.formatter, LOGAX_FORMATTER_PLAIN_TEXT); + cester_assert_ptr_eq(logax_logger.output_stream, stdout); +}) + +CESTER_TEST(init_logax_with_stream, test_inst, { + LogaxLogger logax_logger_stdout; + LogaxLogger logax_logger_stderr; + LogaxLogger logax_logger_custom_stream; + + FILE *file; + logax_init_logger_ws(&logax_logger_stdout, stdout); + logax_init_logger_ws(&logax_logger_stderr, stderr); + logax_init_logger_ws(&logax_logger_custom_stream, file); + + cester_assert_ptr_eq(logax_logger_stdout.output_stream, stdout); + cester_assert_ptr_eq(logax_logger_stderr.output_stream, stderr); + cester_assert_ptr_eq(logax_logger_custom_stream.output_stream, file); +}) + +CESTER_OPTIONS( + CESTER_VERBOSE_LEVEL(3); +) + diff --git a/test/test_write_plaintext_format_to_stream.c b/test/test_write_plaintext_format_to_stream.c new file mode 100644 index 0000000..e687a6c --- /dev/null +++ b/test/test_write_plaintext_format_to_stream.c @@ -0,0 +1,111 @@ +/*!gcc {0} -I. -I../../include/ -I../../libxtd/include/ -I../include/ -I../../../libcester/include -o out; ./out */ +/*!g++ -ansi -pedantic-errors {0} -I. -I../../include/ -I../../../libxtd/include/ -I../include/ -I../../../libcester/include -o out; ./out */ +/*!gcc {0} -I. -I../../include/ -I../../../libcester/include -I../include/ -o out; ./out */ +/*!g++ -std=c++11 {0} -I. -I../../include/ -I../include/ -I../../../libcester/include -o out; ./out */ + +#include +#include + +#define LOGAX_OPTIONS_VERBOSE LOGAX_OPTION_DATE_TIME | LOGAX_OPTION_COLORED | LOGAX_OPTION_FILE_PATH | LOGAX_OPTION_LINE_NUMBER | LOGAX_OPTION_FUNCTION +#define LOGAX_OPTIONS_MINIMAL LOGAX_OPTION_DATE_TIME | LOGAX_OPTION_COLORED | LOGAX_OPTION_FILE_NAME_ONLY | LOGAX_OPTION_LINE_NUMBER +#define LOGAX_OPTIONS_VERBOSE_NO_COLOR LOGAX_OPTION_DATE_TIME | LOGAX_OPTION_FILE_PATH | LOGAX_OPTION_LINE_NUMBER | LOGAX_OPTION_FUNCTION +#define LOGAX_OPTIONS_MINIMAL_NO_COLOR LOGAX_OPTION_DATE_TIME | LOGAX_OPTION_FILE_NAME_ONLY | LOGAX_OPTION_LINE_NUMBER + +CESTER_TEST(logax_write_plaintext_format_to_stream_verbose, test_inst, { + CESTER_CAPTURE_STDOUT(); + + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_VERBOSE | LOGAX_LEVEL_TRACE, "%s", "This is a trace output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_VERBOSE | LOGAX_LEVEL_DEBUG, "%s", "This is a debug output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_VERBOSE | LOGAX_LEVEL_INFO, "%s", "This is an info output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_VERBOSE | LOGAX_LEVEL_WARN, "%s", "This is a warning output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_VERBOSE | LOGAX_LEVEL_ERROR, "%s", "This is an error output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_VERBOSE | LOGAX_LEVEL_FATAL, "%s", "This is a fatal output"); + + + cester_assert_stdout_stream_content_contain("\x1B[36mTRACE\x1B[0m"); + cester_assert_stdout_stream_content_contain("\x1B[32mDEBUG\x1B[0m"); + cester_assert_stdout_stream_content_contain("\x1B[35mINFO\x1B[0m"); + cester_assert_stdout_stream_content_contain("\x1B[33mWARN\x1B[0m"); + cester_assert_stdout_stream_content_contain("\x1B[31mERROR\x1B[0m"); + cester_assert_stdout_stream_content_contain("\x1B[31mFATAL\x1B[0m"); + cester_assert_stdout_stream_content_contain(".c:17 --- [cester_test_logax_write_plaintext_format_to_stream_verbose\t] This is a trace output\n"); + cester_assert_stdout_stream_content_contain(".c:18 --- [cester_test_logax_write_plaintext_format_to_stream_verbose\t] This is a debug output\n"); + cester_assert_stdout_stream_content_contain(".c:19 --- [cester_test_logax_write_plaintext_format_to_stream_verbose\t] This is an info output\n"); + cester_assert_stdout_stream_content_contain(".c:20 --- [cester_test_logax_write_plaintext_format_to_stream_verbose\t] This is a warning output\n"); + cester_assert_stdout_stream_content_contain(".c:21 --- [cester_test_logax_write_plaintext_format_to_stream_verbose\t] This is an error output\n"); + cester_assert_stdout_stream_content_contain(".c:22 --- [cester_test_logax_write_plaintext_format_to_stream_verbose\t] This is a fatal output\n"); + + CESTER_RELEASE_STDOUT(); +}) + +CESTER_TEST(logax_write_plaintext_format_to_stream_minimal, test_inst, { + CESTER_CAPTURE_STDOUT(); + + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_MINIMAL | LOGAX_LEVEL_TRACE, "%s", "This is a trace output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_MINIMAL | LOGAX_LEVEL_DEBUG, "%s", "This is a debug output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_MINIMAL | LOGAX_LEVEL_INFO, "%s", "This is an info output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_MINIMAL | LOGAX_LEVEL_WARN, "%s", "This is a warning output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_MINIMAL | LOGAX_LEVEL_ERROR, "%s", "This is an error output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_MINIMAL | LOGAX_LEVEL_FATAL, "%s", "This is a fatal output"); + + cester_assert_stdout_stream_content_contain("\x1B[36mTRACE\x1B[0m test_write_plaintext_format_to_stream.c:44 This is a trace output\n"); + cester_assert_stdout_stream_content_contain("\x1B[32mDEBUG\x1B[0m test_write_plaintext_format_to_stream.c:45 This is a debug output\n"); + cester_assert_stdout_stream_content_contain("\x1B[35mINFO\x1B[0m test_write_plaintext_format_to_stream.c:46 This is an info output\n"); + cester_assert_stdout_stream_content_contain("\x1B[33mWARN\x1B[0m test_write_plaintext_format_to_stream.c:47 This is a warning output\n"); + cester_assert_stdout_stream_content_contain("\x1B[31mERROR\x1B[0m test_write_plaintext_format_to_stream.c:48 This is an error output\n"); + cester_assert_stdout_stream_content_contain("\x1B[31mFATAL\x1B[0m test_write_plaintext_format_to_stream.c:49 This is a fatal output\n"); + + CESTER_RELEASE_STDOUT(); +}) + +CESTER_TEST(logax_write_plaintext_format_to_stream_verbose_no_color, test_inst, { + CESTER_CAPTURE_STDOUT(); + + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_VERBOSE_NO_COLOR | LOGAX_LEVEL_TRACE, "%s", "This is a trace output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_VERBOSE_NO_COLOR | LOGAX_LEVEL_DEBUG, "%s", "This is a debug output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_VERBOSE_NO_COLOR | LOGAX_LEVEL_INFO, "%s", "This is an info output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_VERBOSE_NO_COLOR | LOGAX_LEVEL_WARN, "%s", "This is a warning output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_VERBOSE_NO_COLOR | LOGAX_LEVEL_ERROR, "%s", "This is an error output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_VERBOSE_NO_COLOR | LOGAX_LEVEL_FATAL, "%s", "This is a fatal output"); + + + cester_assert_stdout_stream_content_contain("TRACE"); + cester_assert_stdout_stream_content_contain("DEBUG"); + cester_assert_stdout_stream_content_contain("INFO"); + cester_assert_stdout_stream_content_contain("WARN"); + cester_assert_stdout_stream_content_contain("ERROR"); + cester_assert_stdout_stream_content_contain("FATAL"); + cester_assert_stdout_stream_content_contain(".c:64 --- [cester_test_logax_write_plaintext_format_to_stream_verbose_no_color\t] This is a trace output\n"); + cester_assert_stdout_stream_content_contain(".c:65 --- [cester_test_logax_write_plaintext_format_to_stream_verbose_no_color\t] This is a debug output\n"); + cester_assert_stdout_stream_content_contain(".c:66 --- [cester_test_logax_write_plaintext_format_to_stream_verbose_no_color\t] This is an info output\n"); + cester_assert_stdout_stream_content_contain(".c:67 --- [cester_test_logax_write_plaintext_format_to_stream_verbose_no_color\t] This is a warning output\n"); + cester_assert_stdout_stream_content_contain(".c:68 --- [cester_test_logax_write_plaintext_format_to_stream_verbose_no_color\t] This is an error output\n"); + cester_assert_stdout_stream_content_contain(".c:69 --- [cester_test_logax_write_plaintext_format_to_stream_verbose_no_color\t] This is a fatal output\n"); + + CESTER_RELEASE_STDOUT(); +}) + +CESTER_TEST(logax_write_plaintext_format_to_stream_minimal_no_color, test_inst, { + CESTER_CAPTURE_STDOUT(); + + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_MINIMAL_NO_COLOR | LOGAX_LEVEL_TRACE, "%s", "This is a trace output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_MINIMAL_NO_COLOR | LOGAX_LEVEL_DEBUG, "%s", "This is a debug output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_MINIMAL_NO_COLOR | LOGAX_LEVEL_INFO, "%s", "This is an info output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_MINIMAL_NO_COLOR | LOGAX_LEVEL_WARN, "%s", "This is a warning output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_MINIMAL_NO_COLOR | LOGAX_LEVEL_ERROR, "%s", "This is an error output"); + logax_write_plaintext_format_to_stream(stdout, LOGAX_OPTIONS_MINIMAL_NO_COLOR | LOGAX_LEVEL_FATAL, "%s", "This is a fatal output"); + + cester_assert_stdout_stream_content_contain("TRACE test_write_plaintext_format_to_stream.c:91 This is a trace output\n"); + cester_assert_stdout_stream_content_contain("DEBUG test_write_plaintext_format_to_stream.c:92 This is a debug output\n"); + cester_assert_stdout_stream_content_contain("INFO test_write_plaintext_format_to_stream.c:93 This is an info output\n"); + cester_assert_stdout_stream_content_contain("WARN test_write_plaintext_format_to_stream.c:94 This is a warning output\n"); + cester_assert_stdout_stream_content_contain("ERROR test_write_plaintext_format_to_stream.c:95 This is an error output\n"); + cester_assert_stdout_stream_content_contain("FATAL test_write_plaintext_format_to_stream.c:96 This is a fatal output\n"); + + CESTER_RELEASE_STDOUT(); +}) + +CESTER_OPTIONS( + CESTER_VERBOSE_LEVEL(3); +) +