AmendHub

Download

ftech

/

Logger

/

logger-test.c

 

(View History)

Francois Techene   Updated tests to show some ASCII art. Latest amendment: 3 on 2025-04-08

1 /* logger_test.c
2 *
3 * Copyright 2025 Francois Techene
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: GPL-3.0-or-later
19 */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23
24 #include "logger.h"
25
26 void
27 draw_header(void)
28 {
29 logger.log(" \n\n");
30 logger.log(" ____________________ ");
31 logger.log(" | __________________ | ");
32 logger.log(" | | | | ");
33 logger.log(" | | | | ");
34 logger.log(" | | | | | | | ");
35 logger.log(" | | _| | | ");
36 logger.log(" | | | | ");
37 logger.log(" | | -___- | | ");
38 logger.log(" | |_________________| | ");
39 logger.log(" | | ");
40 logger.log(" | | ");
41 logger.log(" | == ======= | ");
42 logger.log(" | | ");
43 logger.log(" |_____________________| ");
44 logger.log(" |___________________| ");
45 logger.log(" _ ");
46 logger.log(" / / ___ __ _ __ _ ___ _ __ ");
47 logger.log(" / / / _ \\ / _` |/ _` |/ _ \\ '__|");
48 logger.log("/ /__| (_) | (_| | (_| | __/ | ");
49 logger.log("\\____/\\___/ \\__, |\\__, |\\___|_| ");
50 logger.log(" |___/ |___/ ");
51 logger.log("\n");
52
53 }
54
55 void
56 test_log_levels(void)
57 {
58 logger.log_level = NONE_LEVEL;
59
60 logger.log("");
61 logger.log("#### Testing NONE_LEVEL: Must not show any log:");
62 logger.debug("This debug log should not be visible");
63 logger.info("This info log should not be visible");
64 logger.warn("This warning log should not be visible");
65 logger.error("This error log should not be visible");
66
67
68 logger.log_level = ERROR_LEVEL;
69
70 logger.log("");
71 logger.log("#### Testing ERROR_LEVEL:");
72 logger.debug("This debug log should not be visible !!!");
73 logger.info("This info log should not be visible !!!");
74 logger.warn("This warning log should not be visible !!!");
75 logger.error("This error log should be visible");
76
77
78 logger.log_level = WARNING_LEVEL;
79
80 logger.log("");
81 logger.log("#### Testing WARNING_LEVEL:");
82 logger.debug("This debug log should not be visible !!!");
83 logger.info("This info log should not be visible !!!");
84 logger.warn("This warning log should be visible");
85 logger.error("This error log should be visible");
86
87
88 logger.log_level = INFO_LEVEL;
89
90 logger.log("");
91 logger.log("#### Testing INFO_LEVEL:");
92 logger.debug("This debug log should not be visible !!!");
93 logger.info("This info log should be visible");
94 logger.warn("This warning log should be visible");
95 logger.error("This error log should be visible");
96
97
98 logger.log_level = DEBUG_LEVEL;
99 logger.log("");
100 logger.log("#### Testing DEBUG_LEVEL:");
101 logger.debug("This is a debug message with number %d ", 1);
102 logger.info("This is an info message with number %d ", 2);
103 logger.warn("This is a warning with number %d ", 3);
104 logger.error("This is an error with number %d ", 4);
105 }
106
107 int
108 main(void)
109 {
110 init_logger(DEBUG_LEVEL, CONSOLE_OUT, NULL);
111 draw_header();
112
113
114 init_logger(DEBUG_LEVEL, NONE_OUT, NULL);
115
116 logger.debug("This debug log should not be visible !!!");
117 logger.info("This info log should not be visible !!!");
118 logger.warn("This warning log should not be visible !!!");
119 logger.error("This error log should not be visible !!!");
120
121
122
123 // You can use a file in a shared folder on the network
124 // and use "tail -f" on the remote machine the see the logs
125 // Comment the next init_log if you want to use this one.
126 //
127 init_logger(DEBUG_LEVEL, FILE_OUT, "Shared:Mac Dev:Logger:test.log");
128
129 // This path is relative to the project's folder
130 //
131 init_logger(DEBUG_LEVEL, FILE_OUT, "test.log");
132
133
134 printf("Logging to file: %s ...\n", logger.file_path);
135
136 draw_header();
137 test_log_levels();
138
139
140 printf("Done! Check the logs in the log file.");
141
142 return 1;
143 }