Skip to content

Commit

Permalink
Add Instabug logging destination.
Browse files Browse the repository at this point in the history
  • Loading branch information
BorysKasianenko-okta authored and stevelind-okta committed Sep 13, 2021
1 parent 05624c1 commit 9981650
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 13 deletions.
14 changes: 12 additions & 2 deletions OktaLogger.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "OktaLogger"
s.version = "1.2.3"
s.version = "1.3.0"
s.summary = "Logging proxy for standardized logging interface across products"
s.description = "Standard interface for all logging in Okta apps + SDK. Supports file, console, firebase logging destinations."
s.homepage = "https://github.com/okta/okta-logger-swift"
Expand All @@ -19,6 +19,7 @@ Pod::Spec.new do |s|
s.subspec "Complete" do |complete|
complete.dependency 'OktaLogger/FileLogger'
complete.dependency 'OktaLogger/FirebaseCrashlytics'
complete.dependency 'OktaLogger/InstabugLogger'
end

s.subspec "MacOS" do |macos|
Expand Down Expand Up @@ -52,13 +53,22 @@ Pod::Spec.new do |s|
appCenterLogger.dependency 'OktaLogger/Core'
end

s.subspec 'InstabugLogger' do |instabugLogger|
instabugLogger.ios.source_files = [
'OktaLogger/InstabugLogger/*'
]
instabugLogger.ios.dependency 'Instabug', '~>10.7.5'
instabugLogger.ios.dependency 'OktaLogger/Core'
end

s.subspec "Core" do |core|
core.source_files = 'OktaLogger/*.{h,m,swift}'
core.exclude_files = [
'OktaLogger/Info.plist',
'OktaLogger/FileLoggers',
'OktaLogger/FirebaseCrashlyticsLogger',
'OktaLogger/AppCenterLogger'
'OktaLogger/AppCenterLogger',
'OktaLogger/InstabugLogger'
]
end

Expand Down
54 changes: 53 additions & 1 deletion OktaLogger.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 51;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -32,8 +32,10 @@
DE2FFE21260B89650028CAD6 /* OktaLoggerFileLoggerMultithreadingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE2FFE20260B89650028CAD6 /* OktaLoggerFileLoggerMultithreadingTests.swift */; };
DE504DC425BEE84A00B27BDD /* OktaLoggerFileLogFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE504DC325BEE84A00B27BDD /* OktaLoggerFileLogFormatter.swift */; };
DE6A163725F1120100B0FBA0 /* LogsBrowseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE6A163625F1120100B0FBA0 /* LogsBrowseViewController.swift */; };
DE9B02FF26BD6A090072A501 /* OktaLoggerInstabugLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE9B02FE26BD6A090072A501 /* OktaLoggerInstabugLogger.swift */; };
DEABAFC9260C7C0100DB7008 /* FileTestsHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEABAFC8260C7C0100DB7008 /* FileTestsHelper.swift */; };
DEC5276624DBF9630022B698 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = DEC5276524DBF9630022B698 /* GoogleService-Info.plist */; };
DEE498C726C1139A00487014 /* OktaLoggerInstabugLoggerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEE498C626C1139A00487014 /* OktaLoggerInstabugLoggerTests.swift */; };
DEF2CC23260A341300F8B644 /* OktaLoggerMultithreadingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEF2CC22260A341300F8B644 /* OktaLoggerMultithreadingTests.swift */; };
DEFB59E124EAC76400A1744F /* OktaLoggerFirebaseCrashlyticsLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEFB59E024EAC76300A1744F /* OktaLoggerFirebaseCrashlyticsLogger.swift */; };
E251E7FE248AD1B400EF466D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E251E7FD248AD1B400EF466D /* AppDelegate.swift */; };
Expand Down Expand Up @@ -126,8 +128,10 @@
DE2FFE20260B89650028CAD6 /* OktaLoggerFileLoggerMultithreadingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OktaLoggerFileLoggerMultithreadingTests.swift; sourceTree = "<group>"; };
DE504DC325BEE84A00B27BDD /* OktaLoggerFileLogFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OktaLoggerFileLogFormatter.swift; sourceTree = "<group>"; };
DE6A163625F1120100B0FBA0 /* LogsBrowseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogsBrowseViewController.swift; sourceTree = "<group>"; };
DE9B02FE26BD6A090072A501 /* OktaLoggerInstabugLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OktaLoggerInstabugLogger.swift; sourceTree = "<group>"; };
DEABAFC8260C7C0100DB7008 /* FileTestsHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileTestsHelper.swift; sourceTree = "<group>"; };
DEC5276524DBF9630022B698 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
DEE498C626C1139A00487014 /* OktaLoggerInstabugLoggerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OktaLoggerInstabugLoggerTests.swift; sourceTree = "<group>"; };
DEF2CC22260A341300F8B644 /* OktaLoggerMultithreadingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OktaLoggerMultithreadingTests.swift; sourceTree = "<group>"; };
DEFB59E024EAC76300A1744F /* OktaLoggerFirebaseCrashlyticsLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OktaLoggerFirebaseCrashlyticsLogger.swift; sourceTree = "<group>"; };
DF75E3D21D2B9A971A2CAEC7 /* libPods-OktaLoggerDemoApp.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-OktaLoggerDemoApp.a"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -229,6 +233,7 @@
D5C824D62469DBF1005CF747 /* OktaLogger */ = {
isa = PBXGroup;
children = (
DE9B02FD26BD697B0072A501 /* InstabugLogger */,
8DCF5F662644B23F008698CD /* AppCenterLogger */,
8004832F24C1F0F0008BFF3A /* FileLoggers */,
DEFB59DF24EAC76300A1744F /* FirebaseCrashlyticsLogger */,
Expand All @@ -252,6 +257,7 @@
804F18F624C0174800894A52 /* OktaLoggerFileLoggerTests.swift */,
DE2FFE20260B89650028CAD6 /* OktaLoggerFileLoggerMultithreadingTests.swift */,
D5D0978D246DE00800C1362F /* OktaLoggerConsoleLoggerTests.swift */,
DEE498C626C1139A00487014 /* OktaLoggerInstabugLoggerTests.swift */,
D5D0978A246CB52900C1362F /* Helpers */,
D5C824E42469DBF1005CF747 /* Info.plist */,
D5B22D07246C8E39007ECC2F /* OktaLoggerTests-Bridging-Header.h */,
Expand All @@ -270,6 +276,14 @@
path = Helpers;
sourceTree = "<group>";
};
DE9B02FD26BD697B0072A501 /* InstabugLogger */ = {
isa = PBXGroup;
children = (
DE9B02FE26BD6A090072A501 /* OktaLoggerInstabugLogger.swift */,
);
path = InstabugLogger;
sourceTree = "<group>";
};
DEC9C9CB24E57AC800AAFAE0 /* Recovered References */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -368,6 +382,7 @@
D5C824D92469DBF1005CF747 /* Sources */,
D5C824DA2469DBF1005CF747 /* Frameworks */,
D5C824DB2469DBF1005CF747 /* Resources */,
9ECAD1E0171C5273C443BE35 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand All @@ -389,6 +404,7 @@
E251E7F9248AD1B400EF466D /* Resources */,
80DDE77E24B961B400D0E2F3 /* Embed Frameworks */,
DEC5276724DBFE6C0022B698 /* ShellScript */,
20382702DB652A5C8D9E415D /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -494,6 +510,23 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
20382702DB652A5C8D9E415D /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-OktaLoggerDemoApp/Pods-OktaLoggerDemoApp-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-OktaLoggerDemoApp/Pods-OktaLoggerDemoApp-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-OktaLoggerDemoApp/Pods-OktaLoggerDemoApp-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
3EDE391A122E4EE902619005 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -538,6 +571,23 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
9ECAD1E0171C5273C443BE35 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-OktaLoggerTests/Pods-OktaLoggerTests-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-OktaLoggerTests/Pods-OktaLoggerTests-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-OktaLoggerTests/Pods-OktaLoggerTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
DEC5276724DBFE6C0022B698 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -571,6 +621,7 @@
D54461CB246B55A600C755F1 /* OktaLoggerDestination.swift in Sources */,
8004832E24C1EFDF008BFF3A /* OktaLoggerFileLoggerConfig.swift in Sources */,
8DCF5F682644B25D008698CD /* AppCenterLogger.swift in Sources */,
DE9B02FF26BD6A090072A501 /* OktaLoggerInstabugLogger.swift in Sources */,
806FF25E24B95A3300994D4D /* OktaLoggerFileLogger.swift in Sources */,
D52C2AD12474A4F5003CCF4D /* ReadWriteLock.swift in Sources */,
6582A2024047A1BC55BC98D3 /* LumberjackLoggerDelegate.swift in Sources */,
Expand All @@ -583,6 +634,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
DEE498C726C1139A00487014 /* OktaLoggerInstabugLoggerTests.swift in Sources */,
804F18F724C0174800894A52 /* OktaLoggerFileLoggerTests.swift in Sources */,
D5D0978E246DE00800C1362F /* OktaLoggerConsoleLoggerTests.swift in Sources */,
DEABAFC9260C7C0100DB7008 /* FileTestsHelper.swift in Sources */,
Expand Down
60 changes: 60 additions & 0 deletions OktaLogger/InstabugLogger/OktaLoggerInstabugLogger.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2021-Present, Okta, Inc. and/or its affiliates. All rights reserved.
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (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 Instabug

/**
Concrete logging class for Instabug.
*/
open class OktaLoggerInstabugLogger: OktaLoggerDestinationBase {

override open func log(level: OktaLoggerLogLevel, eventName: String, message: String?, properties: [AnyHashable: Any]?, file: String, line: NSNumber, funcName: String) {
guard Instabug.enabled else {
return
}
let logString = self.stringValue(
level: level,
eventName: eventName,
message: message,
file: file,
line: line,
funcName: funcName
)
switch level {
case .all:
IBGLog.logVerbose(logString)
case .debug:
IBGLog.logDebug(logString)
case .info, .uiEvent:
IBGLog.logInfo(logString)
case .warning:
IBGLog.logWarn(logString)
case .error:
IBGLog.logError(logString)
case .off:
return
default:
return
}
}

open override func stringValue(level: OktaLoggerLogLevel, eventName: String, message: String?, file: String, line: NSNumber, funcName: String) -> String {
let fileLogString = file.split(separator: "/").last ?? ""
let messageLogString: String = {
guard let message = message else {
return ""
}
return ". \(message)"
}()
return "\(eventName)\(messageLogString) | \(fileLogString):\(funcName):\(line)"
}
}
63 changes: 63 additions & 0 deletions OktaLoggerTests/OktaLoggerInstabugLoggerTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2021-Present, Okta, Inc. and/or its affiliates. All rights reserved.
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (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 XCTest
@testable import OktaLogger

class OktaLoggerInstabugLoggerTests: XCTestCase {

var instabugLogger: OktaLoggerInstabugLogger!

override func setUp() {
super.setUp()
instabugLogger = OktaLoggerInstabugLogger(
identifier: "instabug-logger",
level: .all,
defaultProperties: nil
)
}

func testStringValueMessageNotNil() {
let actualLog = instabugLogger.stringValue(
level: .info,
eventName: "Test event",
message: "Test message",
file: "OktaLoggerInstabugLoggerTests.swift",
line: 29,
funcName: "testStringValueMessageNotNil()"
)
XCTAssertEqual(actualLog, "Test event. Test message | OktaLoggerInstabugLoggerTests.swift:testStringValueMessageNotNil():29")
}

func testStringValueMessageNil() {
let actualLog = instabugLogger.stringValue(
level: .info,
eventName: "Test event",
message: nil,
file: "OktaLoggerInstabugLoggerTests.swift",
line: 29,
funcName: "testStringValueMessageNotNil()"
)
XCTAssertEqual(actualLog, "Test event | OktaLoggerInstabugLoggerTests.swift:testStringValueMessageNotNil():29")
}

func testStringValueNoFileName() {
let actualLog = instabugLogger.stringValue(
level: .info,
eventName: "Test event",
message: "Test message",
file: "",
line: 29,
funcName: "testStringValueMessageNotNil()"
)
XCTAssertEqual(actualLog, "Test event. Test message | :testStringValueMessageNotNil():29")
}
}
1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ target 'OktaLogger' do
pod 'AppCenter', '~>4.1.1'
pod 'Firebase/Crashlytics', '~>7.4.0'
pod 'CocoaLumberjack/Swift', '~>3.6.0'
pod 'Instabug', '~>10.7.5'
end

target 'OktaLoggerDemoApp' do
Expand Down
25 changes: 17 additions & 8 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,42 @@ PODS:
- GoogleUtilities/Environment
- GoogleUtilities/UserDefaults (7.2.2):
- GoogleUtilities/Logger
- Instabug (10.7.5)
- nanopb (2.30907.0):
- nanopb/decode (= 2.30907.0)
- nanopb/encode (= 2.30907.0)
- nanopb/decode (2.30907.0)
- nanopb/encode (2.30907.0)
- OktaLogger (1.2.2):
- OktaLogger/Complete (= 1.2.2)
- OktaLogger (1.3.0):
- OktaLogger/Complete (= 1.3.0)
- SwiftLint
- OktaLogger/Complete (1.2.2):
- OktaLogger/Complete (1.3.0):
- OktaLogger/FileLogger
- OktaLogger/FirebaseCrashlytics
- OktaLogger/InstabugLogger
- SwiftLint
- OktaLogger/Core (1.2.2):
- OktaLogger/Core (1.3.0):
- SwiftLint
- OktaLogger/FileLogger (1.2.2):
- OktaLogger/FileLogger (1.3.0):
- CocoaLumberjack/Swift (~> 3.6.0)
- OktaLogger/Core
- SwiftLint
- OktaLogger/FirebaseCrashlytics (1.2.2):
- OktaLogger/FirebaseCrashlytics (1.3.0):
- Firebase/Crashlytics (~> 7.4.0)
- OktaLogger/Core
- SwiftLint
- OktaLogger/InstabugLogger (1.3.0):
- Instabug (~> 10.7.5)
- OktaLogger/Core
- SwiftLint
- PromisesObjC (1.2.12)
- SwiftLint (0.39.2)

DEPENDENCIES:
- AppCenter (~> 4.1.1)
- CocoaLumberjack/Swift (~> 3.6.0)
- Firebase/Crashlytics (~> 7.4.0)
- Instabug (~> 10.7.5)
- OktaLogger (from `.`)

SPEC REPOS:
Expand All @@ -85,6 +92,7 @@ SPEC REPOS:
- FirebaseInstallations
- GoogleDataTransport
- GoogleUtilities
- Instabug
- nanopb
- PromisesObjC
- SwiftLint
Expand All @@ -103,11 +111,12 @@ SPEC CHECKSUMS:
FirebaseInstallations: a46ae59915f0931e18814164849cd0354bea24ed
GoogleDataTransport: 1024b1a4dfbd7a0e92cb20d7e0a6f1fb66b449a4
GoogleUtilities: 31c5b01f978a70c6cff2afc6272b3f1921614b43
Instabug: ec36344097cf86024029f5cf9dde858e6f9ab0ee
nanopb: 59221d7f958fb711001e6a449489542d92ae113e
OktaLogger: 43fd81691a7cdb69ef29997d7f2f218a1415d63b
OktaLogger: 93607a34f00c947c5ccce88e25140bb6a6e03256
PromisesObjC: 3113f7f76903778cf4a0586bd1ab89329a0b7b97
SwiftLint: 22ccbbe3b8008684be5955693bab135e0ed6a447

PODFILE CHECKSUM: 0d62d957d380013c75e13aeb32bd0c568a713007
PODFILE CHECKSUM: e599c7c788b36ecd9f8879e14a2c65fd02ff26b0

COCOAPODS: 1.10.1
Loading

0 comments on commit 9981650

Please sign in to comment.