Skip to content

Commit daa28ae

Browse files
authored
Merge pull request #1 from OskarGroth/master
Update dependency name
2 parents a25b141 + 0b72a5f commit daa28ae

File tree

11 files changed

+37
-44
lines changed

11 files changed

+37
-44
lines changed

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>SchemeUserState</key>
6+
<dict>
7+
<key>swift-log-file.xcscheme_^#shared#^_</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>0</integer>
11+
</dict>
12+
</dict>
13+
</dict>
14+
</plist>

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ let package = Package(
1212
],
1313
dependencies: [
1414
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
15-
.package(url: "https://github.com/Ponyboy47/Trailblazer.git", from: "0.16.0"),
15+
.package(url: "https://github.com/Ponyboy47/Pathman.git", from: "0.20.1"),
1616
],
1717
targets: [
1818
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
1919
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
2020
.target(
2121
name: "FileLogging",
22-
dependencies: ["Logging", "TrailBlazer"]),
22+
dependencies: ["Logging", "Pathman"]),
2323
.testTarget(
2424
name: "FileLoggingTests",
25-
dependencies: ["FileLogging", "Logging", "TrailBlazer"])
25+
dependencies: ["FileLogging", "Logging", "Pathman"])
2626
]
2727
)

Sources/FileLogging/FileHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22
import Logging
3-
import TrailBlazer
3+
import Pathman
44

55
// The formatter used for the timestamp when writing messages to the log file
66
private let _formatter: DateFormatter = {

Sources/FileLogging/FileLogFactory.swift

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import TrailBlazer
1+
import Pathman
22

33
var unusedStreams = Set<FileStream>()
44

@@ -16,17 +16,6 @@ public class _FileLogFactory {
1616
/// The encoding to default to when creating file-based logs from a factory
1717
public static var defaultEncoding: String.Encoding = .utf8
1818

19-
public convenience init(path: String,
20-
encoding: String.Encoding = _FileLogFactory.defaultEncoding) {
21-
if let file = FilePath(path) {
22-
self.init(file: file, encoding: encoding)
23-
} else if let dir = DirectoryPath(path) {
24-
self.init(directory: dir, encoding: encoding)
25-
} else {
26-
fatalError("Path '\(path)' must be either a file, directory, or nonexistent path (treated as a new file)")
27-
}
28-
}
29-
3019
public convenience init(file: FilePath,
3120
encoding: String.Encoding = _FileLogFactory.defaultEncoding) {
3221
// Ensure log files have the '.log' extension
@@ -76,9 +65,7 @@ public final class FileLogHandlerFactory: _FileLogFactory {
7665
}
7766

7867
let path = parent! + "\(label).log"
79-
guard let file = FilePath(path.absolute ?? path) else {
80-
fatalError("Path '\(path.string)' exists and is not a file")
81-
}
68+
let file = FilePath(path.absolute ?? path)
8269

8370
do {
8471
let stream = try file.open(mode: "a")
@@ -90,7 +77,7 @@ public final class FileLogHandlerFactory: _FileLogFactory {
9077
}
9178
return .init(label: label, opened: stream, encoding: encoding)
9279
} catch {
93-
fatalError("Failed to open \(file) for appending")
80+
fatalError("Unable to open \(file) for appending: \(error.localizedDescription)")
9481
}
9582
}
9683
}
@@ -99,19 +86,6 @@ public final class RotatingFileLogHandlerFactory<Handler: RotatingFileLogHandler
9986
public var options: Handler.RotateOptions
10087
public var max: UInt?
10188

102-
public convenience init(path: String,
103-
encoding: String.Encoding = _FileLogFactory.defaultEncoding,
104-
options: Handler.RotateOptions,
105-
max: UInt? = nil) {
106-
if let file = FilePath(path) {
107-
self.init(file: file, encoding: encoding, options: options, max: max)
108-
} else if let dir = DirectoryPath(path) {
109-
self.init(directory: dir, encoding: encoding, options: options, max: max)
110-
} else {
111-
fatalError("Path '\(path)' must be either a file, directory, or nonexistent path (treated as a new file)")
112-
}
113-
}
114-
11589
public convenience init(file: FilePath,
11690
encoding: String.Encoding = _FileLogFactory.defaultEncoding,
11791
options: Handler.RotateOptions,
@@ -148,9 +122,7 @@ public final class RotatingFileLogHandlerFactory<Handler: RotatingFileLogHandler
148122
}
149123

150124
let path = parent! + "\(label).log"
151-
guard let file = FilePath(path.absolute ?? path) else {
152-
fatalError("Path '\(path.string)' exists and is not a file")
153-
}
125+
let file = FilePath(path.absolute ?? path)
154126

155127
do {
156128
let stream = try file.open(mode: "a")

Sources/FileLogging/Handlers/DateRotatingFileLogHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22
import Logging
3-
import TrailBlazer
3+
import Pathman
44

55
public struct DateRotatingFileLogHandler: RotatingFileLogHandler {
66
private let filename: String

Sources/FileLogging/Handlers/FileLogHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Logging
2-
import TrailBlazer
2+
import Pathman
33

44
public struct FileLogHandler: ConstantStreamFileHandler {
55
public let stream: FileStream

Sources/FileLogging/Handlers/RotatingFileLogHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22
import Logging
3-
import TrailBlazer
3+
import Pathman
44

55
var currentStreams = [AnyHashable: FileStream]()
66

Sources/FileLogging/Handlers/SizeRotatingFileLogHandler.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22
import Logging
3-
import TrailBlazer
3+
import Pathman
44

55
public struct SizeRotatingFileLogHandler: RotatingFileLogHandler {
66
private let filename: String
@@ -41,7 +41,7 @@ public struct SizeRotatingFileLogHandler: RotatingFileLogHandler {
4141

4242
public func rotate(message: Data) -> String? {
4343
let msgSize = message.count
44-
guard logFile.size + msgSize > maxSize else { return nil }
44+
guard logFile.size + Int64(msgSize) > maxSize else { return nil }
4545

4646
guard msgSize <= maxSize else {
4747
fatalError("Message is larger than maximum byte size allowed per file rotation (\(msgSize) > \(maxSize))")

Tests/FileLoggingTests/FileLoggingTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
@testable import FileLogging
22
import Foundation
33
import Logging
4-
import TrailBlazer
4+
import Pathman
55
import XCTest
66

77
final class FileLoggingTests: XCTestCase {
88
func testHammer() {
9-
var logFile = FilePath("/tmp/test.log")!
9+
var logFile = FilePath("/tmp/test.log")
1010

1111
let factory = FileLogHandlerFactory(file: logFile)
1212
LoggingSystem.bootstrap(factory.makeFileLogHandler)
@@ -23,7 +23,7 @@ final class FileLoggingTests: XCTestCase {
2323
}
2424

2525
func testHammerRotating() {
26-
let logFile = FilePath("/tmp/test.log")!
26+
let logFile = FilePath("/tmp/test.log")
2727

2828
let factory = RotatingFileLogHandlerFactory<DateRotatingFileLogHandler>(file: logFile, options: 9.seconds)
2929
LoggingSystem.bootstrap(factory.makeRotatingFileLogHandler)

0 commit comments

Comments
 (0)