-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore(swift): init * chore(swift): plugin done * chore: make class, variables and plugin getter public * chore: log level enum represent int * chore: test asserted * chore: podspec points to main * chore(swift): add ci
- Loading branch information
Showing
12 changed files
with
285 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: logger-swift-ci | ||
|
||
on: | ||
pull_request: | ||
types: [closed] | ||
branches: | ||
- main | ||
paths: | ||
- "logger/implementations/swift/**" | ||
|
||
jobs: | ||
ci: | ||
name: swift-logger-ci | ||
runs-on: macos-latest | ||
timeout-minutes: 60 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Build Pod | ||
run: pod spec lint --allow-warnings --verbose | ||
|
||
- name: Build Package | ||
run: swift build | ||
working-directory: ./logger/implementations/swift | ||
|
||
- name: Run Tests | ||
run: swift test | ||
working-directory: ./logger/implementations/swift |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Pod::Spec.new do |s| | ||
s.name = 'LoggerPlugin' | ||
s.version = '0.0.1' | ||
s.summary = 'Logger plugin' | ||
s.homepage = 'https://github.com/polywrap/logging' | ||
s.license = 'MIT' | ||
s.author = { 'Cesar' => '[email protected]' } | ||
|
||
s.source_files = 'logger/implementations/swift/Source/**/*.swift' | ||
s.swift_version = "5.0" | ||
s.ios.deployment_target = '14.0' | ||
s.source = { :git => "https://github.com/polywrap/logging.git", :branch => 'main' } | ||
s.static_framework = true | ||
s.dependency 'PolywrapClient', '~> 0.0.7' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/config/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc | ||
!Source/wrap | ||
node_modules | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"pins" : [ | ||
{ | ||
"identity" : "asyncobjects", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/SwiftyLab/AsyncObjects.git", | ||
"state" : { | ||
"revision" : "93aacfba87d738ac94fb50c2a6768c43ec9d42eb", | ||
"version" : "2.1.0" | ||
} | ||
}, | ||
{ | ||
"identity" : "messagepacker", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/hirotakan/MessagePacker.git", | ||
"state" : { | ||
"revision" : "4d8346c6bc579347e4df0429493760691c5aeca2", | ||
"version" : "0.4.7" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-client", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/polywrap/swift-client", | ||
"state" : { | ||
"branch" : "main", | ||
"revision" : "488ecdb35461ba38de5bb9144ca2b37609c75caa" | ||
} | ||
}, | ||
{ | ||
"identity" : "swift-collections", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-collections.git", | ||
"state" : { | ||
"revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2", | ||
"version" : "1.0.4" | ||
} | ||
} | ||
], | ||
"version" : 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// swift-tools-version: 5.7 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "LoggerPlugin", | ||
platforms: [.iOS(.v15), .macOS(.v11)], | ||
products: [ | ||
// Products define the executables and libraries a package produces, and make them visible to other packages. | ||
.library( | ||
name: "LoggerPlugin", | ||
targets: ["LoggerPlugin"]), | ||
], | ||
dependencies: [ | ||
// Dependencies declare other packages that this package depends on. | ||
// .package(url: /* package url */, from: "1.0.0"), | ||
.package(url: "https://github.com/polywrap/swift-client", branch: "main"), | ||
], | ||
targets: [ | ||
// Targets are the basic building blocks of a package. A target can define a module or a test suite. | ||
// Targets can depend on other targets in this package, and on products in packages this package depends on. | ||
.target( | ||
name: "LoggerPlugin", | ||
dependencies: [ | ||
.product(name: "PolywrapClient", package: "swift-client"), | ||
], | ||
path: "Source" | ||
), | ||
.testTarget( | ||
name: "LoggerPluginTests", | ||
dependencies: ["LoggerPlugin"], | ||
path: "Tests" | ||
), | ||
], | ||
swiftLanguageVersions: [.v5] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import OSLog | ||
import PolywrapClient | ||
|
||
public typealias LogFunc = (LogLevel, String) -> Void | ||
|
||
extension Logger { | ||
/// Using your bundle identifier is a great way to ensure a unique identifier. | ||
private static var subsystem = Bundle.main.bundleIdentifier! | ||
|
||
/// Logs the view cycles like a view that appeared. | ||
static let viewCycle = Logger(subsystem: subsystem, category: "viewcycle") | ||
|
||
/// All logs related to tracking and analytics. | ||
static let statistics = Logger(subsystem: subsystem, category: "statistics") | ||
} | ||
|
||
public class LoggerPlugin: Plugin { | ||
public var methodsMap: [String : PluginMethod] = [:] | ||
public let config: LogFunc? | ||
|
||
public init(config: LogFunc?) { | ||
self.config = config | ||
} | ||
|
||
public func log(_ args: ArgsLog, _ env: VoidCodable?, _ invoker: Invoker) -> Bool { | ||
if let logFunc = config { | ||
logFunc(args.level, args.message) | ||
return true | ||
} | ||
|
||
switch args.level { | ||
case .DEBUG: | ||
Logger.viewCycle.debug("\(args.message)") | ||
case .WARN: | ||
Logger.viewCycle.warning("\(args.message)") | ||
case .ERROR: | ||
Logger.viewCycle.error("\(args.message)") | ||
case .INFO: | ||
Logger.viewCycle.info("\(args.message)") | ||
} | ||
|
||
return true | ||
} | ||
} | ||
|
||
public func getLoggerPlugin(_ logFunc: LogFunc?) -> LoggerPlugin { | ||
var plugin = LoggerPlugin(config: logFunc) | ||
plugin.addMethod(name: "log", closure: plugin.log) | ||
return plugin | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// NOTE: This is an auto-generated file. | ||
// All modifications will be overwritten. | ||
|
||
import PolywrapClient | ||
import Foundation | ||
|
||
public struct ArgsLog: Codable { | ||
var level: LogLevel | ||
var message: String | ||
} | ||
|
||
|
||
public protocol Plugin: PluginModule { | ||
func log(_ args: ArgsLog, _ env: VoidCodable?, _ invoker: Invoker) throws -> Bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// NOTE: This is an auto-generated file. | ||
// All modifications will be overwritten. | ||
|
||
import PolywrapClient | ||
import Foundation | ||
|
||
// Env START // | ||
|
||
|
||
// Env END // | ||
|
||
// Objects START // | ||
|
||
|
||
// Objects END // | ||
|
||
// Enums START // | ||
|
||
public enum LogLevel: Int, Codable { | ||
case DEBUG = 0 | ||
case INFO | ||
case WARN | ||
case ERROR | ||
} | ||
|
||
|
||
// Enums END // | ||
|
||
// Imported objects START // | ||
|
||
|
||
// Imported objects END // | ||
|
||
// Imported envs START // | ||
|
||
|
||
// Imported envs END // | ||
|
||
// Imported enums START // | ||
|
||
|
||
// Imported enums END // | ||
|
||
// Imported modules START // | ||
|
||
// Imported Modules END // |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import XCTest | ||
@testable import LoggerPlugin | ||
@testable import PolywrapClient | ||
|
||
|
||
func getClient() throws -> (PolywrapClient, Uri) { | ||
let uri = try Uri("plugin/logger") | ||
let loggerPlugin = getLoggerPlugin(nil) | ||
let package = PluginPackage(loggerPlugin) | ||
let builder = BuilderConfig().addPackage(uri, package) | ||
return (builder.build(), uri) | ||
} | ||
|
||
final class LoggerPluginTests: XCTestCase { | ||
func testLog() throws { | ||
let (client, uri) = try getClient() | ||
let args = ArgsLog(level: LogLevel.INFO, message: "Hallo!") | ||
|
||
let response: Bool = try client.invoke(uri: uri, method: "log", args: args) | ||
XCTAssert(response) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "@polywrap/logger-swift", | ||
"description": "Polywrap Logger Plugin in swift", | ||
"scripts": { | ||
"codegen": "polywrap codegen -g ./Source/wrap" | ||
}, | ||
"devDependencies": { | ||
"polywrap": "0.11.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#import * from "wrapscan.io/polywrap/[email protected]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
format: 0.3.0 | ||
project: | ||
type: plugin/swift | ||
name: Logger | ||
source: | ||
module: ./Package.swift | ||
schema: ./polywrap.graphql |