New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Bridge: Logging Bridge for SwiftLog #535
base: main
Are you sure you want to change the base?
Conversation
Hello Reviewers, can you please take a look at the approach? Your feedback is appreciated. Thanks @nachoBonafonte @bryce-b @vvydier |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking really good, and the documentation is helping a lot. I added some comments about the API and consistency. Let me know what do you think.
public var attributes: [String: AttributeValue]? | ||
} | ||
|
||
// Define a custom log handler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation comments are written with a triple ///, it also has a format for parameters and return values. Swift can parse this comments to create documentation
private var loggerProvider : LoggerProvider // Property to set LoggerProvider | ||
private var logger: OpenTelemetryApi.Logger | ||
|
||
// Define the log level for this handler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the default level? can it be changed temporary for a specific log? These things should be part of the commentary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the default level is .info. It can be changed like this
var logger = Logger(label: "com.example.myapp")
logger.logLevel = .info // the level of of the handler
private var logger: OpenTelemetryApi.Logger | ||
|
||
// Define the log level for this handler | ||
private var _logLevel: Logging.Logger.Level = .info |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a private and a public that overwrites it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is so that the user can change the default log level.
} | ||
} | ||
|
||
// should default logger provider be a noop? or the sdk implementation? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use the default one, if initialized is because the user wants to use it.
self.logger = loggerBuilder.build() | ||
} | ||
|
||
public func log(level: Logging.Logger.Level, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the level be optional, as there is a default one? Or should it be mandatory and remove the default one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The log level defined above is for the LogHandler whereas this is the log level with which the message was logged
var logger = Logger(label: "com.example.myapp")
logger.logLevel = .info // the level of of the handler
logger.handler = otelLogHandler
logger.debug("This is a debug message") // this log message will not be printed as .debug is lower than .info
logger.info("Logging with additional metadata") // this will be printed
Logging Bridge for Apple's SwiftLog #517
Some Notes:
Basic Structure - LogHandler implements
TODO: Write tests for the bridge