Skip to content

Commit

Permalink
Remove concurrency features (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
sushichop authored Feb 12, 2022
1 parent 182de01 commit ad5297a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 67 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [x.y.z](https://github.com/sushichop/Puppy/releases/tag/x.y.z) (yyyy-mm-dd)

- Remove concurrency features. [#39](https://github.com/sushichop/Puppy/pull/39)

## [0.4.0](https://github.com/sushichop/Puppy/releases/tag/0.4.0) (2022-01-31)

- `FileRotatonLogger` inherits `FileLogger`. [#29](https://github.com/sushichop/Puppy/pull/29)
Expand Down
27 changes: 0 additions & 27 deletions Sources/Puppy/FileLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,6 @@ public class FileLogger: BaseLogger {
}
}

#if compiler(>=5.5.2)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public func delete(_ url: URL) async throws -> URL {
try await withCheckedThrowingContinuation { continuation in
queue!.async {
do {
try FileManager.default.removeItem(at: url)
continuation.resume(returning: url)
} catch {
continuation.resume(throwing: FileDeletingError.failed(at: url))
}
}
}
}
#endif

public func flush() {
queue!.sync {
fileHandle?.synchronizeFile()
Expand All @@ -96,17 +80,6 @@ public class FileLogger: BaseLogger {
}
}

#if compiler(>=5.5.2)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public func flush() async {
await withCheckedContinuation { continuation in
queue!.async {
continuation.resume()
}
}
}
#endif

func openFile() throws {
closeFile()
let directoryURL = fileURL.deletingLastPathComponent()
Expand Down
40 changes: 0 additions & 40 deletions Tests/PuppyTests/FileLoggerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,30 +180,6 @@ final class FileLoggerTests: XCTestCase {
wait(for: [expSuccess, expFailure], timeout: 5.0)
}

#if compiler(>=5.5.2)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
func testDeletingFileAsyncAwait() async throws {
let existentFileURL = URL(fileURLWithPath: "./existent-async-await.log").absoluteURL
let noExistentFileURL = URL(fileURLWithPath: "./no-existent-async-await.log").absoluteURL
let fileLogger = try FileLogger("com.example.yourapp.filelogger.deletingasyncawait", fileURL: existentFileURL)

do {
let url = try await fileLogger.delete(existentFileURL)
XCTAssertEqual(url, existentFileURL)
} catch {
XCTFail("error should not be thrown, but it was thrown: \(error.localizedDescription)")
}

do {
_ = try await fileLogger.delete(noExistentFileURL)
XCTFail("error should be thrown while awaiting, but it was not thrown")
} catch {
XCTAssertEqual(error as? FileDeletingError, .failed(at: noExistentFileURL))
XCTAssertEqual(error.localizedDescription, "failed to delete the file: \(noExistentFileURL)")
}
}
#endif

func testFlushFile() throws {
let flushFileURL = URL(fileURLWithPath: "./flush.log").absoluteURL
let fileLogger = try FileLogger("com.example.yourapp.filelogger.flush", fileURL: flushFileURL, flushMode: .manual)
Expand Down Expand Up @@ -238,22 +214,6 @@ final class FileLoggerTests: XCTestCase {
wait(for: [exp], timeout: 5.0)
}

#if compiler(>=5.5.2)
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
func testFlushFileAsyncAwait() async throws {
let fileURL = URL(fileURLWithPath: "./flush-async-await.log").absoluteURL
let fileLogger = try FileLogger("com.example.yourapp.filelogger.flushasyncawait", fileURL: fileURL, flushMode: .manual)
let log = Puppy()
log.add(fileLogger)
log.trace("flushAsyncAwait, TRACE message using FileLogger")
log.verbose("flushAsyncAwait, VERBOSE message using FileLogger")

await fileLogger.flush()
_ = try await fileLogger.delete(fileURL)
log.remove(fileLogger)
}
#endif

func testFilePermssion() throws {
let fileURL = URL(fileURLWithPath: "./permisson600.log").absoluteURL
let fileLogger = try FileLogger("com.example.yourapp.filelogger.permisson600", fileURL: fileURL, filePermisson: "600")
Expand Down

0 comments on commit ad5297a

Please sign in to comment.