-
All server-side Swift apps usually have an existing logger (e.g. in Vapor it's Bootstrapping another logger is also not possible since SwiftLog explicitly disallows this and will fatal error if you try |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
we have given you the ability to initialize the logger just once somewhere in your application. In order to initialize it you just need to call
Alternatively, if you need finer grain control of instances of SwiftLog, you can call SDKLoggingSystem.add to control specific instances of the log handler. For example:
Is this what you are asking? |
Beta Was this translation helpful? Give feedback.
-
ah I think what you are asking is if you have an existing logger and you do not want to use the SDK's logger. In that case, you need to conform your logger to the public protocol LogAgent {
/// name of the struct or class where the logger was instantiated from
var name: String {get}
/// Get or set the configured log level.
var level: LogLevel {get set}
/// This method is called when a `LogAgent` must emit a log message.
///
/// - parameters:
/// - level: The `LogLevel` the message was logged at.
/// - message: The message to log.
/// - metadata: The metadata associated to this log message as a dictionary
/// - source: The source where the log message originated, for example the logging module.
/// - file: The file the log message was emitted from.
/// - function: The function the log line was emitted from.
/// - line: The line the log message was emitted from.
func log(level: LogLevel,
message: String,
metadata: [String: String]?,
source: String,
file: String,
function: String,
line: UInt)
} Then once you have done that you can pass it to an SDK client via the following code: struct MyRuntimeConfiguration: SDKRuntimeConfiguration {
var logger: LogAgent
var retryer: SDKRetryer
init(logger: LogAgent) throws {
self.logger = logger //pass in your logger or instantiate it here
self.retryer = try SDKRetryer()
}
}
let myRuntimeConfig = MyRuntimeConfiguration(logger: SwiftLogger(label: "SomeLogger")) //pass in your instance of the logger you already have
let config = try S3Client.S3ClientConfiguration(region: "us-east-1", runtimeConfig: myRuntimeConfig)
let s3Client = S3Client(config: config) |
Beta Was this translation helpful? Give feedback.
ah I think what you are asking is if you have an existing logger and you do not want to use the SDK's logger. In that case, you need to conform your logger to the
LogAgent
protocol that exists in theClientRuntime
module.