Skip to content

Commit b03cd48

Browse files
fix(logs): add debug output for structured logs when debug option is enabled (#1466)
* add printf for logs when debug is true * use existing SENTRY_(LEVEL) macros * update CHANGELOG.md * add future TODO + fix null-log * make debug_print_log static
1 parent b6ed4c3 commit b03cd48

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Removed the 10-item limit per envelope for non-session data. Sessions are now limited to 100 per envelope, while other items (e.g., attachments) have no limit in amount. ([#1347](https://github.com/getsentry/sentry-native/pull/1347))
88
- Align the `breakpad` interface changes introduced with [#1083](https://github.com/getsentry/sentry-native/pull/1083) with the corresponding iOS build. ([#1465](https://github.com/getsentry/sentry-native/pull/1465))
9+
- Add structured logs to debug output when `debug` option is set. ([#1466](https://github.com/getsentry/sentry-native/pull/1466))
910

1011
## 0.12.2
1112

src/sentry_logger.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,9 @@ void sentry__logger_disable(void);
4646

4747
#define SENTRY_ERROR(message) sentry__logger_log(SENTRY_LEVEL_ERROR, message)
4848

49+
#define SENTRY_FATALF(message, ...) \
50+
sentry__logger_log(SENTRY_LEVEL_FATAL, message, __VA_ARGS__)
51+
52+
#define SENTRY_FATAL(message) sentry__logger_log(SENTRY_LEVEL_FATAL, message)
53+
4954
#endif

src/sentry_logs.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,33 @@ construct_log(sentry_level_t level, const char *message, va_list args)
752752
return log;
753753
}
754754

755+
static void
756+
debug_print_log(sentry_level_t level, const char *log_body)
757+
{
758+
// TODO if we enable our debug-macro as logging integration
759+
// we need to avoid recursion here
760+
switch (level) {
761+
case SENTRY_LEVEL_TRACE:
762+
SENTRY_TRACEF("LOG: %s", log_body);
763+
break;
764+
case SENTRY_LEVEL_DEBUG:
765+
SENTRY_DEBUGF("LOG: %s", log_body);
766+
break;
767+
case SENTRY_LEVEL_INFO:
768+
SENTRY_INFOF("LOG: %s", log_body);
769+
break;
770+
case SENTRY_LEVEL_WARNING:
771+
SENTRY_WARNF("LOG: %s", log_body);
772+
break;
773+
case SENTRY_LEVEL_ERROR:
774+
SENTRY_ERRORF("LOG: %s", log_body);
775+
break;
776+
case SENTRY_LEVEL_FATAL:
777+
SENTRY_FATALF("LOG: %s", log_body);
778+
break;
779+
}
780+
}
781+
755782
log_return_value_t
756783
sentry__logs_log(sentry_level_t level, const char *message, va_list args)
757784
{
@@ -774,6 +801,11 @@ sentry__logs_log(sentry_level_t level, const char *message, va_list args)
774801
discarded = true;
775802
}
776803
}
804+
if (options->debug && !sentry_value_is_null(log)) {
805+
debug_print_log(level,
806+
sentry_value_as_string(
807+
sentry_value_get_by_key(log, "body")));
808+
}
777809
}
778810
if (discarded) {
779811
return SENTRY_LOG_RETURN_DISCARD;

0 commit comments

Comments
 (0)