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

ios: enhance tapable logger to handle variadic args from the JS log #524

Merged
merged 6 commits into from
Oct 11, 2024

Conversation

nancywu1
Copy link
Contributor

@nancywu1 nancywu1 commented Oct 2, 2024

#523

Change Type (required)

Indicate the type of change your pull request is:

  • patch
  • minor
  • major

Does your PR have any documentation updates?

  • Updated docs
  • No Update needed
  • Unable to update docs

Release Notes

Prefixing message with the format [Player] [\(logLevel)]: moved out of the Tapable logger and moved to PrintLoggerPlugin. Any consumers using their own LoggerPlugin will need to append the logLevel if they want to print it

Before

public class CustomLoggingPlugin: NativePlugin {
    
    public let pluginName = "CustomLoggingPlugin"

    public func apply<P>(player: P) where P: HeadlessPlayer {
        guard let player = player as? SwiftUIPlayer else { return }
        player.logger.logLevel = .trace
        player.logger.hooks.trace.tap(name: pluginName, { print("Custom message")\(($0))" ) })
        ...
    }

After

public class CustomLoggingPlugin: NativePlugin {
    
    public let pluginName = "CustomLoggingPlugin"

    public func apply<P>(player: P) where P: HeadlessPlayer {
        guard let player = player as? SwiftUIPlayer else { return }
        player.logger.logLevel = .trace
        let prefixedMessage = "[Player] [trace]: "
        player.logger.hooks.trace.tap(name: pluginName, { print("\(prefixedMessage) Custom message \(($0))" ) })
        ...
    }

Breaking Changes

Any usage of the player.logger.hooks taps will have breaking changes in the callback because the calls have been changed to provide a [Any] type instead of String so it can be returned in the form of messages instead of a single message. Unless nothing is done in the callback to access the value but just to print it, there should be breaking changes

Example:

// this should be no breaking change
player.logger.hooks.trace.tap(name: "log", { print("\(($0))" ) })

// if `values` should be accessed in anyway, i.e want the first value, or want to seperate the values
 player.logger.hooks.debug.tap(name: "log") { values in
            // values is of type [Any], if you want to print only the first value
            print("\((message as? [String])?.first))" )
        }
📦 Published PR as canary version: 0.9.2--canary.524.17782

Try this version out locally by upgrading relevant packages to 0.9.2--canary.524.17782

Version

Published prerelease version: 0.10.0-next.0

Changelog

Release Notes

ios: enhance tapable logger to handle variadic args from the JS log (#524)

Prefixing message with the format [Player] [\(logLevel)]: moved out of the Tapable logger and moved to PrintLoggerPlugin. Any consumers using their own LoggerPlugin will need to append the logLevel if they want to print it

Before

public class CustomLoggingPlugin: NativePlugin {
    
    public let pluginName = "CustomLoggingPlugin"

    public func apply<P>(player: P) where P: HeadlessPlayer {
        guard let player = player as? SwiftUIPlayer else { return }
        player.logger.logLevel = .trace
        player.logger.hooks.trace.tap(name: pluginName, { print("Custom message")\(($0))" ) })
        ...
    }

After

public class CustomLoggingPlugin: NativePlugin {
    
    public let pluginName = "CustomLoggingPlugin"

    public func apply<P>(player: P) where P: HeadlessPlayer {
        guard let player = player as? SwiftUIPlayer else { return }
        player.logger.logLevel = .trace
        let prefixedMessage = "[Player] [trace]: "
        player.logger.hooks.trace.tap(name: pluginName, { print("\(prefixedMessage) Custom message \(($0))" ) })
        ...
    }

Breaking Changes

Any usage of the player.logger.hooks taps will have breaking changes in the callback because the calls have been changed to provide a [Any] type instead of String so it can be returned in the form of messages instead of a single message. Unless nothing is done in the callback to access the value but just to print it, there should be breaking changes

Example:

// this should be no breaking change
player.logger.hooks.trace.tap(name: "log", { print("\(($0))" ) })

// if `values` should be accessed in anyway, i.e want the first value, or want to seperate the values
 player.logger.hooks.debug.tap(name: "log") { values in
            // values is of type [Any], if you want to print only the first value
            print("\((message as? [String])?.first))" )
        }

🚀 Enhancement

  • ios: enhance tapable logger to handle variadic args from the JS log #524 (@nancywu1)

🐛 Bug Fix

🏠 Internal

Authors: 4

@nancywu1
Copy link
Contributor Author

nancywu1 commented Oct 2, 2024

/canary

@nancywu1
Copy link
Contributor Author

nancywu1 commented Oct 2, 2024

/canary

player.logger.hooks.warn.tap(name: pluginName, { print($0) })
player.logger.hooks.error.tap(name: pluginName, { print($0 ?? "", $1?.localizedDescription ?? "") })

let prefixedMessage = player.logger.hooks.prefixMessage.call(logLevel) ?? ""
Copy link
Contributor

Choose a reason for hiding this comment

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

i think we can remove the prefixMessage hook from TapableLogger, and just have that be opinionated behavior of PrintLoggerPlugin

@nancywu1
Copy link
Contributor Author

nancywu1 commented Oct 3, 2024

/canary

Copy link

codecov bot commented Oct 3, 2024

Codecov Report

Attention: Patch coverage is 99.04762% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.92%. Comparing base (a363556) to head (2633358).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
ios/logger/Sources/TapableLogger.swift 97.67% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #524      +/-   ##
==========================================
+ Coverage   91.91%   91.92%   +0.01%     
==========================================
  Files         341      341              
  Lines       27311    27290      -21     
  Branches     1944     1944              
==========================================
- Hits        25103    25087      -16     
+ Misses       2194     2189       -5     
  Partials       14       14              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nancywu1 nancywu1 marked this pull request as ready for review October 10, 2024 19:48
@nancywu1 nancywu1 requested a review from adierkens as a code owner October 10, 2024 19:48
@nancywu1 nancywu1 added the minor Increment the minor version when merged label Oct 11, 2024
@nancywu1 nancywu1 merged commit 47aa811 into main Oct 11, 2024
11 checks passed
@nancywu1 nancywu1 deleted the 523-enhance-tapable-logger-ios branch October 11, 2024 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Increment the minor version when merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants