1
+ // Copyright (C) 2024 Miguel Ángel González Santamarta
2
+ //
3
+ // This program is free software: you can redistribute it and/or modify
4
+ // it under the terms of the GNU General Public License as published by
5
+ // the Free Software Foundation, either version 3 of the License, or
6
+ // (at your option) any later version.
7
+ //
8
+ // This program is distributed in the hope that it will be useful,
9
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ // GNU General Public License for more details.
12
+ //
13
+ // You should have received a copy of the GNU General Public License
14
+ // along with this program. If not, see <https://www.gnu.org/licenses/>.
15
+
16
+ #include " whisper_ros/logs.hpp"
17
+
18
+ namespace whisper_ros {
19
+
20
+ /* *
21
+ * @brief Default error logging function.
22
+ *
23
+ * This function logs an error message to stderr with the format:
24
+ * [ERROR] [file:function:line] message.
25
+ *
26
+ * @param file The name of the source file where the log function is called.
27
+ * @param function The name of the function where the log function is called.
28
+ * @param line The line number in the source file where the log function is
29
+ * called.
30
+ * @param text The format string for the log message.
31
+ * @param ... Additional arguments for the format string.
32
+ */
33
+ void default_log_error (const char *file, const char *function, int line,
34
+ const char *text, ...) {
35
+ va_list args;
36
+ va_start (args, text);
37
+ fprintf (stderr, " [ERROR] [%s:%s:%d] " , file, function, line);
38
+ vfprintf (stderr, text, args);
39
+ fprintf (stderr, " \n " );
40
+ va_end (args);
41
+ }
42
+
43
+ /* *
44
+ * @brief Default warning logging function.
45
+ *
46
+ * This function logs a warning message to stderr with the format:
47
+ * [WARN] [file:function:line] message.
48
+ *
49
+ * @param file The name of the source file where the log function is called.
50
+ * @param function The name of the function where the log function is called.
51
+ * @param line The line number in the source file where the log function is
52
+ * called.
53
+ * @param text The format string for the log message.
54
+ * @param ... Additional arguments for the format string.
55
+ */
56
+ void default_log_warn (const char *file, const char *function, int line,
57
+ const char *text, ...) {
58
+ va_list args;
59
+ va_start (args, text);
60
+ fprintf (stderr, " [WARN] [%s:%s:%d] " , file, function, line);
61
+ vfprintf (stderr, text, args);
62
+ fprintf (stderr, " \n " );
63
+ va_end (args);
64
+ }
65
+
66
+ /* *
67
+ * @brief Default info logging function.
68
+ *
69
+ * This function logs an informational message to stderr with the format:
70
+ * [INFO] [file:function:line] message.
71
+ *
72
+ * @param file The name of the source file where the log function is called.
73
+ * @param function The name of the function where the log function is called.
74
+ * @param line The line number in the source file where the log function is
75
+ * called.
76
+ * @param text The format string for the log message.
77
+ * @param ... Additional arguments for the format string.
78
+ */
79
+ void default_log_info (const char *file, const char *function, int line,
80
+ const char *text, ...) {
81
+ va_list args;
82
+ va_start (args, text);
83
+ fprintf (stderr, " [INFO] [%s:%s:%d] " , file, function, line);
84
+ vfprintf (stderr, text, args);
85
+ fprintf (stderr, " \n " );
86
+ va_end (args);
87
+ }
88
+
89
+ /* *
90
+ * @brief Default debug logging function.
91
+ *
92
+ * This function logs a debug message to stderr with the format:
93
+ * [DEBUG] [file:function:line] message.
94
+ *
95
+ * @param file The name of the source file where the log function is called.
96
+ * @param function The name of the function where the log function is called.
97
+ * @param line The line number in the source file where the log function is
98
+ * called.
99
+ * @param text The format string for the log message.
100
+ * @param ... Additional arguments for the format string.
101
+ */
102
+ void default_log_debug (const char *file, const char *function, int line,
103
+ const char *text, ...) {
104
+ va_list args;
105
+ va_start (args, text);
106
+ fprintf (stderr, " [DEBUG] [%s:%s:%d] " , file, function, line);
107
+ vfprintf (stderr, text, args);
108
+ fprintf (stderr, " \n " );
109
+ va_end (args);
110
+ }
111
+
112
+ // Initialize the function pointers with default log functions
113
+ LogFunction log_error = default_log_error;
114
+ LogFunction log_warn = default_log_warn;
115
+ LogFunction log_info = default_log_info;
116
+ LogFunction log_debug = default_log_debug;
117
+
118
+ } // namespace whisper_ros
0 commit comments