Skip to content
Snippets Groups Projects
Commit 39626f45 authored by Olivier Dion's avatar Olivier Dion Committed by Adrien Béraud
Browse files

agent/bindings/logger: Add Jami's logger foreign function bindings

Change-Id: Ib70fdc0739a0ab7216be851b35f55a1ecb72a9a2
parent e60e88f0
No related branches found
No related tags found
No related merge requests found
(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 ...))
...@@ -24,15 +24,21 @@ ...@@ -24,15 +24,21 @@
/* Include module's bindings here */ /* Include module's bindings here */
#include "bindings/account.h" #include "bindings/account.h"
#include "bindings/call.h" #include "bindings/call.h"
#include "bindings/logger.h"
#include "bindings/signal.h" #include "bindings/signal.h"
void void
install_scheme_primitives() install_scheme_primitives()
{ {
/* Define modules here */ /* Define modules here */
scm_c_define_module("jami account", install_account_primitives, NULL); auto load_module = [](auto name, auto init){
scm_c_define_module("jami call", install_call_primitives, NULL); scm_c_define_module(name, init, NULL);
scm_c_define_module("jami signal", install_signal_primitives, 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);
} }
/* /*
......
/*
* 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);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment