Improve log url configuration

This commit is contained in:
Christoph Hagen 2023-11-22 10:35:47 +01:00
parent 14f06072ad
commit 3fa699e9bf
2 changed files with 18 additions and 5 deletions

View File

@ -9,16 +9,28 @@ struct Config: Codable {
let maxBodySize: String let maxBodySize: String
/// The path to the folder where the metric logs are stored /// The path to the folder where the metric logs are stored
let logPath: String ///
/// If no path is provided, then a folder `logs` in the resources directory is created
/// If the path is relative, then it is assumed relative to the resources directory
let logPath: String?
/// Serve files in the Public directory using Vapor /// Serve files in the Public directory using Vapor
let serveFiles: Bool let serveFiles: Bool
/// Authentication tokens for remotes allowed to write /// Authentication tokens for remotes allowed to write
let writers: [String] let writers: [String]
var logURL: URL { func logURL(possiblyRelativeTo resourcesDirectory: URL) -> URL {
.init(fileURLWithPath: logPath) guard let logPath else {
return resourcesDirectory.appendingPathComponent("logs")
}
guard !logPath.hasPrefix("/") else {
return .init(fileURLWithPath: logPath)
}
guard #available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *) else {
return resourcesDirectory.appendingPathComponent(logPath)
}
return resourcesDirectory.appending(path: logPath)
} }
} }

View File

@ -25,7 +25,8 @@ public func configure(_ app: Application) throws {
let config = Config(loadFrom: resourceDirectory) let config = Config(loadFrom: resourceDirectory)
let authenticator = Authenticator(writers: config.writers) let authenticator = Authenticator(writers: config.writers)
let monitor = MetricObserver(logFileFolder: config.logURL, logMetricId: "caps.log") let logURL = config.logURL(possiblyRelativeTo: resourceDirectory)
let monitor = MetricObserver(logFileFolder: logURL, logMetricId: "caps.log")
MetricObserver.standard = monitor MetricObserver.standard = monitor
serverStatus = Metric<ServerStatus>("caps.status", serverStatus = Metric<ServerStatus>("caps.status",