Skip to content

Commit

Permalink
add separate init log level
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaMoelans committed Dec 18, 2024
1 parent df8752d commit b5ff5e2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,12 @@ SENTRY_API int sentry_options_get_debug(const sentry_options_t *opts);
SENTRY_API void sentry_options_set_logger_level(
sentry_options_t *opts, sentry_level_t level);

/**
* Sets the log level for the sentry_init function
*/
SENTRY_API void sentry_options_set_init_log_level(
sentry_options_t *opts, sentry_level_t level);

/**
* Sets the number of breadcrumbs being tracked and attached to events.
*
Expand Down
7 changes: 7 additions & 0 deletions src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ sentry_init(sentry_options_t *options)
if (options->debug) {
logger = options->logger;
}
sentry_logger_t old_logger = logger; // restore this after init
if (options->log_init) {
logger = options->logger;
logger.logger_level = options->init_logger_level;
}
sentry__logger_set_global(logger);

// we need to ensure the dir exists, otherwise `path_absolute` will fail.
Expand Down Expand Up @@ -200,6 +205,8 @@ sentry_init(sentry_options_t *options)
sentry__init_cached_functions();
#endif

sentry__logger_set_global(old_logger);

sentry__mutex_unlock(&g_options_lock);
return 0;

Expand Down
14 changes: 13 additions & 1 deletion src/sentry_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,11 @@ sentry_options_get_user_agent(const sentry_options_t *opts)
void
sentry_options_set_debug(sentry_options_t *opts, int debug)
{
opts->debug = !!debug;
if (!!debug) {
sentry_options_set_logger_level(opts, SENTRY_LEVEL_DEBUG);
} else {
opts->debug = false;
}
}

int
Expand Down Expand Up @@ -401,6 +405,14 @@ void
sentry_options_set_logger_level(sentry_options_t *opts, sentry_level_t level)
{
opts->logger.logger_level = level;
opts->debug = true;
}

void
sentry_options_set_init_log_level(sentry_options_t *opts, sentry_level_t level)
{
opts->init_logger_level = level;
opts->log_init = true;
}

void
Expand Down
2 changes: 2 additions & 0 deletions src/sentry_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ typedef struct sentry_options_s {
sentry_path_t *database_path;
sentry_path_t *handler_path;
sentry_logger_t logger;
sentry_level_t init_logger_level;
bool log_init;
size_t max_breadcrumbs;
bool debug;
bool auto_session_tracking;
Expand Down

0 comments on commit b5ff5e2

Please sign in to comment.