/* logger_test.c * * Copyright 2025 Francois Techene * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * SPDX-License-Identifier: GPL-3.0-or-later */ #include #include #include "logger.h" 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; 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"); logger.log_level = ERROR_LEVEL; 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"); logger.log_level = WARNING_LEVEL; 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"); logger.log_level = INFO_LEVEL; 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); 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 !!!"); // 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; }