Skip to content

Commit b24b30c

Browse files
feat: add option to set debug log level (#1107)
* feat: add logger output level * remove test function * add separate init log level * refactor: rename of internal log macros * update CHANGELOG.md * applied feedback changing log macros * missed one F * remove overdesigned init log level * changelog update
1 parent 19ba6d5 commit b24b30c

21 files changed

+124
-100
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
**Features**:
6+
7+
- Add option to set debug log level. ([#1107](https://github.com/getsentry/sentry-native/pull/1107))
8+
39
## 0.7.17
410

511
**Features**:

include/sentry.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,8 @@ SENTRY_API const char *sentry_options_get_user_agent(
10691069
const sentry_options_t *opts);
10701070

10711071
/**
1072-
* Enables or disables debug printing mode.
1072+
* Enables or disables debug printing mode. To change the log level from the
1073+
* default DEBUG level, use `sentry_options_set_logger_level`.
10731074
*/
10741075
SENTRY_API void sentry_options_set_debug(sentry_options_t *opts, int debug);
10751076

@@ -1078,6 +1079,12 @@ SENTRY_API void sentry_options_set_debug(sentry_options_t *opts, int debug);
10781079
*/
10791080
SENTRY_API int sentry_options_get_debug(const sentry_options_t *opts);
10801081

1082+
/**
1083+
* Sets the level of the logger. Has no effect if `debug` is not set to true.
1084+
*/
1085+
SENTRY_API void sentry_options_set_logger_level(
1086+
sentry_options_t *opts, sentry_level_t level);
1087+
10811088
/**
10821089
* Sets the number of breadcrumbs being tracked and attached to events.
10831090
*

src/backends/sentry_backend_breakpad.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ breakpad_backend_callback(const google_breakpad::MinidumpDescriptor &descriptor,
6363
void *UNUSED(context), bool succeeded)
6464
#endif
6565
{
66-
SENTRY_DEBUG("entering breakpad minidump callback");
66+
SENTRY_INFO("entering breakpad minidump callback");
6767

6868
// this is a bit strange, according to docs, `succeeded` should be true when
6969
// a minidump file was successfully generated. however, when running our
@@ -125,7 +125,7 @@ breakpad_backend_callback(const google_breakpad::MinidumpDescriptor &descriptor,
125125
uctx = &uctx_data;
126126
#endif
127127

128-
SENTRY_TRACE("invoking `on_crash` hook");
128+
SENTRY_DEBUG("invoking `on_crash` hook");
129129
sentry_value_t result
130130
= options->on_crash_func(uctx, event, options->on_crash_data);
131131
should_handle = !sentry_value_is_null(result);
@@ -167,7 +167,7 @@ breakpad_backend_callback(const google_breakpad::MinidumpDescriptor &descriptor,
167167
sentry__path_remove(dump_path);
168168
sentry__path_free(dump_path);
169169
} else {
170-
SENTRY_TRACE("event was discarded by the `on_crash` hook");
170+
SENTRY_DEBUG("event was discarded by the `on_crash` hook");
171171
sentry_value_decref(event);
172172
}
173173

@@ -176,7 +176,7 @@ breakpad_backend_callback(const google_breakpad::MinidumpDescriptor &descriptor,
176176
sentry__transport_dump_queue(options->transport, options->run);
177177
// and restore the old transport
178178
}
179-
SENTRY_DEBUG("crash has been captured");
179+
SENTRY_INFO("crash has been captured");
180180

181181
#ifndef SENTRY_PLATFORM_WINDOWS
182182
sentry__leave_signal_handler();

src/backends/sentry_backend_crashpad.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ crashpad_register_wer_module(
139139
}
140140

141141
if (wer_path && sentry__path_is_file(wer_path)) {
142-
SENTRY_TRACEF("registering crashpad WER handler "
142+
SENTRY_DEBUGF("registering crashpad WER handler "
143143
"\"%" SENTRY_PATH_PRI "\"",
144144
wer_path->path);
145145

@@ -186,7 +186,7 @@ crashpad_backend_flush_scope_to_event(const sentry_path_t *event_path,
186186
sentry_free(mpack);
187187

188188
if (rv != 0) {
189-
SENTRY_DEBUG("flushing scope to msgpack failed");
189+
SENTRY_WARN("flushing scope to msgpack failed");
190190
}
191191
}
192192

@@ -257,7 +257,7 @@ sentry__crashpad_handler(int signum, siginfo_t *info, ucontext_t *user_context)
257257
{
258258
sentry__page_allocator_enable();
259259
# endif
260-
SENTRY_DEBUG("flushing session and queue before crashpad handler");
260+
SENTRY_INFO("flushing session and queue before crashpad handler");
261261

262262
bool should_dump = true;
263263

@@ -276,11 +276,11 @@ sentry__crashpad_handler(int signum, siginfo_t *info, ucontext_t *user_context)
276276
uctx.user_context = user_context;
277277
# endif
278278

279-
SENTRY_TRACE("invoking `on_crash` hook");
279+
SENTRY_DEBUG("invoking `on_crash` hook");
280280
crash_event = options->on_crash_func(
281281
&uctx, crash_event, options->on_crash_data);
282282
} else if (options->before_send_func) {
283-
SENTRY_TRACE("invoking `before_send` hook");
283+
SENTRY_DEBUG("invoking `before_send` hook");
284284
crash_event = options->before_send_func(
285285
crash_event, nullptr, options->before_send_data);
286286
}
@@ -305,12 +305,12 @@ sentry__crashpad_handler(int signum, siginfo_t *info, ucontext_t *user_context)
305305
sentry_transport_free(disk_transport);
306306
}
307307
} else {
308-
SENTRY_TRACE("event was discarded");
308+
SENTRY_DEBUG("event was discarded");
309309
}
310310
sentry__transport_dump_queue(options->transport, options->run);
311311
}
312312

313-
SENTRY_DEBUG("handing control over to crashpad");
313+
SENTRY_INFO("handing control over to crashpad");
314314
// If we __don't__ want a minidump produced by crashpad we need to either
315315
// exit or longjmp at this point. The crashpad client handler which calls
316316
// back here (SetFirstChanceExceptionHandler) does the same if the
@@ -392,7 +392,7 @@ crashpad_backend_startup(
392392
return 1;
393393
}
394394

395-
SENTRY_TRACEF("starting crashpad backend with handler "
395+
SENTRY_DEBUGF("starting crashpad backend with handler "
396396
"\"%" SENTRY_PATH_PRI "\"",
397397
absolute_handler_path->path);
398398
sentry_path_t *current_run_folder = options->run->run_path;
@@ -437,7 +437,7 @@ crashpad_backend_startup(
437437
char *minidump_url
438438
= sentry__dsn_get_minidump_url(options->dsn, options->user_agent);
439439
if (minidump_url) {
440-
SENTRY_TRACEF("using minidump URL \"%s\"", minidump_url);
440+
SENTRY_DEBUGF("using minidump URL \"%s\"", minidump_url);
441441
}
442442
bool success = data->client->StartHandler(handler, database, database,
443443
minidump_url ? minidump_url : "", options->proxy ? options->proxy : "",
@@ -453,7 +453,7 @@ crashpad_backend_startup(
453453
sentry__path_free(absolute_handler_path);
454454

455455
if (success) {
456-
SENTRY_DEBUG("started crashpad client handler");
456+
SENTRY_INFO("started crashpad client handler");
457457
} else {
458458
SENTRY_WARN("failed to start crashpad client handler");
459459
// not calling `shutdown`
@@ -545,7 +545,7 @@ crashpad_backend_add_breadcrumb(sentry_backend_t *backend,
545545
sentry_free(mpack);
546546

547547
if (rv != 0) {
548-
SENTRY_DEBUG("flushing breadcrumb to msgpack failed");
548+
SENTRY_WARN("flushing breadcrumb to msgpack failed");
549549
}
550550
}
551551

src/backends/sentry_backend_inproc.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ startup_inproc_backend(
8989
stack_t old_sig_stack;
9090
int ret = sigaltstack(NULL, &old_sig_stack);
9191
if (ret == 0 && old_sig_stack.ss_flags == SS_DISABLE) {
92-
SENTRY_TRACEF("installing signal stack (size: %d)", SIGNAL_STACK_SIZE);
92+
SENTRY_DEBUGF("installing signal stack (size: %d)", SIGNAL_STACK_SIZE);
9393
g_signal_stack.ss_sp = sentry_malloc(SIGNAL_STACK_SIZE);
9494
if (!g_signal_stack.ss_sp) {
9595
return 1;
@@ -98,7 +98,7 @@ startup_inproc_backend(
9898
g_signal_stack.ss_flags = 0;
9999
sigaltstack(&g_signal_stack, 0);
100100
} else if (ret == 0) {
101-
SENTRY_TRACEF("using existing signal stack (size: %d, flags: %d)",
101+
SENTRY_DEBUGF("using existing signal stack (size: %d, flags: %d)",
102102
old_sig_stack.ss_size, old_sig_stack.ss_flags);
103103
} else if (ret == -1) {
104104
SENTRY_WARNF("Failed to query signal stack size: %s", strerror(errno));
@@ -485,15 +485,15 @@ make_signal_event(
485485
void *backtrace[MAX_FRAMES];
486486
size_t frame_count
487487
= sentry_unwind_stack_from_ucontext(uctx, &backtrace[0], MAX_FRAMES);
488-
SENTRY_TRACEF(
488+
SENTRY_DEBUGF(
489489
"captured backtrace from ucontext with %lu frames", frame_count);
490490
// if unwinding from a ucontext didn't yield any results, try again with a
491491
// direct unwind. this is most likely the case when using `libbacktrace`,
492492
// since that does not allow to unwind from a ucontext at all.
493493
if (!frame_count) {
494494
frame_count = sentry_unwind_stack(NULL, &backtrace[0], MAX_FRAMES);
495495
}
496-
SENTRY_TRACEF("captured backtrace with %lu frames", frame_count);
496+
SENTRY_DEBUGF("captured backtrace with %lu frames", frame_count);
497497

498498
sentry_value_t stacktrace
499499
= sentry_value_new_stacktrace(&backtrace[0], frame_count);
@@ -518,7 +518,7 @@ make_signal_event(
518518
static void
519519
handle_ucontext(const sentry_ucontext_t *uctx)
520520
{
521-
SENTRY_DEBUG("entering signal handler");
521+
SENTRY_INFO("entering signal handler");
522522

523523
const struct signal_slot *sig_slot = NULL;
524524
for (int i = 0; i < SIGNAL_COUNT; ++i) {
@@ -550,7 +550,7 @@ handle_ucontext(const sentry_ucontext_t *uctx)
550550
// we process the signal.
551551
if (sentry_options_get_handler_strategy(options)
552552
== SENTRY_HANDLER_STRATEGY_CHAIN_AT_START) {
553-
SENTRY_TRACE("defer to runtime signal handler at start");
553+
SENTRY_DEBUG("defer to runtime signal handler at start");
554554
// there is a good chance that we won't return from the previous
555555
// handler and that would mean we couldn't enter this handler with
556556
// the next signal coming in if we didn't "leave" here.
@@ -563,7 +563,7 @@ handle_ucontext(const sentry_ucontext_t *uctx)
563563

564564
// let's re-enter because it means this was an actual native crash
565565
sentry__enter_signal_handler();
566-
SENTRY_TRACE(
566+
SENTRY_DEBUG(
567567
"return from runtime signal handler, we handle the signal");
568568
}
569569
#endif
@@ -578,7 +578,7 @@ handle_ucontext(const sentry_ucontext_t *uctx)
578578
sentry__write_crash_marker(options);
579579

580580
if (options->on_crash_func) {
581-
SENTRY_TRACE("invoking `on_crash` hook");
581+
SENTRY_DEBUG("invoking `on_crash` hook");
582582
event = options->on_crash_func(uctx, event, options->on_crash_data);
583583
should_handle = !sentry_value_is_null(event);
584584
}
@@ -600,15 +600,15 @@ handle_ucontext(const sentry_ucontext_t *uctx)
600600
sentry__transport_dump_queue(disk_transport, options->run);
601601
sentry_transport_free(disk_transport);
602602
} else {
603-
SENTRY_TRACE("event was discarded by the `on_crash` hook");
603+
SENTRY_DEBUG("event was discarded by the `on_crash` hook");
604604
sentry_value_decref(event);
605605
}
606606

607607
// after capturing the crash event, dump all the envelopes to disk
608608
sentry__transport_dump_queue(options->transport, options->run);
609609
}
610610

611-
SENTRY_DEBUG("crash has been captured");
611+
SENTRY_INFO("crash has been captured");
612612

613613
#ifdef SENTRY_PLATFORM_UNIX
614614
// reset signal handlers and invoke the original ones. This will then tear

src/modulefinder/sentry_modulefinder_linux.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -725,9 +725,9 @@ sentry_get_modules_list(void)
725725
sentry__mutex_lock(&g_mutex);
726726
if (!g_initialized) {
727727
g_modules = sentry_value_new_list();
728-
SENTRY_TRACE("trying to read modules from /proc/self/maps");
728+
SENTRY_DEBUG("trying to read modules from /proc/self/maps");
729729
load_modules(g_modules);
730-
SENTRY_TRACEF("read %zu modules from /proc/self/maps",
730+
SENTRY_DEBUGF("read %zu modules from /proc/self/maps",
731731
sentry_value_get_length(g_modules));
732732
sentry_value_freeze(g_modules);
733733
g_initialized = true;

src/path/sentry_path_unix.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ write_buffer_with_flags(
474474
int fd = open(
475475
path->path, flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
476476
if (fd < 0) {
477-
SENTRY_TRACEF(
477+
SENTRY_WARNF(
478478
"failed to open file \"%s\" for writing (errno %d, flags %x)",
479479
path->path, errno, flags);
480480
return 1;

src/path/sentry_path_windows.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ sentry__path_current_exe(void)
110110
sentry_path_t *path = path_with_len(MAX_PATH);
111111
size_t len = GetModuleFileNameW(NULL, path->path, MAX_PATH);
112112
if (!len) {
113-
SENTRY_DEBUG("unable to get current exe path");
113+
SENTRY_WARN("unable to get current exe path");
114114
sentry__path_free(path);
115115
return NULL;
116116
}

0 commit comments

Comments
 (0)