From f57fd80b74922b8764391970e9d0134e72bbfc06 Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Thu, 7 Dec 2023 11:25:00 +0100 Subject: [PATCH 1/4] use console logger --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index aecea93..897e378 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -103,6 +103,7 @@ int main(int argc, char* argv[]) auto interpreter = xeus_r::make_interpreter(argc, argv); auto hist = xeus::make_in_memory_history_manager(); + auto logger = xeus::make_console_logger(xeus::xlogger::full); std::string connection_filename = extract_filename(argc, argv); @@ -114,7 +115,8 @@ int main(int argc, char* argv[]) std::move(context), std::move(interpreter), xeus::make_xserver_zmq, - std::move(hist)); + std::move(hist), + std::move(logger)); std::cout << "Starting xr kernel...\n\n" From 970e201224e3e15e4ff7c34b0d6d234fcf7902f1 Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Thu, 7 Dec 2023 13:08:42 +0100 Subject: [PATCH 2/4] ignore log files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6bd2f43..96e316d 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,4 @@ __pycache__ bld .virtual_documents/ Untitled*.ipynb +*.log From a1cdddeea8a6b624566eca1c6049eea002619838 Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Thu, 7 Dec 2023 13:16:55 +0100 Subject: [PATCH 3/4] wire logging --- share/jupyter/kernels/xr/resources/log.R | 14 ++++++++++++++ src/main.cpp | 3 ++- src/routines.cpp | 9 +++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 share/jupyter/kernels/xr/resources/log.R diff --git a/share/jupyter/kernels/xr/resources/log.R b/share/jupyter/kernels/xr/resources/log.R new file mode 100644 index 0000000..25e0644 --- /dev/null +++ b/share/jupyter/kernels/xr/resources/log.R @@ -0,0 +1,14 @@ + +logger <- function(level, name) { + function(...) { + if (isTRUE(getOption('jupyter.log_level') >= level)) { + msg <- glue::glue(...) + .Call("xeusr_log", name, msg, PACKAGE = "(embedding)") + } + invisible(NULL) + } +} + +log_debug <- logger(3L, 'DEBUG') +log_info <- logger(2L, 'INFO') +log_error <- logger(1L, 'ERROR') diff --git a/src/main.cpp b/src/main.cpp index 897e378..344279c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -103,7 +103,8 @@ int main(int argc, char* argv[]) auto interpreter = xeus_r::make_interpreter(argc, argv); auto hist = xeus::make_in_memory_history_manager(); - auto logger = xeus::make_console_logger(xeus::xlogger::full); + auto logger = xeus::make_console_logger(xeus::xlogger::full, + xeus::make_file_logger(xeus::xlogger::content, "xeusr.log")); std::string connection_filename = extract_filename(argc, argv); diff --git a/src/routines.cpp b/src/routines.cpp index 22097fa..0ab3193 100644 --- a/src/routines.cpp +++ b/src/routines.cpp @@ -91,6 +91,14 @@ SEXP is_complete_request(SEXP code_) { return out; } +SEXP xeusr_log(SEXP level_, SEXP msg_) { + std::string level = CHAR(STRING_ELT(level_, 0)); + std::string msg = CHAR(STRING_ELT(msg_, 0)); + + // TODO: actually do some logging + return R_NilValue; +} + } void register_r_routines() { @@ -105,6 +113,7 @@ void register_r_routines() { {"xeusr_update_display_data" , (DL_FUNC) &routines::update_display_data , 2}, {"xeusr_clear_output" , (DL_FUNC) &routines::clear_output , 1}, {"xeusr_is_complete_request" , (DL_FUNC) &routines::is_complete_request , 1}, + {"xeusr_log" , (DL_FUNC) &routines::xeusr_log , 2}, {NULL, NULL, 0} }; From c324b35fca673d087cd2102236f2021411914f15 Mon Sep 17 00:00:00 2001 From: Romain Francois Date: Thu, 7 Dec 2023 13:29:40 +0100 Subject: [PATCH 4/4] use the JUPYTER_LOGFILE environment variable --- src/main.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 344279c..b341b18 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -75,6 +75,15 @@ std::string extract_filename(int argc, char* argv[]) return res; } +std::unique_ptr make_file_logger(xeus::xlogger::level log_level) { + auto logfile = std::getenv("JUPYTER_LOGFILE"); + if (logfile == nullptr) { + return nullptr; + } + + return xeus::make_file_logger(log_level, logfile); +} + int main(int argc, char* argv[]) { if (should_print_version(argc, argv)) @@ -103,8 +112,8 @@ int main(int argc, char* argv[]) auto interpreter = xeus_r::make_interpreter(argc, argv); auto hist = xeus::make_in_memory_history_manager(); - auto logger = xeus::make_console_logger(xeus::xlogger::full, - xeus::make_file_logger(xeus::xlogger::content, "xeusr.log")); + + auto logger = xeus::make_console_logger(xeus::xlogger::full, make_file_logger(xeus::xlogger::full)); std::string connection_filename = extract_filename(argc, argv);