mirror of
https://github.com/wnagrodzki/SwiftLogger.git
synced 2025-04-07 04:51:52 +02:00
Rename File to OSFileHandle. Move OSFileHandle to OSFileHandle.swift
This commit is contained in:
parent
1eb496f343
commit
3f90ca9fa6
5 changed files with 33 additions and 20 deletions
|
@ -23,6 +23,7 @@
|
||||||
2ED103E12135C61100EB3683 /* LogrotateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ED103E02135C61100EB3683 /* LogrotateTests.swift */; };
|
2ED103E12135C61100EB3683 /* LogrotateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ED103E02135C61100EB3683 /* LogrotateTests.swift */; };
|
||||||
2ED103E32135D3FB00EB3683 /* SizeLimitedFileTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ED103E22135D3FB00EB3683 /* SizeLimitedFileTests.swift */; };
|
2ED103E32135D3FB00EB3683 /* SizeLimitedFileTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ED103E22135D3FB00EB3683 /* SizeLimitedFileTests.swift */; };
|
||||||
2ED103E52138553B00EB3683 /* DiskLoggerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ED103E42138553B00EB3683 /* DiskLoggerTests.swift */; };
|
2ED103E52138553B00EB3683 /* DiskLoggerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ED103E42138553B00EB3683 /* DiskLoggerTests.swift */; };
|
||||||
|
2ED83781236A19A60008C01F /* OSFileHandle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ED83780236A19A60008C01F /* OSFileHandle.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
/* Begin PBXContainerItemProxy section */
|
||||||
|
@ -66,6 +67,7 @@
|
||||||
2ED103E02135C61100EB3683 /* LogrotateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogrotateTests.swift; sourceTree = "<group>"; };
|
2ED103E02135C61100EB3683 /* LogrotateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogrotateTests.swift; sourceTree = "<group>"; };
|
||||||
2ED103E22135D3FB00EB3683 /* SizeLimitedFileTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SizeLimitedFileTests.swift; sourceTree = "<group>"; };
|
2ED103E22135D3FB00EB3683 /* SizeLimitedFileTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SizeLimitedFileTests.swift; sourceTree = "<group>"; };
|
||||||
2ED103E42138553B00EB3683 /* DiskLoggerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiskLoggerTests.swift; sourceTree = "<group>"; };
|
2ED103E42138553B00EB3683 /* DiskLoggerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiskLoggerTests.swift; sourceTree = "<group>"; };
|
||||||
|
2ED83780236A19A60008C01F /* OSFileHandle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSFileHandle.swift; sourceTree = "<group>"; };
|
||||||
2EDA8AE8213ACCFF00FE5840 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
|
2EDA8AE8213ACCFF00FE5840 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
|
@ -149,6 +151,7 @@
|
||||||
2EBF4B552122B598008E4117 /* SizeLimitedFile.swift */,
|
2EBF4B552122B598008E4117 /* SizeLimitedFile.swift */,
|
||||||
2EBF4B562122B598008E4117 /* Logrotate.swift */,
|
2EBF4B562122B598008E4117 /* Logrotate.swift */,
|
||||||
2ED077DA2132B0320058EEFC /* OSFileManager.swift */,
|
2ED077DA2132B0320058EEFC /* OSFileManager.swift */,
|
||||||
|
2ED83780236A19A60008C01F /* OSFileHandle.swift */,
|
||||||
);
|
);
|
||||||
path = DiskLogger;
|
path = DiskLogger;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -259,6 +262,7 @@
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
2EBF4B582122B598008E4117 /* SizeLimitedFile.swift in Sources */,
|
2EBF4B582122B598008E4117 /* SizeLimitedFile.swift in Sources */,
|
||||||
|
2ED83781236A19A60008C01F /* OSFileHandle.swift in Sources */,
|
||||||
2EBF4B572122B598008E4117 /* DiskLogger.swift in Sources */,
|
2EBF4B572122B598008E4117 /* DiskLogger.swift in Sources */,
|
||||||
2EBF4B4C2122AF53008E4117 /* NullLogger.swift in Sources */,
|
2EBF4B4C2122AF53008E4117 /* NullLogger.swift in Sources */,
|
||||||
2EBF4B3E2122AA34008E4117 /* Logger.swift in Sources */,
|
2EBF4B3E2122AA34008E4117 /* Logger.swift in Sources */,
|
||||||
|
|
|
@ -148,14 +148,7 @@ private class FileWriterFactory: SizeLimitedFileFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
private class FileHandleFactory: FileFactory {
|
private class FileHandleFactory: FileFactory {
|
||||||
func makeInstance(forWritingTo: URL) throws -> File {
|
func makeInstance(forWritingTo: URL) throws -> OSFileHandle {
|
||||||
return try FileHandle(forWritingTo: forWritingTo)
|
return try FileHandle(forWritingTo: forWritingTo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension FileHandle: File {
|
|
||||||
|
|
||||||
func swift_write(_ data: Data) throws {
|
|
||||||
try __write(data, error: ())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
23
Logger/Loggers/DiskLogger/OSFileHandle.swift
Normal file
23
Logger/Loggers/DiskLogger/OSFileHandle.swift
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
//
|
||||||
|
// OSFileHandle.swift
|
||||||
|
// Logger
|
||||||
|
//
|
||||||
|
// Created by Wojciech Nagrodzki on 30/10/2019.
|
||||||
|
// Copyright © 2019 Wojciech Nagrodzki. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
protocol OSFileHandle {
|
||||||
|
func seekToEndOfFile() -> UInt64
|
||||||
|
func swift_write(_ data: Data) throws
|
||||||
|
func synchronizeFile()
|
||||||
|
func closeFile()
|
||||||
|
}
|
||||||
|
|
||||||
|
extension FileHandle: OSFileHandle {
|
||||||
|
|
||||||
|
func swift_write(_ data: Data) throws {
|
||||||
|
try __write(data, error: ())
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,15 +24,8 @@
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
protocol File {
|
|
||||||
func seekToEndOfFile() -> UInt64
|
|
||||||
func swift_write(_ data: Data) throws
|
|
||||||
func synchronizeFile()
|
|
||||||
func closeFile()
|
|
||||||
}
|
|
||||||
|
|
||||||
protocol FileFactory {
|
protocol FileFactory {
|
||||||
func makeInstance(forWritingTo: URL) throws -> File
|
func makeInstance(forWritingTo: URL) throws -> OSFileHandle
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write failed as allowed size limit would be exceeded.
|
/// Write failed as allowed size limit would be exceeded.
|
||||||
|
@ -55,7 +48,7 @@ protocol SizeLimitedFile {
|
||||||
/// Allows writing to a file while respecting allowed size limit.
|
/// Allows writing to a file while respecting allowed size limit.
|
||||||
final class SizeLimitedFileImpl {
|
final class SizeLimitedFileImpl {
|
||||||
|
|
||||||
private let file: File
|
private let file: OSFileHandle
|
||||||
private let sizeLimit: UInt64
|
private let sizeLimit: UInt64
|
||||||
private var currentSize: UInt64
|
private var currentSize: UInt64
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ private class UnopenableFileFactory: FileFactory {
|
||||||
|
|
||||||
struct OpenFileError: Error {}
|
struct OpenFileError: Error {}
|
||||||
|
|
||||||
func makeInstance(forWritingTo: URL) throws -> File {
|
func makeInstance(forWritingTo: URL) throws -> OSFileHandle {
|
||||||
throw OpenFileError()
|
throw OpenFileError()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,12 +78,12 @@ private class FileMockFactory: FileFactory {
|
||||||
|
|
||||||
let mock = FileMock()
|
let mock = FileMock()
|
||||||
|
|
||||||
func makeInstance(forWritingTo: URL) throws -> File {
|
func makeInstance(forWritingTo: URL) throws -> OSFileHandle {
|
||||||
return mock
|
return mock
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class FileMock: File {
|
private class FileMock: OSFileHandle {
|
||||||
|
|
||||||
private(set) var writtenData = Data()
|
private(set) var writtenData = Data()
|
||||||
private(set) var synchronizeFileCallCount = 0
|
private(set) var synchronizeFileCallCount = 0
|
||||||
|
|
Loading…
Add table
Reference in a new issue