Skip to content

Commit

Permalink
Example: add LogEntries lib
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardopereira committed Oct 15, 2016
1 parent 088f678 commit 384d5ed
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
2 changes: 1 addition & 1 deletion Example/Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "whitesmith/WSLogger"
github "LogentriesCommunity/le_ios" "master"
1 change: 1 addition & 0 deletions Example/Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github "LogentriesCommunity/le_ios" "d66e4ec18d45d9b8adfde91e5230f15718f96767"
35 changes: 35 additions & 0 deletions Example/WSLoggerExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
D7D35E781DB228BF005CD7E9 /* Frameworks */,
D7D35E791DB228BF005CD7E9 /* Resources */,
D7D35E9E1DB22A63005CD7E9 /* Embed Frameworks */,
D73F32481DB2A90F00E7DBF4 /* Carthage */,
);
buildRules = (
);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Example/WSLoggerExample/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
13 changes: 11 additions & 2 deletions Example/WSLoggerExample/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions Example/WSLoggerExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

import UIKit

class ViewController: UIViewController {
class ViewController: UIViewController, Loggable {

override func viewDidLoad() {
super.viewDidLoad()

log("Test from WSLogger")
}

}
9 changes: 6 additions & 3 deletions Source/WSLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) + " "
Expand All @@ -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.
Expand Down

0 comments on commit 384d5ed

Please sign in to comment.