diff --git a/test/agent/jami/logger.scm b/test/agent/jami/logger.scm new file mode 100644 index 0000000000000000000000000000000000000000..5cf40c06dc502bd2eaf1361c71ad1fe880aabb32 --- /dev/null +++ b/test/agent/jami/logger.scm @@ -0,0 +1,27 @@ +(define-module (jami logger) + #:use-module ((jami logger bindings) #:prefix ffi:) + #:export (debug + info + warning + error)) + +(define-syntax-rule (logging% lvl fmt args ...) + (let* ((source-location (current-source-location)) + (filename (or (assq-ref source-location 'filename) "<guile>")) + (line (or (assq-ref source-location 'line) -1))) + (ffi:log lvl + filename + (+ line 1) + (format #f fmt args ...)))) + +(define-syntax-rule (debug fmt args ...) + (logging% ffi:LOG_DEBUG fmt args ...)) + +(define-syntax-rule (info fmt args ...) + (logging% ffi:LOG_INFO fmt args ...)) + +(define-syntax-rule (warning fmt args ...) + (logging% ffi:LOG_WARNING fmt args ...)) + +(define-syntax-rule (error fmt args ...) + (logging% ffi:LOG_ERR fmt args ...)) diff --git a/test/agent/src/bindings/bindings.cpp b/test/agent/src/bindings/bindings.cpp index 7ef7f28c7cd39cfff4c5a4308e08aff9c924def8..6876234f53b040ca204dfdf8be6a1844f31bf681 100644 --- a/test/agent/src/bindings/bindings.cpp +++ b/test/agent/src/bindings/bindings.cpp @@ -24,15 +24,21 @@ /* Include module's bindings here */ #include "bindings/account.h" #include "bindings/call.h" +#include "bindings/logger.h" #include "bindings/signal.h" void install_scheme_primitives() { /* Define modules here */ - scm_c_define_module("jami account", install_account_primitives, NULL); - scm_c_define_module("jami call", install_call_primitives, NULL); - scm_c_define_module("jami signal", install_signal_primitives, NULL); + auto load_module = [](auto name, auto init){ + scm_c_define_module(name, init, NULL); + }; + + load_module("jami account", install_account_primitives); + load_module("jami call", install_call_primitives); + load_module("jami logger bindings", install_logger_primitives); + load_module("jami signal", install_signal_primitives); } /* diff --git a/test/agent/src/bindings/logger.h b/test/agent/src/bindings/logger.h new file mode 100644 index 0000000000000000000000000000000000000000..a7637a1a61a2b9f1741352f32b18af68de59a6ae --- /dev/null +++ b/test/agent/src/bindings/logger.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2021 Savoir-faire Linux Inc. + * + * Author: Olivier Dion <olivier.dion@savoirfairelinux.com> + * + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#pragma once + +/* Jami */ +#include "logger.h" + +/* Agent */ +#include "utils.h" + +static SCM log_binding(SCM log_lvl_int, SCM file_str, SCM line_int, SCM text_str) +{ + const std::string file = from_guile(file_str); + const std::string text = from_guile(text_str); + + jami::Logger::log(from_guile(log_lvl_int), + file.c_str(), + from_guile(line_int), + false, "[GUILE] %s\n", text.c_str()); + + return SCM_UNDEFINED; +} + +static void +install_logger_primitives(void *) +{ + define_primitive("log", 4, 0, 0, (void*) log_binding); + + DEFINE_INT(LOG_DEBUG); + DEFINE_INT(LOG_INFO); + DEFINE_INT(LOG_WARNING); + DEFINE_INT(LOG_ERR); +}