Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Unreleased

### Improvements

- Add logs from SentrySDK.logger to Godot output ([#463](https://github.com/getsentry/sentry-godot/pull/463))
- This behavior is enabled by default and can be disabled by setting `SentryOptions.print_logs` to `false`.

## 1.2.0

### Features
Expand Down
3 changes: 3 additions & 0 deletions doc_classes/SentryOptions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
<member name="max_breadcrumbs" type="int" setter="set_max_breadcrumbs" getter="get_max_breadcrumbs" default="100">
Maximum number of breadcrumbs to send with an event. You should be aware that Sentry has a maximum payload size and any events exceeding that payload size will be dropped.
</member>
<member name="print_logs" type="bool" setter="set_print_logs" getter="is_print_logs_enabled" default="true">
If [code]true[/code], the SDK will print log messages added with [member SentrySDK.logger] API to the Godot console in addition to sending them to Sentry. When disabled, log messages will only be sent to Sentry without appearing in the local console output.
</member>
<member name="release" type="String" setter="set_release" getter="get_release" default="&quot;{app_name}@{app_version}&quot;">
Release version of the application. This value must be unique across all projects in your organization. Suggested format is [code][email protected][/code].
You can use the [code]{app_name}[/code] and [code]{app_version}[/code] placeholders to insert the application name and version from the Project Settings.
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/logging/sentry_godot_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ void SentryGodotLogger::_log_message(const String &p_message, bool p_error) {
return;
}

bool as_log = SentryOptions::get_singleton()->get_enable_logs();
bool as_log = SentryOptions::get_singleton()->get_enable_logs() && !sentry::logging::skip_logging_messages;
bool as_breadcrumb = SentryOptions::get_singleton()->is_logger_messages_as_breadcrumbs_enabled();

if (!as_log && !as_breadcrumb) {
Expand Down
1 change: 1 addition & 0 deletions src/sentry/logging/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
namespace sentry::logging {

thread_local bool in_message_logging = false;
thread_local bool skip_logging_messages = false;

} //namespace sentry::logging
7 changes: 7 additions & 0 deletions src/sentry/logging/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ struct MessageScope {
~MessageScope() { in_message_logging = false; }
};

// Controls whether Godot logger messages should be forwarded to Sentry Logs.
// When true, Godot logger messages are suppressed and not sent to Logs.
// This flag is used by SentryLogger to send log messages with custom structure
// while avoiding duplicate messages that would otherwise be produced by the
// Godot logging system.
extern thread_local bool skip_logging_messages;

} //namespace sentry::logging
24 changes: 24 additions & 0 deletions src/sentry/sentry_logger.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include "sentry_logger.h"

#include "sentry/logging/state.h"
#include "sentry/sentry_log.h" // Needed for VariantCaster<LogLevel>
#include "sentry/sentry_sdk.h"

#include <godot_cpp/variant/utility_functions.hpp>

namespace sentry {

void SentryLogger::log(LogLevel p_level, const String &p_body, const Array &p_params, const Dictionary &p_attributes) {
Expand All @@ -17,7 +20,28 @@ void SentryLogger::log(LogLevel p_level, const String &p_body, const Array &p_pa
}
body = p_body % p_params;
}

INTERNAL_SDK()->log(p_level, body, attributes);

if (SentryOptions::get_singleton()->is_print_logs_enabled()) {
// Add log to Godot's logging system without triggering recursive logging to Sentry Logs.
sentry::logging::skip_logging_messages = true;
switch (p_level) {
case LOG_LEVEL_TRACE:
case LOG_LEVEL_DEBUG:
case LOG_LEVEL_INFO: {
UtilityFunctions::print(body);
} break;
case LOG_LEVEL_WARN: {
UtilityFunctions::push_warning(body);
} break;
case LOG_LEVEL_ERROR:
case LOG_LEVEL_FATAL: {
UtilityFunctions::push_error(body);
} break;
}
sentry::logging::skip_logging_messages = false;
}
}

void SentryLogger::trace(const String &p_body, const Array &p_params, const Dictionary &p_attributes) {
Expand Down
10 changes: 7 additions & 3 deletions src/sentry/sentry_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ void SentryOptions::_define_project_settings(const Ref<SentryOptions> &p_options
ERR_FAIL_NULL(ProjectSettings::get_singleton());

// Migrate renamed project settings to their new locations
_migrate_setting("sentry/experimental/enable_logs", "sentry/options/enable_logs");
_migrate_setting("sentry/experimental/enable_logs", "sentry/options/logs/enable_logs");
_migrate_setting("sentry/options/enable_logs", "sentry/options/logs/enable_logs");

_define_setting("sentry/options/auto_init", p_options->auto_init);
_define_setting("sentry/options/skip_auto_init_on_editor_play", p_options->skip_auto_init_on_editor_play);
Expand All @@ -112,7 +113,8 @@ void SentryOptions::_define_project_settings(const Ref<SentryOptions> &p_options
_define_setting("sentry/options/attach_log", p_options->attach_log, false);
_define_setting("sentry/options/attach_scene_tree", p_options->attach_scene_tree);

_define_setting("sentry/options/enable_logs", p_options->enable_logs, false);
_define_setting("sentry/options/logs/enable_logs", p_options->enable_logs, false);
_define_setting("sentry/options/logs/print_logs", p_options->print_logs, false);

_define_setting("sentry/options/app_hang/tracking", p_options->app_hang_tracking, false);
_define_setting("sentry/options/app_hang/timeout_sec", p_options->app_hang_timeout_sec, false);
Expand Down Expand Up @@ -158,7 +160,8 @@ void SentryOptions::_load_project_settings(const Ref<SentryOptions> &p_options)
p_options->attach_log = ProjectSettings::get_singleton()->get_setting("sentry/options/attach_log", p_options->attach_log);
p_options->attach_scene_tree = ProjectSettings::get_singleton()->get_setting("sentry/options/attach_scene_tree", p_options->attach_scene_tree);

p_options->enable_logs = ProjectSettings::get_singleton()->get_setting("sentry/options/enable_logs", p_options->enable_logs);
p_options->enable_logs = ProjectSettings::get_singleton()->get_setting("sentry/options/logs/enable_logs", p_options->enable_logs);
p_options->print_logs = ProjectSettings::get_singleton()->get_setting("sentry/options/logs/print_logs", p_options->print_logs);

p_options->app_hang_tracking = ProjectSettings::get_singleton()->get_setting("sentry/options/app_hang/tracking", p_options->app_hang_tracking);
p_options->app_hang_timeout_sec = ProjectSettings::get_singleton()->get_setting("sentry/options/app_hang/timeout_sec", p_options->app_hang_timeout_sec);
Expand Down Expand Up @@ -245,6 +248,7 @@ void SentryOptions::_bind_methods() {
BIND_PROPERTY(SentryOptions, PropertyInfo(Variant::BOOL, "attach_scene_tree"), set_attach_scene_tree, is_attach_scene_tree_enabled);

BIND_PROPERTY(SentryOptions, PropertyInfo(Variant::BOOL, "enable_logs"), set_enable_logs, get_enable_logs);
BIND_PROPERTY(SentryOptions, PropertyInfo(Variant::BOOL, "print_logs"), set_print_logs, is_print_logs_enabled);
BIND_PROPERTY(SentryOptions, PropertyInfo(Variant::CALLABLE, "before_send_log"), set_before_send_log, get_before_send_log);

BIND_PROPERTY(SentryOptions, PropertyInfo(Variant::BOOL, "app_hang_tracking"), set_app_hang_tracking, is_app_hang_tracking_enabled);
Expand Down
6 changes: 5 additions & 1 deletion src/sentry/sentry_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class SentryOptions : public RefCounted {
bool attach_scene_tree = false;

bool enable_logs = true;
Callable before_send_log;
bool print_logs = true;

bool app_hang_tracking = false;
double app_hang_timeout_sec = 5.0;
Expand All @@ -100,6 +100,7 @@ class SentryOptions : public RefCounted {

Callable before_send;
Callable before_capture_screenshot;
Callable before_send_log;

Vector<Ref<SentryEventProcessor>> event_processors;

Expand Down Expand Up @@ -164,6 +165,9 @@ class SentryOptions : public RefCounted {
_FORCE_INLINE_ bool get_enable_logs() const { return enable_logs; }
_FORCE_INLINE_ void set_enable_logs(bool p_enabled) { enable_logs = p_enabled; }

_FORCE_INLINE_ bool is_print_logs_enabled() const { return print_logs; }
_FORCE_INLINE_ void set_print_logs(bool p_enabled) { print_logs = p_enabled; }

_FORCE_INLINE_ Callable get_before_send_log() const { return before_send_log; }
_FORCE_INLINE_ void set_before_send_log(const Callable &p_callback) { before_send_log = p_callback; }

Expand Down
Loading