Skip to content
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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

khushijain21
Copy link

@khushijain21 khushijain21 commented Apr 25, 2024

Logging Bridge for Apple's SwiftLog #517

Some Notes:
Basic Structure - LogHandler implements

  • log Level - sets log level on the handler (Default is INFO)
  • Metadata - metadata on the log handler
  • func log (...params) - converts logger data to OTel format and emits it

TODO: Write tests for the bridge

@khushijain21 khushijain21 marked this pull request as ready for review April 26, 2024 13:42
@khushijain21 khushijain21 marked this pull request as draft April 26, 2024 13:42
@khushijain21
Copy link
Author

Hello Reviewers, can you please take a look at the approach? Your feedback is appreciated. Thanks @nachoBonafonte @bryce-b @vvydier

@nachoBonafonte nachoBonafonte marked this pull request as ready for review May 13, 2024 21:27
Copy link
Member

@nachoBonafonte nachoBonafonte left a 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
Copy link
Member

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
Copy link
Member

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

Copy link
Author

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
Copy link
Member

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?

Copy link
Author

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?
Copy link
Member

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,
Copy link
Member

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?

Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants