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

Custom logger implementation on iOS #1026

Conversation

jsligh
Copy link
Collaborator

@jsligh jsligh commented Jul 16, 2024

Fixes #1023

@jsligh jsligh requested a review from YuriyVelichkoPI July 16, 2024 15:06
@jsligh jsligh self-assigned this Jul 16, 2024
@jsligh
Copy link
Collaborator Author

jsligh commented Jul 16, 2024

I will be making a docs PR after this is merged

@@ -33,38 +33,70 @@ public class Log: NSObject {
public static var logToFile = false

public static func error(_ object: Any, filename: String = #file, line: Int = #line, function: String = #function) {
log(object, logLevel: .error, filename: filename, line: line, function: function)
if (customLogger == nil) {
Copy link
Contributor

@YuriyVelichkoPI YuriyVelichkoPI Jul 24, 2024

Choose a reason for hiding this comment

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

In my opinion, this kind of functionality should be implemented in the following way:

  1. Introduce the class SDKConsoleLogger which implements PrebidLogger protocol
  2. Introduce internal property var logger: PrebidLogger? = SDKConsoleLogger()
  3. Introduce a custom setter for the logger so pubs can set up own one.
  4. in all functions of the Log class just use logger?.dosomething( .... )

It will alow to avoid if ... else and seamlessly add another SDK loggers like SDKFileLogger if needed.

@jsligh jsligh requested a review from YuriyVelichkoPI July 29, 2024 16:36
public static var logLevel: LogLevel = .debug
public static var logToFile = false

public static func error(_ object: Any, filename: String = #file, line: Int = #line, function: String = #function) {
log(object, logLevel: .error, filename: filename, line: line, function: function)
logger?.error(object, filename: filename, line: line, function: function)
}

public static func info(_ object: Any, filename: String = #file, line: Int = #line, function: String = #function) {
log(object, logLevel: .info, filename: filename, line: line, function: function)
Copy link
Contributor

Choose a reason for hiding this comment

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

Now, you should remove system fogging from the Log class. Otherwise, the same messages will be logged twice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They shouldn't because the SDKConsoleLogger's log method doesn't post to the system log.

@jsligh jsligh force-pushed the 1023-setcustomlogger-implementation-from-android-library-is-not-present-in-ios-library branch from 729d976 to bb768f8 Compare August 22, 2024 16:15
@YuriyVelichkoPI
Copy link
Contributor

@ValentinPostindustria, could you please finalize this PR?

@OlenaPostindustria OlenaPostindustria marked this pull request as draft January 8, 2025 11:20
@OlenaPostindustria OlenaPostindustria force-pushed the 1023-setcustomlogger-implementation-from-android-library-is-not-present-in-ios-library branch from f534dcf to 0d602ae Compare January 8, 2025 11:22
@OlenaPostindustria OlenaPostindustria changed the title setcustomlogger implementation on iOS Custom logger implementation on iOS Jan 8, 2025
@OlenaPostindustria OlenaPostindustria marked this pull request as ready for review January 8, 2025 15:53
@OlenaPostindustria OlenaPostindustria force-pushed the 1023-setcustomlogger-implementation-from-android-library-is-not-present-in-ios-library branch from bffef8e to b58f46c Compare January 9, 2025 10:40
Copy link
Contributor

@YuriyVelichkoPI YuriyVelichkoPI left a comment

Choose a reason for hiding this comment

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

LGTM

@YuriyVelichkoPI YuriyVelichkoPI merged commit 110f6d2 into master Jan 10, 2025
4 checks passed
@YuriyVelichkoPI YuriyVelichkoPI deleted the 1023-setcustomlogger-implementation-from-android-library-is-not-present-in-ios-library branch January 10, 2025 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

setCustomLogger implementation from Android Library is not present in iOS library
4 participants