6 #include <SWI-Prolog.h>
7 #include "knowrob/Logger.h"
8 #include "knowrob/integration/prolog/PrologTerm.h"
9 #include "knowrob/integration/prolog/logging.h"
13 static inline foreign_t pl_log_message_internal(term_t level_term, term_t msg_term,
const char *file,
int line) {
14 static atom_t ATOM_error = PL_new_atom(
"error");
15 static atom_t ATOM_warning = PL_new_atom(
"warning");
16 static atom_t ATOM_informational = PL_new_atom(
"informational");
17 static atom_t ATOM_debug = PL_new_atom(
"debug");
21 if (!PL_get_atom(level_term, &level_atom)) {
30 if (msg->isAtomic()) {
31 ss << std::static_pointer_cast<Atomic>(msg)->stringForm();
34 if (msg_str.front() ==
'\'') {
36 msg_str.erase(msg_str.size() - 1);
41 if (level_atom == ATOM_debug) {
43 }
else if (level_atom == ATOM_informational) {
45 }
else if (level_atom == ATOM_warning) {
47 }
else if (level_atom == ATOM_error) {
50 KB_WARN(
"unknown logging level '{}'.", PL_atom_chars(level_atom));
58 return pl_log_message_internal(level_term, msg_term, __FILE__, __LINE__);
61 foreign_t
log_message4(term_t level_term, term_t msg_term, term_t file_term, term_t line_term) {
64 if (PL_get_atom(file_term, &file_atom) &&
65 PL_get_integer(line_term, &line_number)) {
66 const char *file_string = PL_atom_chars(file_atom);
67 return pl_log_message_internal(level_term, msg_term, file_string, line_number);
#define KB_DEBUG1(file, line,...)
#define KB_WARN1(file, line,...)
#define KB_INFO1(file, line,...)
#define KB_ERROR1(file, line,...)
TermPtr toKnowRobTerm() const
foreign_t log_message4(term_t level_term, term_t msg_term, term_t file_term, term_t line_term)
foreign_t log_message2(term_t level_term, term_t msg_term)
std::shared_ptr< Term > TermPtr