Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use console logger #61

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ __pycache__
bld
.virtual_documents/
Untitled*.ipynb
*.log
14 changes: 14 additions & 0 deletions share/jupyter/kernels/xr/resources/log.R
Original file line number Diff line number Diff line change
@@ -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')
14 changes: 13 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ std::string extract_filename(int argc, char* argv[])
return res;
}

std::unique_ptr<xeus::xlogger> 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))
Expand Down Expand Up @@ -104,6 +113,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, make_file_logger(xeus::xlogger::full));

std::string connection_filename = extract_filename(argc, argv);

if (!connection_filename.empty())
Expand All @@ -114,7 +125,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"
Expand Down
9 changes: 9 additions & 0 deletions src/routines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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}
};
Expand Down
Loading