Improve log url configuration
This commit is contained in:
parent
14f06072ad
commit
3fa699e9bf
@ -9,7 +9,10 @@ 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
|
||||||
@ -17,8 +20,17 @@ struct Config: Codable {
|
|||||||
/// 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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",
|
||||||
|
Loading…
Reference in New Issue
Block a user