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

Logger fallback to console.error if process._rawDebug is missing #592

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions source/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,21 @@ void s_threadsafe_log_create(struct aws_napi_logger_ctx *ctx, napi_env env) {
napi_value node_rawdebug = NULL;
AWS_NAPI_ENSURE(env, napi_get_named_property(env, node_process, "_rawDebug", &node_rawdebug));

napi_valuetype rawdebug_type;
AWS_NAPI_ENSURE(env, napi_typeof(env, node_rawdebug, &rawdebug_type));

/* process._rawDebug is specific to NodeJS and may not exist in
other environments like Deno, fall back to console.error */
if (rawdebug_type == napi_undefined) {
napi_value node_console = NULL;
AWS_NAPI_ENSURE(env, napi_get_named_property(env, node_global, "console", &node_console));

napi_value node_error = NULL;
AWS_NAPI_ENSURE(env, napi_get_named_property(env, node_console, "error", &node_error));

node_rawdebug = node_error;
}

napi_value resource_name = NULL;
AWS_NAPI_ENSURE(env, napi_create_string_utf8(env, "aws_logger", 10, &resource_name));

Expand Down
Loading