-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
400 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (C) 2024 Miguel Ángel González Santamarta | ||
|
||
// 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 <https://www.gnu.org/licenses/>. | ||
|
||
#ifndef YASMIN_LOGS_HPP | ||
#define YASMIN_LOGS_HPP | ||
|
||
#include <cstdarg> | ||
#include <cstdio> | ||
|
||
namespace yasmin { | ||
|
||
// define raw function pointer type for logging | ||
typedef void (*LogFunction)(const char *, ...); | ||
|
||
// declare function pointers as extern | ||
extern LogFunction log_error; | ||
extern LogFunction log_warn; | ||
extern LogFunction log_info; | ||
extern LogFunction log_debug; | ||
|
||
// macros to use the function pointers for logging | ||
#define YASMIN_LOG_ERROR(text, ...) yasmin::log_error(text, ##__VA_ARGS__) | ||
#define YASMIN_LOG_WARN(text, ...) yasmin::log_warn(text, ##__VA_ARGS__) | ||
#define YASMIN_LOG_INFO(text, ...) yasmin::log_info(text, ##__VA_ARGS__) | ||
#define YASMIN_LOG_DEBUG(text, ...) yasmin::log_debug(text, ##__VA_ARGS__) | ||
|
||
// function to set custom log functions | ||
void set_loggers(LogFunction error, LogFunction warn, LogFunction info, | ||
LogFunction debug); | ||
|
||
void set_default_loggers(); | ||
} // namespace yasmin | ||
|
||
#endif // YASMIN_LOGS_HPP |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright (C) 2024 Miguel Ángel González Santamarta | ||
|
||
// 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 <https://www.gnu.org/licenses/>. | ||
|
||
#include "yasmin/logs.hpp" | ||
|
||
namespace yasmin { | ||
|
||
// define the default log functions | ||
void default_log_error(const char *text, ...) { | ||
va_list args; | ||
va_start(args, text); | ||
fprintf(stderr, "[ERROR] "); | ||
vfprintf(stderr, text, args); | ||
fprintf(stderr, "\n"); | ||
va_end(args); | ||
} | ||
|
||
void default_log_warn(const char *text, ...) { | ||
va_list args; | ||
va_start(args, text); | ||
fprintf(stderr, "[WARN] "); | ||
vfprintf(stderr, text, args); | ||
fprintf(stderr, "\n"); | ||
va_end(args); | ||
} | ||
|
||
void default_log_info(const char *text, ...) { | ||
va_list args; | ||
va_start(args, text); | ||
fprintf(stderr, "[INFO] "); | ||
vfprintf(stderr, text, args); | ||
fprintf(stderr, "\n"); | ||
va_end(args); | ||
} | ||
|
||
void default_log_debug(const char *text, ...) { | ||
va_list args; | ||
va_start(args, text); | ||
fprintf(stderr, "[DEBUG] "); | ||
vfprintf(stderr, text, args); | ||
fprintf(stderr, "\n"); | ||
va_end(args); | ||
} | ||
|
||
// define the function pointers to be initialized with default log functions | ||
LogFunction log_error = default_log_error; | ||
LogFunction log_warn = default_log_warn; | ||
LogFunction log_info = default_log_info; | ||
LogFunction log_debug = default_log_debug; | ||
|
||
// implement the set_loggers function | ||
void set_loggers(LogFunction error, LogFunction warn, LogFunction info, | ||
LogFunction debug) { | ||
log_error = error ? error : default_log_error; | ||
log_warn = warn ? warn : default_log_warn; | ||
log_info = info ? info : default_log_info; | ||
log_debug = debug ? debug : default_log_debug; | ||
} | ||
|
||
void set_default_loggers() { | ||
set_loggers(default_log_error, default_log_warn, default_log_info, | ||
default_log_debug); | ||
} | ||
|
||
} // namespace yasmin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (C) 2024 Miguel Ángel González Santamarta | ||
|
||
// 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 <https://www.gnu.org/licenses/>. | ||
|
||
#ifndef YASMIN_ROS_LOGS_HPP | ||
#define YASMIN_ROS_LOGS_HPP | ||
|
||
namespace yasmin_ros { | ||
|
||
void set_ros_loggers(); | ||
|
||
} // namespace yasmin_ros | ||
|
||
#endif // YASMIN_ROS_LOGS_HPP |
Oops, something went wrong.