Skip to content

Commit

Permalink
Merge pull request #15 from giginet/4.0.0-for-merge
Browse files Browse the repository at this point in the history
4.0.0
  • Loading branch information
giginet authored Oct 31, 2018
2 parents bf00a6a + 8032258 commit 0477970
Show file tree
Hide file tree
Showing 12 changed files with 553 additions and 201 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.2
4.2
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
os: osx
osx_image: xcode9.2
osx_image: xcode10
language: objective-c
before_script:
- swiftlint --strict
- pod lib lint
matrix:
include:
- env: NAME=Xcode DESTINATION="platform=iOS Simulator,name=iPhone 8"
- env: NAME=Xcode DESTINATION="platform=iOS Simulator,OS=9.0,name=iPhone 4s"
script:
- xcodebuild test -project Puree.xcodeproj -scheme PureeTests -destination "${DESTINATION}"
4 changes: 2 additions & 2 deletions Puree.podspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Pod::Spec.new do |s|
s.name = "Puree"
s.version = "3.3.0"
s.version = "4.0.0"
s.summary = "Awesome log aggregator"
s.homepage = "https://github.com/cookpad/Puree-Swift"
s.license = { :type => "MIT", :file => "LICENSE" }
s.authors = { "Tomohiro Moro" => "[email protected]", "Kohki Miki" => "[email protected]", "Vincent Isambart" => "[email protected]" }
s.platform = :ios, "9.0"
s.platform = :ios, "10.0"
s.source = { :git => "https://github.com/cookpad/Puree-Swift.git", :tag => "#{s.version}" }
s.source_files = "Sources/**/*.{h,swift}"
end
48 changes: 38 additions & 10 deletions Puree.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
83E040602105E69F00B92093 /* TestingBuffer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83E0405E2105E68C00B92093 /* TestingBuffer.swift */; };
BF_104851505209 /* InMemoryLogStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_613975198094 /* InMemoryLogStore.swift */; };
BF_180232540354 /* Output.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_848196260343 /* Output.swift */; };
BF_198816004411 /* TestingBuffer.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_869531157922 /* TestingBuffer.swift */; };
BF_210674583290 /* Filter.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_176166977065 /* Filter.swift */; };
BF_219592565366 /* Puree.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FR_479946421258 /* Puree.framework */; };
BF_278872148905 /* Puree.h in Headers */ = {isa = PBXBuildFile; fileRef = FR_793364177672 /* Puree.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -38,12 +38,13 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
83E0405E2105E68C00B92093 /* TestingBuffer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestingBuffer.swift; sourceTree = "<group>"; };
FR_135157311129 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
FR_167045655688 /* LogEntryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogEntryTests.swift; sourceTree = "<group>"; };
FR_176166977065 /* Filter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Filter.swift; sourceTree = "<group>"; };
FR_254889461063 /* BufferedOutput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BufferedOutput.swift; sourceTree = "<group>"; };
FR_272688927660 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
FR_412093004181 /* PureeTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = PureeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
FR_412093004181 /* PureeTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PureeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
FR_479946421258 /* Puree.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Puree.framework; sourceTree = BUILT_PRODUCTS_DIR; };
FR_613975198094 /* InMemoryLogStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InMemoryLogStore.swift; sourceTree = "<group>"; };
FR_630835297098 /* BufferedOutputTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BufferedOutputTests.swift; sourceTree = "<group>"; };
Expand All @@ -56,7 +57,6 @@
FR_818352195712 /* LogStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogStore.swift; sourceTree = "<group>"; };
FR_828954093903 /* DateProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateProvider.swift; sourceTree = "<group>"; };
FR_848196260343 /* Output.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Output.swift; sourceTree = "<group>"; };
FR_869531157922 /* TestingBuffer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestingBuffer.swift; sourceTree = "<group>"; };
FR_870064055253 /* TagPatternTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagPatternTests.swift; sourceTree = "<group>"; };
FR_912035359082 /* LogEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogEntry.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand All @@ -73,6 +73,23 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
83935AC520F88CA800FA8B9A /* Output */ = {
isa = PBXGroup;
children = (
FR_254889461063 /* BufferedOutput.swift */,
FR_848196260343 /* Output.swift */,
);
path = Output;
sourceTree = "<group>";
};
83935AC620F8920500FA8B9A /* Output */ = {
isa = PBXGroup;
children = (
FR_630835297098 /* BufferedOutputTests.swift */,
);
path = Output;
sourceTree = "<group>";
};
G_1203410589804 /* LogStore */ = {
isa = PBXGroup;
children = (
Expand All @@ -85,11 +102,11 @@
G_2671118715628 /* PureeTests */ = {
isa = PBXGroup;
children = (
FR_630835297098 /* BufferedOutputTests.swift */,
FR_135157311129 /* Info.plist */,
FR_167045655688 /* LogEntryTests.swift */,
FR_657386344080 /* LoggerTests.swift */,
G_7185892225853 /* LogStore */,
83935AC620F8920500FA8B9A /* Output */,
FR_870064055253 /* TagPatternTests.swift */,
G_6662760494323 /* Utilities */,
);
Expand All @@ -108,13 +125,12 @@
G_3400314782399 /* Puree */ = {
isa = PBXGroup;
children = (
FR_254889461063 /* BufferedOutput.swift */,
FR_176166977065 /* Filter.swift */,
FR_272688927660 /* Info.plist */,
FR_912035359082 /* LogEntry.swift */,
FR_775709644702 /* Logger.swift */,
G_1203410589804 /* LogStore */,
FR_848196260343 /* Output.swift */,
83935AC520F88CA800FA8B9A /* Output */,
FR_793364177672 /* Puree.h */,
FR_644801390644 /* TagPattern.swift */,
G_3356739590045 /* Utilities */,
Expand All @@ -127,7 +143,7 @@
isa = PBXGroup;
children = (
FR_613975198094 /* InMemoryLogStore.swift */,
FR_869531157922 /* TestingBuffer.swift */,
83E0405E2105E68C00B92093 /* TestingBuffer.swift */,
);
path = Utilities;
sourceTree = "<group>";
Expand Down Expand Up @@ -212,6 +228,14 @@
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0940;
TargetAttributes = {
NT_412093004181 = {
LastSwiftMigration = 1000;
};
NT_479946421258 = {
LastSwiftMigration = 1000;
};
};
};
buildConfigurationList = CL_479946421258 /* Build configuration list for PBXProject "Puree" */;
compatibilityVersion = "Xcode 3.2";
Expand Down Expand Up @@ -239,9 +263,9 @@
BF_364947189323 /* FileLogStoreTests.swift in Sources */,
BF_104851505209 /* InMemoryLogStore.swift in Sources */,
BF_647931598633 /* LogEntryTests.swift in Sources */,
83E040602105E69F00B92093 /* TestingBuffer.swift in Sources */,
BF_859683188258 /* LoggerTests.swift in Sources */,
BF_595409884047 /* TagPatternTests.swift in Sources */,
BF_198816004411 /* TestingBuffer.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -281,6 +305,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
SDKROOT = iphoneos;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -298,11 +323,12 @@
ENABLE_TESTABILITY = YES;
INFOPLIST_FILE = Sources/Puree/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.cookpad.Puree;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
};
Expand Down Expand Up @@ -379,11 +405,12 @@
ENABLE_TESTABILITY = YES;
INFOPLIST_FILE = Sources/Puree/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.cookpad.Puree;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
};
Expand All @@ -398,6 +425,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
SDKROOT = iphoneos;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
![](Documentation/logo.png)

[![Build Status](https://travis-ci.org/cookpad/Puree-Swift.svg?branch=master)](https://travis-ci.org/cookpad/Puree-Swift)
[![Language](https://img.shields.io/badge/language-Swift%204.0.2-orange.svg)](https://swift.org)
[![Language](https://img.shields.io/badge/language-Swift%204.2-orange.svg)](https://swift.org)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/Puree.svg)](http://cocoadocs.org/docsets/Puree)
[![Platform](https://img.shields.io/cocoapods/p/Puree.svg?style=flat)](http://cocoadocs.org/docsets/Puree)
Expand Down Expand Up @@ -37,7 +37,7 @@ github "cookpad/Puree-Swift"
```ruby
use_frameworks!

pod 'Puree', '~> 3.0'
pod 'Puree', '~> 4.0'
```

## Usage
Expand Down
45 changes: 28 additions & 17 deletions Sources/Puree/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,42 @@ public final class Logger {
}

private let configuration: Configuration
private let dispatchQueue = DispatchQueue(label: "com.cookpad.Puree.Logger", qos: .background)
private(set) var filters: [Filter] = []
private(set) var outputs: [Output] = []

public var currentDate: Date {
return configuration.dateProvider.now
}

var logStore: LogStore {
return configuration.logStore
}

public init(configuration: Configuration) throws {
self.configuration = configuration

try configuration.logStore.prepare()
try configureFilterPlugins()
try configureOutputPlugins()

outputs.forEach { $0.start() }
start()
}

private func configureFilterPlugins() throws {
filters = try configuration.filterSettings.map { try $0.makeFilter() }
}

private func configureOutputPlugins() throws {
outputs = try configuration.outputSettings.map { try $0.makeOutput(logStore) }
outputs = try configuration.outputSettings.map { try $0.makeOutput(configuration.logStore) }
}

public func postLog(_ payload: [String: Any]?, tag: String) {
func matchesOutputs(with tag: String) -> [Output] {
return outputs.filter { $0.tagPattern.match(in: tag) != nil }
}
dispatchQueue.async {
func matchesOutputs(with tag: String) -> [Output] {
return self.outputs.filter { $0.tagPattern.match(in: tag) != nil }
}

for log in filteredLogs(with: payload, tag: tag) {
for output in matchesOutputs(with: tag) {
output.emit(log: log)
for log in self.filteredLogs(with: payload, tag: tag) {
for output in matchesOutputs(with: tag) {
output.emit(log: log)
}
}
}
}
Expand All @@ -74,18 +73,30 @@ public final class Logger {
return logs
}

private func start() {
dispatchQueue.async {
self.outputs.forEach { $0.start() }
}
}

public func suspend() {
outputs.forEach { $0.suspend() }
dispatchQueue.sync {
outputs.forEach { $0.suspend() }
}
}

public func resume() {
outputs.forEach { $0.resume() }
dispatchQueue.async {
self.outputs.forEach { $0.resume() }
}
}

public func shutdown() {
filters.removeAll()
suspend()
outputs.removeAll()
dispatchQueue.sync {
filters.removeAll()
outputs.forEach { $0.suspend() }
outputs.removeAll()
}
}

deinit {
Expand Down
Loading

0 comments on commit 0477970

Please sign in to comment.