From 384d5ed475b3113d534bddbc92e12462aebb71dc Mon Sep 17 00:00:00 2001 From: Ricardo Pereira Date: Sat, 15 Oct 2016 19:49:56 +0100 Subject: [PATCH] Example: add LogEntries lib --- .gitignore | 2 +- Example/Cartfile | 2 +- Example/Cartfile.resolved | 1 + .../WSLoggerExample.xcodeproj/project.pbxproj | 35 +++++++++++++++++++ Example/WSLoggerExample/AppDelegate.swift | 2 +- Example/WSLoggerExample/Logger.swift | 13 +++++-- Example/WSLoggerExample/ViewController.swift | 4 +-- Source/WSLogger.swift | 9 +++-- 8 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 Example/Cartfile.resolved diff --git a/.gitignore b/.gitignore index 3ecdd3b..6aa6088 100644 --- a/.gitignore +++ b/.gitignore @@ -54,7 +54,7 @@ Pods/ # Add this line if you want to avoid checking in source code from Carthage dependencies. # Carthage/Checkouts -Carthage/Build +Carthage # fastlane # diff --git a/Example/Cartfile b/Example/Cartfile index 727f7d3..9c8104d 100644 --- a/Example/Cartfile +++ b/Example/Cartfile @@ -1 +1 @@ -github "whitesmith/WSLogger" +github "LogentriesCommunity/le_ios" "master" diff --git a/Example/Cartfile.resolved b/Example/Cartfile.resolved new file mode 100644 index 0000000..d9bbaf5 --- /dev/null +++ b/Example/Cartfile.resolved @@ -0,0 +1 @@ +github "LogentriesCommunity/le_ios" "d66e4ec18d45d9b8adfde91e5230f15718f96767" diff --git a/Example/WSLoggerExample.xcodeproj/project.pbxproj b/Example/WSLoggerExample.xcodeproj/project.pbxproj index c333020..939ef1c 100644 --- a/Example/WSLoggerExample.xcodeproj/project.pbxproj +++ b/Example/WSLoggerExample.xcodeproj/project.pbxproj @@ -166,6 +166,7 @@ D7D35E781DB228BF005CD7E9 /* Frameworks */, D7D35E791DB228BF005CD7E9 /* Resources */, D7D35E9E1DB22A63005CD7E9 /* Embed Frameworks */, + D73F32481DB2A90F00E7DBF4 /* Carthage */, ); buildRules = ( ); @@ -276,6 +277,24 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + D73F32481DB2A90F00E7DBF4 /* Carthage */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "$(SRCROOT)/Carthage/Build/iOS/lelib.framework", + ); + name = Carthage; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/usr/local/bin/carthage copy-frameworks"; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ D7D35E771DB228BF005CD7E9 /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -420,6 +439,10 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); INFOPLIST_FILE = WSLoggerExample/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = co.whitesmith.WSLoggerExample; @@ -435,6 +458,10 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); INFOPLIST_FILE = WSLoggerExample/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = co.whitesmith.WSLoggerExample; @@ -447,6 +474,10 @@ isa = XCBuildConfiguration; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); INFOPLIST_FILE = WSLoggerExampleTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = co.whitesmith.WSLoggerExampleTests; @@ -459,6 +490,10 @@ isa = XCBuildConfiguration; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); INFOPLIST_FILE = WSLoggerExampleTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = co.whitesmith.WSLoggerExampleTests; diff --git a/Example/WSLoggerExample/AppDelegate.swift b/Example/WSLoggerExample/AppDelegate.swift index 4899e22..ec39e1a 100644 --- a/Example/WSLoggerExample/AppDelegate.swift +++ b/Example/WSLoggerExample/AppDelegate.swift @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { - // Override point for customization after application launch. + loggerSetup() return true } diff --git a/Example/WSLoggerExample/Logger.swift b/Example/WSLoggerExample/Logger.swift index 84d8e2f..f87595c 100644 --- a/Example/WSLoggerExample/Logger.swift +++ b/Example/WSLoggerExample/Logger.swift @@ -8,13 +8,22 @@ import Foundation import WSLogger +import lelib + +func loggerSetup() { + LoggerOptions.defaultLevel = .Debug + WSLogger.shared.traceFile = true + WSLogger.shared.traceMethod = true + // LogEntries + LELog.sharedInstance().token = "XXXX-XXX-XXX-XXXX" +} extension WSLoggable { func log(message: String, level: WSLogLevel = .Debug, customAttributes: [String : AnyObject]? = nil, fileName: NSString = #file, line: Int = #line, function: String = #function) { // Log internally - WSLogger.shared.log(message, level: level, customAttributes: customAttributes, className: String(self.dynamicType), fileName: fileName, line: line, function: function) + let text = WSLogger.shared.log(message, level: level, customAttributes: customAttributes, className: String(self.dynamicType), fileName: fileName, line: line, function: function) // Log remotely - // Fabric ?! + LELog.sharedInstance().log(text) } } diff --git a/Example/WSLoggerExample/ViewController.swift b/Example/WSLoggerExample/ViewController.swift index efec258..d70e91b 100644 --- a/Example/WSLoggerExample/ViewController.swift +++ b/Example/WSLoggerExample/ViewController.swift @@ -8,11 +8,11 @@ import UIKit -class ViewController: UIViewController { +class ViewController: UIViewController, Loggable { override func viewDidLoad() { super.viewDidLoad() - + log("Test from WSLogger") } } diff --git a/Source/WSLogger.swift b/Source/WSLogger.swift index e7ffcdd..0a7f182 100644 --- a/Source/WSLogger.swift +++ b/Source/WSLogger.swift @@ -33,9 +33,10 @@ final public class WSLogger { } /// Log locally - public func log(message: String, level: WSLogLevel = .Debug, customAttributes: [String:AnyObject]? = nil, className: String = "", fileName: NSString = #file, line: Int = #line, function: String = #function) { + public func log(message: String, level: WSLogLevel = .Debug, customAttributes: [String:AnyObject]? = nil, className: String = "", fileName: NSString = #file, line: Int = #line, function: String = #function) -> String { assert(level != .None) - guard logAllowed(level, className: className) else { return } + guard logAllowed(level, className: className) else { return "" } + var traceInfo = "" if traceFile { traceInfo += fileName.lastPathComponent + ":" + String(line) + " " @@ -44,7 +45,9 @@ final public class WSLogger { traceInfo += className.isEmpty ? function : className + "." + function traceInfo += " " } - printable.print("\(traceInfo)\(String.init(level).uppercaseString) \"\(message)\" [\(customAttributes)]") + let text = "\(traceInfo)\(String.init(level).uppercaseString) \"\(message)\" [\(customAttributes)]" + printable.print(text) + return text } /// Reset logger settings.