Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Commit

Permalink
Upgraded to Swift 3 (Xcode 8 beta 6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouke authored and nilsvu committed Oct 2, 2016
1 parent 4b810e6 commit 7e708ae
Show file tree
Hide file tree
Showing 8 changed files with 306 additions and 295 deletions.
59 changes: 35 additions & 24 deletions Evergreen.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
87189B931CB325A200EB3284 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87189B831CB325A200EB3284 /* Logger.swift */; };
87515FDD1CB2BBA100E0120D /* Evergreen.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 87515FD31CB2BBA100E0120D /* Evergreen.framework */; };
875160001CB2BEC500E0120D /* Evergreen.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 87515FF61CB2BEC500E0120D /* Evergreen.framework */; };
875160281CB2C12F00E0120D /* LoggerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 875160251CB2C12F00E0120D /* LoggerTests.swift */; };
875160291CB2C12F00E0120D /* LoggerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 875160251CB2C12F00E0120D /* LoggerTests.swift */; };
8751602A1CB2C12F00E0120D /* LoggerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 875160251CB2C12F00E0120D /* LoggerTests.swift */; };
8751602B1CB2C12F00E0120D /* LoggingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 875160261CB2C12F00E0120D /* LoggingTests.swift */; };
8751602C1CB2C12F00E0120D /* LoggingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 875160261CB2C12F00E0120D /* LoggingTests.swift */; };
8751602D1CB2C12F00E0120D /* LoggingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 875160261CB2C12F00E0120D /* LoggingTests.swift */; };
8751602E1CB2C12F00E0120D /* StenographyTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 875160271CB2C12F00E0120D /* StenographyTestCase.swift */; };
8751602F1CB2C12F00E0120D /* StenographyTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 875160271CB2C12F00E0120D /* StenographyTestCase.swift */; };
875160301CB2C12F00E0120D /* StenographyTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 875160271CB2C12F00E0120D /* StenographyTestCase.swift */; };
D5C1AA6D1D701E3F0015363F /* LoggerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C1AA6A1D701E3F0015363F /* LoggerTests.swift */; };
D5C1AA6E1D701E3F0015363F /* LoggerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C1AA6A1D701E3F0015363F /* LoggerTests.swift */; };
D5C1AA6F1D701E3F0015363F /* LoggerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C1AA6A1D701E3F0015363F /* LoggerTests.swift */; };
D5C1AA701D701E3F0015363F /* LoggingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C1AA6B1D701E3F0015363F /* LoggingTests.swift */; };
D5C1AA711D701E3F0015363F /* LoggingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C1AA6B1D701E3F0015363F /* LoggingTests.swift */; };
D5C1AA721D701E3F0015363F /* LoggingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C1AA6B1D701E3F0015363F /* LoggingTests.swift */; };
D5C1AA731D701E3F0015363F /* StenographyTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C1AA6C1D701E3F0015363F /* StenographyTestCase.swift */; };
D5C1AA741D701E3F0015363F /* StenographyTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C1AA6C1D701E3F0015363F /* StenographyTestCase.swift */; };
D5C1AA751D701E3F0015363F /* StenographyTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C1AA6C1D701E3F0015363F /* StenographyTestCase.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -70,11 +70,11 @@
87515FF61CB2BEC500E0120D /* Evergreen.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Evergreen.framework; sourceTree = BUILT_PRODUCTS_DIR; };
87515FFF1CB2BEC500E0120D /* Evergreen-tvOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Evergreen-tvOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
875160121CB2C00C00E0120D /* Evergreen.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Evergreen.framework; sourceTree = BUILT_PRODUCTS_DIR; };
875160251CB2C12F00E0120D /* LoggerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LoggerTests.swift; path = Tests/Evergreen/LoggerTests.swift; sourceTree = SOURCE_ROOT; };
875160261CB2C12F00E0120D /* LoggingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LoggingTests.swift; path = Tests/Evergreen/LoggingTests.swift; sourceTree = SOURCE_ROOT; };
875160271CB2C12F00E0120D /* StenographyTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = StenographyTestCase.swift; path = Tests/Evergreen/StenographyTestCase.swift; sourceTree = SOURCE_ROOT; };
87539B1F19DB23F00084658D /* Evergreen.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Evergreen.framework; sourceTree = BUILT_PRODUCTS_DIR; };
87539B2A19DB23F00084658D /* Evergreen-iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Evergreen-iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
D5C1AA6A1D701E3F0015363F /* LoggerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LoggerTests.swift; path = Tests/EvergreenTests/LoggerTests.swift; sourceTree = SOURCE_ROOT; };
D5C1AA6B1D701E3F0015363F /* LoggingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LoggingTests.swift; path = Tests/EvergreenTests/LoggingTests.swift; sourceTree = SOURCE_ROOT; };
D5C1AA6C1D701E3F0015363F /* StenographyTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = StenographyTestCase.swift; path = Tests/EvergreenTests/StenographyTestCase.swift; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -170,9 +170,9 @@
87539B2B19DB23F00084658D /* EvergreenTests */ = {
isa = PBXGroup;
children = (
875160251CB2C12F00E0120D /* LoggerTests.swift */,
875160261CB2C12F00E0120D /* LoggingTests.swift */,
875160271CB2C12F00E0120D /* StenographyTestCase.swift */,
D5C1AA6A1D701E3F0015363F /* LoggerTests.swift */,
D5C1AA6B1D701E3F0015363F /* LoggingTests.swift */,
D5C1AA6C1D701E3F0015363F /* StenographyTestCase.swift */,
);
name = EvergreenTests;
path = VILogKitTests;
Expand Down Expand Up @@ -358,12 +358,14 @@
};
87515FDB1CB2BBA100E0120D = {
CreatedOnToolsVersion = 7.3;
LastSwiftMigration = 0800;
};
87515FF51CB2BEC500E0120D = {
CreatedOnToolsVersion = 7.3;
};
87515FFE1CB2BEC500E0120D = {
CreatedOnToolsVersion = 7.3;
LastSwiftMigration = 0800;
};
875160111CB2C00C00E0120D = {
CreatedOnToolsVersion = 7.3;
Expand All @@ -373,6 +375,7 @@
};
87539B2919DB23F00084658D = {
CreatedOnToolsVersion = 6.0.1;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -466,9 +469,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
875160291CB2C12F00E0120D /* LoggerTests.swift in Sources */,
8751602F1CB2C12F00E0120D /* StenographyTestCase.swift in Sources */,
8751602C1CB2C12F00E0120D /* LoggingTests.swift in Sources */,
D5C1AA6E1D701E3F0015363F /* LoggerTests.swift in Sources */,
D5C1AA741D701E3F0015363F /* StenographyTestCase.swift in Sources */,
D5C1AA711D701E3F0015363F /* LoggingTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -486,9 +489,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8751602A1CB2C12F00E0120D /* LoggerTests.swift in Sources */,
875160301CB2C12F00E0120D /* StenographyTestCase.swift in Sources */,
8751602D1CB2C12F00E0120D /* LoggingTests.swift in Sources */,
D5C1AA6F1D701E3F0015363F /* LoggerTests.swift in Sources */,
D5C1AA751D701E3F0015363F /* StenographyTestCase.swift in Sources */,
D5C1AA721D701E3F0015363F /* LoggingTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -516,9 +519,9 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
875160281CB2C12F00E0120D /* LoggerTests.swift in Sources */,
8751602E1CB2C12F00E0120D /* StenographyTestCase.swift in Sources */,
8751602B1CB2C12F00E0120D /* LoggingTests.swift in Sources */,
D5C1AA6D1D701E3F0015363F /* LoggerTests.swift in Sources */,
D5C1AA731D701E3F0015363F /* StenographyTestCase.swift in Sources */,
D5C1AA701D701E3F0015363F /* LoggingTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -614,6 +617,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -634,6 +638,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.11;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down Expand Up @@ -701,6 +706,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TVOS_DEPLOYMENT_TARGET = 9.2;
};
name = Debug;
Expand All @@ -719,6 +725,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
SWIFT_VERSION = 3.0;
TVOS_DEPLOYMENT_TARGET = 9.2;
};
name = Release;
Expand Down Expand Up @@ -817,6 +824,7 @@
PRODUCT_NAME = Evergreen;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -856,6 +864,7 @@
PRODUCT_MODULE_NAME = "$(PRODUCT_NAME:c99extidentifier)";
PRODUCT_NAME = Evergreen;
SDKROOT = iphoneos;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -909,6 +918,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -922,6 +932,7 @@
);
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ As usual with CocoaPods, make sure to use the `*.xcworkspace` instead of the `*.

### Swift Package Manager (currently in beta)

You can also use the Swift Package Manager included in the [Swift 2.2 beta](https://swift.org/download/). Just add Evergreen as a dependency to your package description, like this:
You can also use the Swift Package Manager included in the [Xcode 8 beta 6](https://developer.apple.com/xcode). Just add Evergreen as a dependency to your package description, like this:

```swift
import PackageDescription
Expand Down
76 changes: 38 additions & 38 deletions Sources/Evergreen/Formatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,76 +10,76 @@ import Foundation


public class Formatter {

public let components: [Component]

public init(components: [Component]) {
self.components = components
}

public enum Style {
case Default, Simple, Full
case `default`, simple, full
}

/// Creates a formatter from any of the predefined styles.
public convenience init(style: Style) {
let components: [Component]
switch style {
case .Default:
components = [ .Text("["), .Logger, .Text("|"), .LogLevel, .Text("] "), .Message ]
case .Simple:
components = [ .Message ]
case .Full:
let dateFormatter = NSDateFormatter()
case .default:
components = [ .text("["), .logger, .text("|"), .logLevel, .text("] "), .message ]
case .simple:
components = [ .message ]
case .full:
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS"
components = [ .Date(formatter: dateFormatter), .Text(" ["), .Logger, .Text("|"), .LogLevel, .Text("] "), .Message ]
components = [ .date(formatter: dateFormatter), .text(" ["), .logger, .text("|"), .logLevel, .text("] "), .message ]
}
self.init(components: components)
}

public enum Component {
case Text(String), Date(formatter: NSDateFormatter), Logger, LogLevel, Message, Function, File, Line//, Any(stringForEvent: (event: Event<M>) -> String)
public func stringForEvent<M>(event: Event<M>) -> String {
case text(String), date(formatter: DateFormatter), logger, logLevel, message, function, file, line//, Any(stringForEvent: (event: Event<M>) -> String)

public func stringForEvent<M>(_ event: Event<M>) -> String {
switch self {
case .Text(let text):
case .text(let text):
return text
case .Date(let formatter):
return formatter.stringFromDate(event.date)
case .Logger:
case .date(let formatter):
return formatter.string(from: event.date as Date)
case .logger:
return event.logger.description
case .LogLevel:
return (event.logLevel?.description ?? "Unspecified").uppercaseString
case .Message:
case .logLevel:
return (event.logLevel?.description ?? "Unspecified").uppercased()
case .message:
switch event.message() {
case let error as NSError:
return error.localizedDescription
case let message:
return String(message)
return String(describing: message)
}
case .Function:
case .function:
return event.function
case .File:
case .file:
return event.file
case .Line:
case .line:
return String(event.line)
}
}
}

/// Produces a record from a given event. The record can be subsequently emitted by a handler.
public final func recordFromEvent<M>(event: Event<M>) -> Record {
public final func recordFromEvent<M>(_ event: Event<M>) -> Record {
return Record(date: event.date, logLevel: event.logLevel, description: self.stringFromEvent(event))
}
public func stringFromEvent<M>(event: Event<M>) -> String

public func stringFromEvent<M>(_ event: Event<M>) -> String
{
var string = components.map({ $0.stringForEvent(event) }).joinWithSeparator("")
var string = components.map({ $0.stringForEvent(event) }).joined(separator: "")

if let elapsedTime = event.elapsedTime {
string += " [ELAPSED TIME: \(elapsedTime)s]"
}

if let error = event.error {
let errorMessage: String
switch error {
Expand All @@ -88,16 +88,16 @@ public class Formatter {
case let error as CustomStringConvertible:
errorMessage = error.description
default:
errorMessage = String(error)
errorMessage = String(describing: error)
}
string += " [ERROR: \(errorMessage)]"
}

if event.once {
string += " [ONLY LOGGED ONCE]"
}

return string
}

}
Loading

0 comments on commit 7e708ae

Please sign in to comment.