sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

fix: logging when not in debug mode

Open armcknight opened this issue 3 years ago • 4 comments

Originally I noticed that the condition in SentryLog short circuits if the SDK is not in debug mode, so we will never print even error logs in a production app.

Then I noticed that the statically assigned value of diagnosticLevel in SentryLog is always overwritten by the hardcoded default in SentryOptions. This PR also centralizes the default, modifies the log level when SentryOptions.debug is modified, removes the separate tracking of debug state in SentryLog and thus simplifies the check for whether to log, since it now only needs to look at log level.

#skip-changelog

armcknight avatar Aug 10 '22 07:08 armcknight

Hmm just occurred to me that setting debug to false after setting diagnosticLevel will overwrite it to error again. That needs to be fixed. diagnosticLevel probably shouldn’t even be exposed publicly, but that’s a different story.

armcknight avatar Aug 10 '22 08:08 armcknight

@brustolin @bruno-garcia I just wanted to confirm that this change in behavior is desired. I was fixing the broken tests and noticed that one is testConfigureWithoutDebug_PrintsNothing, which tells me that this was deliberate. Do we really not want to print any warning or error messages in production? How do we get logs from customers today to help debug issues?

armcknight avatar Aug 12 '22 00:08 armcknight

@brustolin @bruno-garcia I just wanted to confirm that this change in behavior is desired. I was fixing the broken tests and noticed that one is testConfigureWithoutDebug_PrintsNothing, which tells me that this was deliberate. Do we really not want to print any warning or error messages in production? How do we get logs from customers today to help debug issues?

I like this changes for debug in development purpose, I don't see how this logs in production would help, is not like the final user would dump the device log and sent it to the developer. AFAIK (dont quote me on this 😉) this logs are not send automatically to ituneConnect app report thing.

brustolin avatar Aug 12 '22 07:08 brustolin

You have a point about end users, that would require a more integrated approach. This would be immediately helpful for any other build that doesn't set debug to true, that could be test/profile builds or TestFlight betas.

armcknight avatar Aug 12 '22 18:08 armcknight

@brustolin I updated the doc comment in SentryOptions, but that led me to make a few other changes after thinking about things some more. I deprecated diagnosticLevel so most of the changes in the latest commit deal with that. Let me know what you think.

armcknight avatar Aug 16 '22 08:08 armcknight

@brustolin I updated the doc comment in SentryOptions, but that led me to make a few other changes after thinking about things some more. I deprecated diagnosticLevel so most of the changes in the latest commit deal with that. Let me know what you think.

I had a conversation about this with @bruno-garcia last week and if I understood it right we really want diagnosticLevel. I kind like it, sometimes during debug having a very verbose SDK is a pain. The power to change granularity is nice.

brustolin avatar Aug 16 '22 09:08 brustolin

I think this should be closed now, now that we've discussed the philosophy behind how we do logging. Nothing is actually broken there, so shouldn't be messed with.

armcknight avatar Aug 17 '22 06:08 armcknight