PostHog / posthog-ios

PostHog iOS SDK
https://posthog.com/docs/libraries/ios
MIT License
28 stars 37 forks source link

Enable logs without setup SDK #101

Closed GeorgeKyrylenko1998 closed 5 months ago

GeorgeKyrylenko1998 commented 5 months ago

Problem Statement

I try to configure SDK and have some troubles (is not a problem), I go to enable SDK logs to check what is going wrong but logs are not work, after this I have open source code and found this interesting think. which mean you cannot get logs without setup SDK but for setup SDK when you are have some issue you are need logs which need configured SDK @objc public func debug(_ enabled: Bool = true) { if !isEnabled() { return } toggleHedgeLog(enabled) }

Solution Brainstorm

Please give possibility to enable logs without SDK configuration @objc public func debug(_ enabled: Bool = true) { toggleHedgeLog(enabled) }

marandaneto commented 5 months ago

Hi @GeorgeKyrylenko1998

That is intended, the debug call only works if the SDK is enabled/configured.

Check this out https://posthog.com/docs/libraries/ios#configuration

Just do this instead:

let config = PostHogConfig(apiKey: POSTHOG_API_KEY, host: POSTHOG_HOST) 
config.debug = true
PostHogSDK.shared.setup(config)

Then you will get de logs.

GeorgeKyrylenko1998 commented 5 months ago

@marandaneto I guess is not a clear to understand + I have no find debug by search https://posthog.com/docs/libraries/ios#configuration I guess more easy is enable/disable logs in one place and do not still in mind is SDK configured in this moment or not

marandaneto commented 5 months ago

@marandaneto I guess is not a clear to understand + I have no find debug by search posthog.com/docs/libraries/ios#configuration I guess more easy is enable/disable logs in one place and do not still in mind is SDK configured in this moment or not

that flag is not mentioned in the docs, indeed. but you can do exactly what I told you here and it'll work. this option enables debug before the SDK is init. the PostHogSDK.shared.debug(true) or false is after the SDK is already running, both approaches are valid.