AmendHub

Download:

ftech

/

Logger

/

amendments

/

3

Updated tests to show some ASCII art.


Francois Techene made amendment 3 27 days ago
--- logger-test.c Tue Apr 8 09:47:06 2025 +++ logger-test.c Tue Apr 8 12:16:18 2025 @@ -23,89 +23,121 @@ #include "logger.h" -int -main(void) -{ +void +draw_header(void) +{ + logger.log(" \n\n"); + logger.log(" ____________________ "); + logger.log(" | __________________ | "); + logger.log(" | | | | "); + logger.log(" | | | | "); + logger.log(" | | | | | | | "); + logger.log(" | | _| | | "); + logger.log(" | | | | "); + logger.log(" | | -___- | | "); + logger.log(" | |_________________| | "); + logger.log(" | | "); + logger.log(" | | "); + logger.log(" | == ======= | "); + logger.log(" | | "); + logger.log(" |_____________________| "); + logger.log(" |___________________| "); + logger.log(" _ "); + logger.log(" / / ___ __ _ __ _ ___ _ __ "); + logger.log(" / / / _ \\ / _` |/ _` |/ _ \\ '__|"); + logger.log("/ /__| (_) | (_| | (_| | __/ | "); + logger.log("\\____/\\___/ \\__, |\\__, |\\___|_| "); + logger.log(" |___/ |___/ "); + logger.log("\n"); + +} + +void +test_log_levels(void) +{ + logger.log_level = NONE_LEVEL; - printf("+-----------------------------------+\n"); - printf("| Logger Test |\n"); - printf("+-----------------------------------+\n"); - - // You can use a file in a shared folder on the network - // and use "tail -f" on the remote machine the see the logs - // Comment the next init_log if you want to use it. - // - init_logger(DEBUG_LEVEL, FILE_OUT, "Shared:Mac Dev:Logger:test.log"); - - - // This path is relative to the project's folder - // - init_logger(DEBUG_LEVEL, FILE_OUT, "test.log"); - - - printf("-- Logging to file: %s\n", logger.file_path); - - logger.debug("This is a debug message to %s", logger.file_path); - logger.info("This is an info message to %s ", logger.file_path); - logger.warn("This is a warning to %s", logger.file_path); - logger.error("This is an error to %s", logger.file_path); - - - init_logger(DEBUG_LEVEL, CONSOLE_OUT, NULL); - - printf("-- Logging to the console:\n"); - logger.debug("This is a debug message with number %d ", 1); - logger.info("This is an info message with number %d ", 2); - logger.warn("This is a warning with number %d ", 3); - logger.error("This is an error with number %d ", 4); - - - init_logger(NONE_LEVEL, CONSOLE_OUT, NULL); - - printf("\n-- NONE_LEVEL: Must not show any log: \n"); + logger.log(""); + logger.log("#### Testing NONE_LEVEL: Must not show any log:"); logger.debug("This debug log should not be visible"); logger.info("This info log should not be visible"); logger.warn("This warning log should not be visible"); logger.error("This error log should not be visible"); - init_logger(ERROR_LEVEL, CONSOLE_OUT, NULL); + logger.log_level = ERROR_LEVEL; - printf("-- ERROR_LEVEL: Must show only errors: \n"); + logger.log(""); + logger.log("#### Testing ERROR_LEVEL:"); logger.debug("This debug log should not be visible !!!"); logger.info("This info log should not be visible !!!"); logger.warn("This warning log should not be visible !!!"); logger.error("This error log should be visible"); - init_logger(WARNING_LEVEL, CONSOLE_OUT, NULL); + logger.log_level = WARNING_LEVEL; - printf("\n-- WARNING_LEVEL: Must show warnings and errors: \n"); + logger.log(""); + logger.log("#### Testing WARNING_LEVEL:"); logger.debug("This debug log should not be visible !!!"); logger.info("This info log should not be visible !!!"); logger.warn("This warning log should be visible"); logger.error("This error log should be visible"); - init_logger(INFO_LEVEL, CONSOLE_OUT, NULL); + logger.log_level = INFO_LEVEL; - printf("\n-- INFO_LEVEL: Must show info, warnings and errors: \n"); + logger.log(""); + logger.log("#### Testing INFO_LEVEL:"); logger.debug("This debug log should not be visible !!!"); logger.info("This info log should be visible"); logger.warn("This warning log should be visible"); logger.error("This error log should be visible"); + logger.log_level = DEBUG_LEVEL; + logger.log(""); + logger.log("#### Testing DEBUG_LEVEL:"); + logger.debug("This is a debug message with number %d ", 1); + logger.info("This is an info message with number %d ", 2); + logger.warn("This is a warning with number %d ", 3); + logger.error("This is an error with number %d ", 4); +} + +int +main(void) +{ + init_logger(DEBUG_LEVEL, CONSOLE_OUT, NULL); + draw_header(); + + init_logger(DEBUG_LEVEL, NONE_OUT, NULL); - printf("\n-- Logging to none output: \n"); logger.debug("This debug log should not be visible !!!"); logger.info("This info log should not be visible !!!"); logger.warn("This warning log should not be visible !!!"); logger.error("This error log should not be visible !!!"); - printf("Done!"); - return 1; + // You can use a file in a shared folder on the network + // and use "tail -f" on the remote machine the see the logs + // Comment the next init_log if you want to use this one. + // + init_logger(DEBUG_LEVEL, FILE_OUT, "Shared:Mac Dev:Logger:test.log"); + + // This path is relative to the project's folder + // + init_logger(DEBUG_LEVEL, FILE_OUT, "test.log"); + + + printf("Logging to file: %s ...\n", logger.file_path); + + draw_header(); + test_log_levels(); + + + printf("Done! Check the logs in the log file."); + + return 1; } --- test.log Tue Apr 8 09:47:18 2025 +++ test.log Tue Apr 8 12:16:37 2025 @@ -1,4 +1,43 @@ -DEBUG: This is a debug message to test.log -INFO: This is an info message to test.log -WARNING: This is a warning to test.log -ERROR: This is an error to test.log + + ____________________ + | __________________ | + | | | | + | | | | + | | | | | | | + | | _| | | + | | | | + | | -___- | | + | |_________________| | + | | + | | + | == ======= | + | | + |_____________________| + |___________________| + _ + / / ___ __ _ __ _ ___ _ __ + / / / _ \ / _` |/ _` |/ _ \ '__| +/ /__| (_) | (_| | (_| | __/ | +\____/\___/ \__, |\__, |\___|_| + |___/ |___/ + + +#### Testing NONE_LEVEL: Must not show any log: + +#### Testing ERROR_LEVEL: +ERROR: This error log should be visible + +#### Testing WARNING_LEVEL: +WARNING: This warning log should be visible +ERROR: This error log should be visible + +#### Testing INFO_LEVEL: +INFO: This info log should be visible +WARNING: This warning log should be visible +ERROR: This error log should be visible + +#### Testing DEBUG_LEVEL: +DEBUG: This is a debug message with number 1 +INFO: This is an info message with number 2 +WARNING: This is a warning with number 3 +ERROR: This is an error with number 4