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

setcustomlogger implementation on iOS #1026

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
6 changes: 0 additions & 6 deletions InternalTestApp/InternalTestApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
34FC0CF624ADD5640045553E /* PrebidGAMRewardedController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34FC0CF524ADD5640045553E /* PrebidGAMRewardedController.swift */; };
3C28C9D82C35713B00D0A7DB /* CustomRendererInterstitialController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C28C9D72C35713B00D0A7DB /* CustomRendererInterstitialController.swift */; };
3C28C9D92C35713B00D0A7DB /* CustomRendererInterstitialController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C28C9D72C35713B00D0A7DB /* CustomRendererInterstitialController.swift */; };
3C28C9DB2C357E3500D0A7DB /* SampleCustomRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C28C9DA2C357E3500D0A7DB /* SampleCustomRenderer.swift */; };
3C28C9DC2C357E3500D0A7DB /* SampleCustomRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C28C9DA2C357E3500D0A7DB /* SampleCustomRenderer.swift */; };
3CC4A3E92C11F96800B97128 /* CustomRendererBannerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CC4A3E82C11F96800B97128 /* CustomRendererBannerController.swift */; };
3CC4A3EA2C11F96800B97128 /* CustomRendererBannerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CC4A3E82C11F96800B97128 /* CustomRendererBannerController.swift */; };
457FD34BA45C3840CC31A8F5 /* Pods_InternalTestApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5C11D97034E668BBFDD0DDCA /* Pods_InternalTestApp.framework */; };
Expand Down Expand Up @@ -381,7 +379,6 @@
35F94D131F93F85D00CF46DB /* InternalTestAppUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = InternalTestAppUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
35F94D171F93F85D00CF46DB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3C28C9D72C35713B00D0A7DB /* CustomRendererInterstitialController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomRendererInterstitialController.swift; sourceTree = "<group>"; };
3C28C9DA2C357E3500D0A7DB /* SampleCustomRenderer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleCustomRenderer.swift; sourceTree = "<group>"; };
3CC4A3E82C11F96800B97128 /* CustomRendererBannerController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomRendererBannerController.swift; sourceTree = "<group>"; };
530E722B292FACB20025B44D /* UIImageView+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImageView+Extensions.swift"; sourceTree = "<group>"; };
5397BD132936185400ABDA22 /* PrebidOriginalAPIDisplayBannerController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrebidOriginalAPIDisplayBannerController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -847,7 +844,6 @@
34B10A2F255017DE00B5FE09 /* ThreadCheckingButton.swift */,
34C25816255D69E1000A4A73 /* EventReportContainer.swift */,
530E722B292FACB20025B44D /* UIImageView+Extensions.swift */,
3C28C9DA2C357E3500D0A7DB /* SampleCustomRenderer.swift */,
);
path = Utilities;
sourceTree = "<group>";
Expand Down Expand Up @@ -1577,7 +1573,6 @@
53ED2FE829798104007D13EE /* PrebidBannerController.swift in Sources */,
53ED2FE929798104007D13EE /* PrebidBannerConfigurationController.swift in Sources */,
53ED2FEA29798104007D13EE /* TestCase.swift in Sources */,
3C28C9DC2C357E3500D0A7DB /* SampleCustomRenderer.swift in Sources */,
53ED2FEB29798104007D13EE /* PrebidAdMobNativeViewController.swift in Sources */,
53ED2FEC29798104007D13EE /* PrebidInterstitialController.swift in Sources */,
53ED2FED29798104007D13EE /* PrebidOriginalAPIDisplayInterstitialController.swift in Sources */,
Expand Down Expand Up @@ -1674,7 +1669,6 @@
3493022224740BEE004A6086 /* PrebidBannerController.swift in Sources */,
5BDB85DA2739794900A529F6 /* PrebidBannerConfigurationController.swift in Sources */,
5B3EEDE52101FB8800BAA0C4 /* TestCase.swift in Sources */,
3C28C9DB2C357E3500D0A7DB /* SampleCustomRenderer.swift in Sources */,
92C475122796FF8400C26E27 /* PrebidAdMobNativeViewController.swift in Sources */,
34FC0CF424ADD3A80045553E /* PrebidInterstitialController.swift in Sources */,
5397BD26293760F500ABDA22 /* PrebidOriginalAPIDisplayInterstitialController.swift in Sources */,
Expand Down

This file was deleted.

9 changes: 9 additions & 0 deletions PrebidMobile.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,8 @@
A908694629E05F7900B37479 /* PrebidRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = A908694529E05F7900B37479 /* PrebidRenderer.swift */; };
A9750D7A2ABB9A300066E4E6 /* PluginEventListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9750D792ABB9A300066E4E6 /* PluginEventListener.swift */; };
A9A3396B2AC57193006AD0E7 /* PBMAdViewDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9A3396A2AC57193006AD0E7 /* PBMAdViewDelegate.swift */; };
F9F0999D2C78CC8A007DB464 /* SDKConsoleLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9F0999C2C78CC8A007DB464 /* SDKConsoleLogger.swift */; };
F95DA2072C87567D0068A2BB /* SampleCustomRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F95DA2062C87567D0068A2BB /* SampleCustomRenderer.swift */; };
FA5AD5E42271FA4100C8F274 /* ConstantsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA5AD5E32271FA4100C8F274 /* ConstantsTest.swift */; };
FA9D7F2722E8A83D006FCBEF /* AdViewUtilsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA9D7F2622E8A83D006FCBEF /* AdViewUtilsTests.swift */; };
FAA29904242D1C27002ACBF2 /* TargetingObjCTests.m in Sources */ = {isa = PBXBuildFile; fileRef = FAA29903242D1C27002ACBF2 /* TargetingObjCTests.m */; };
Expand Down Expand Up @@ -1672,6 +1674,8 @@
A908694529E05F7900B37479 /* PrebidRenderer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrebidRenderer.swift; sourceTree = "<group>"; };
A9750D792ABB9A300066E4E6 /* PluginEventListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PluginEventListener.swift; sourceTree = "<group>"; };
A9A3396A2AC57193006AD0E7 /* PBMAdViewDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PBMAdViewDelegate.swift; sourceTree = "<group>"; };
F9F0999C2C78CC8A007DB464 /* SDKConsoleLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SDKConsoleLogger.swift; sourceTree = "<group>"; };
F95DA2062C87567D0068A2BB /* SampleCustomRenderer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SampleCustomRenderer.swift; sourceTree = "<group>"; };
FA4A88432497A99D00FDCBB6 /* Swizzling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Swizzling.swift; sourceTree = "<group>"; };
FA5AD5E32271FA4100C8F274 /* ConstantsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConstantsTest.swift; sourceTree = "<group>"; };
FA85F9B4264946FC00B8BE72 /* TestUtils.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = TestUtils.xcodeproj; path = ../tools/TestUtils/TestUtils.xcodeproj; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1896,6 +1900,7 @@
FAEE4CE2262DC2B200AD9966 /* Log.swift */,
531CF21827E8FC1B005E5ABE /* LogLevel.swift */,
53F096C927E917D40058C94C /* Log+Extensions.h */,
F9F0999C2C78CC8A007DB464 /* SDKConsoleLogger.swift */,
);
path = Logging;
sourceTree = "<group>";
Expand Down Expand Up @@ -3184,6 +3189,7 @@
A908694029E05E8D00B37479 /* PluginRenderer */ = {
isa = PBXGroup;
children = (
F95DA2062C87567D0068A2BB /* SampleCustomRenderer.swift */,
A908694129E05EAF00B37479 /* PrebidMobilePluginRegister.swift */,
A908694329E05ED500B37479 /* PrebidMobilePluginRenderer.swift */,
A9750D792ABB9A300066E4E6 /* PluginEventListener.swift */,
Expand Down Expand Up @@ -3857,6 +3863,7 @@
925D5D702737B74E00A8A2B5 /* PBMTouchForwardingViewTest.swift in Sources */,
FAA299122434C769002ACBF2 /* UtilsObjCTests.m in Sources */,
925D5E7A2737F62500A8A2B5 /* VideoFileTypeTest.swift in Sources */,
F9F0999E2C78CC8A007DB464 /* SDKConsoleLogger.swift in Sources */,
925D5DB12737C54500A8A2B5 /* MockAdLoader.swift in Sources */,
925D5D742737B7FB00A8A2B5 /* UserConsentManagerTest.swift in Sources */,
922AFD2E2737260900732C53 /* PBMDeepLinkPlusHelperTest.swift in Sources */,
Expand Down Expand Up @@ -4154,6 +4161,7 @@
537B6518283372FD008AE9D1 /* PathBuilder.swift in Sources */,
FAEE4D1A262DC2B200AD9966 /* NativeAd.swift in Sources */,
5BC37A1B271F1D0000444D5E /* Prebid.swift in Sources */,
F95DA2072C87567D0068A2BB /* SampleCustomRenderer.swift in Sources */,
5BC379A8271F1D0000444D5E /* PBMModalViewController.m in Sources */,
5BC37AC3271F1D0100444D5E /* PBMURLComponents.m in Sources */,
5BC378D3271F1CFF00444D5E /* PBMORTBAbstract.m in Sources */,
Expand Down Expand Up @@ -4235,6 +4243,7 @@
53C925022990FB30009E6F94 /* String+Extensions.swift in Sources */,
53A368E92AB2E38200A03B3E /* BidInfo.swift in Sources */,
799109FB28F99C2B004837B4 /* PBMORTBAppExt.m in Sources */,
F9F0999D2C78CC8A007DB464 /* SDKConsoleLogger.swift in Sources */,
925A641627317A39009E72F9 /* HiddenWebViewManager.swift in Sources */,
5BC3796C271F1D0000444D5E /* PBMVastCreativeLinear.m in Sources */,
928E5A7027F0F743000ADA1A /* ContextSubType.swift in Sources */,
Expand Down
34 changes: 33 additions & 1 deletion PrebidMobile/Logging/Log.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Foundation
public class Log: NSObject {

// MARK: - Public properties

public static var logger: PrebidLogger? = SDKConsoleLogger()
public static var dateFormat = "yyyy-MM-dd hh:mm:ssSSS"
public static var dateFormatter: DateFormatter {
let formatter = DateFormatter()
Expand All @@ -29,35 +29,46 @@ public class Log: NSObject {
return formatter
}

public static func setCustomLogger(customLogger: PrebidLogger?) {
logger = customLogger
}

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)
jsligh marked this conversation as resolved.
Show resolved Hide resolved
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.

logger?.info(object, filename: filename, line: line, function: function)
}

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

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

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

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

public static func whereAmI(filename: String = #file, line: Int = #line, function: String = #function) {
log("", logLevel: .info, filename: filename, line: line, function: function)
logger?.whereAmI(filename: filename, line: line, function: function)
}

static func log(_ object: Any, logLevel: LogLevel, filename: String, line: Int, function: String) {
Expand All @@ -66,6 +77,7 @@ public class Log: NSObject {
print(finalMessage)
serialWriteToLog(finalMessage)
}
logger?.log(object, logLevel: logLevel, filename: filename, line: line, function: function)
}

public static func serialWriteToLog(_ message: String) {
Expand Down Expand Up @@ -186,3 +198,23 @@ func print(_ object: Any) {
Swift.print(object)
#endif
}

public protocol PrebidLogger {

func error(_ object: Any, filename: String, line: Int, function: String)

func info(_ object: Any, filename: String, line: Int, function: String)

func debug(_ object: Any, filename: String, line: Int, function: String)

func verbose(_ object: Any, filename: String, line: Int, function: String)

func warn(_ object: Any, filename: String, line: Int, function: String)

func severe(_ object: Any, filename: String, line: Int, function: String)

func whereAmI(filename: String, line: Int, function: String)

func log(_ object: Any, logLevel: LogLevel, filename: String, line: Int, function: String)

}
51 changes: 51 additions & 0 deletions PrebidMobile/Logging/SDKConsoleLogger.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*   Copyright 2018-2024 Prebid.org, Inc.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

import Foundation

@objc public class SDKConsoleLogger: NSObject, PrebidLogger {

public func error(_ object: Any, filename: String, line: Int, function: String) {
log(object, logLevel: .error, filename: filename, line: line, function: function)
}

public func info(_ object: Any, filename: String, line: Int, function: String) {
log(object, logLevel: .info, filename: filename, line: line, function: function)
}

public func debug(_ object: Any, filename: String, line: Int, function: String) {
log(object, logLevel: .debug, filename: filename, line: line, function: function)
}

public func verbose(_ object: Any, filename: String, line: Int, function: String) {
log(object, logLevel: .verbose, filename: filename, line: line, function: function)
}

public func warn(_ object: Any, filename: String, line: Int, function: String) {
log(object, logLevel: .warn, filename: filename, line: line, function: function)
}

public func severe(_ object: Any, filename: String, line: Int, function: String) {
log(object, logLevel: .severe, filename: filename, line: line, function: function)
}

public func whereAmI(filename: String, line: Int, function: String) {

}

public func log(_ object: Any, logLevel: LogLevel, filename: String, line: Int, function: String) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
 See the License for the specific language governing permissions and
 limitations under the License.
 */

import Foundation
import PrebidMobile
import UIKit

public class SampleCustomRenderer: NSObject, PrebidMobilePluginRenderer {
Expand Down
Loading