Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logging: Add rn warning and logging #798

Merged
merged 2 commits into from
Jul 3, 2023

Conversation

Eric-Warehime
Copy link
Contributor

Adds a log when we detect we're running in react-native which tells users they will need to polyfill crypto libraries.

The react-native project does not (and probably won't) provide any crypto functionality facebook/react-native#5049 so users need to polyfill things like crypto.getRandomValues if they want to do address generation.

I've added a convenience function to determine if we're in react-native ( see facebook/react-native@e966cd1 )

Also added tslog to provide logging cross platform and an exported function for users to adjust the log level if they don't want to see any logs.

src/logging.ts Outdated
/**
* setLogLevel adjusts the minimum level of logs which are output by the SDK's logger
*/
export function setLogLevel(level: number) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this somehow being called implicitly somewhere?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading your PR description more carefully I see the purpose now. Perhaps we have enough static checks to see that this function is well formed. Regardless, a unit test can act as a sanity check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not being called anywhere, it's set that users can set the log level to turn off logs if they don't want to see a certain level.

Copy link
Contributor

@winder winder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only concern is whether or not we should document this behavior somehow. I guess the log is to make it self-documenting so I'm also OK with it as-is. I don't have any opinion on the logging library, but it seems like a sensible approach to providing this hint to the developers.

Copy link

@Blackglade Blackglade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just wary of adding a logging specific package when logging isn't prevalent in the app to begin with. I think this is the only place (outside maybe some examples) that a log function is called. Maybe worth just switching to console.warn() until there's a specific need for more custom sdk-wide logging. (unless there are plans in future PR's to introduce a lot more logging)

@Eric-Warehime
Copy link
Contributor Author

@Blackglade Yeah I can change to a console log. My inclination is to introduce more logging in the future, but if it's not something that people want/need then yeah minimizing the dependencies is best.

@Eric-Warehime Eric-Warehime merged commit 6c3194f into algorand:develop Jul 3, 2023
@Eric-Warehime Eric-Warehime deleted the rn-warning-logging branch July 3, 2023 20:02
joe-p pushed a commit to joe-p/js-algorand-sdk that referenced this pull request Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants