-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Add support for logging configuration. #88
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a9d595f
feat: Add support for logging configuration.
kinyoklion a54f017
feat: Add configurable logging.
kinyoklion b526164
Revert foxy.cmake
kinyoklion 455b782
Cleanup
kinyoklion 01b8da5
Name disambiguation for GCC.
kinyoklion b9a8dde
Handle missing backend. Make ILogBackend have noexcept methods.
kinyoklion 2d36eb0
Use nullptr
kinyoklion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
libs/common/include/launchdarkly/config/shared/builders/logging_builder.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| #pragma once | ||
|
|
||
| #include <launchdarkly/config/shared/built/logging.hpp> | ||
| #include <launchdarkly/logging/log_backend.hpp> | ||
|
|
||
| #include <variant> | ||
|
|
||
| namespace launchdarkly::config::shared::builders { | ||
|
|
||
| /** | ||
| * Used to configure logging for the SDK. | ||
| */ | ||
| class LoggingBuilder { | ||
| public: | ||
| /** | ||
| * Class for configuring built in logging using the SDKs console logger. | ||
| */ | ||
| class BasicLogging { | ||
| public: | ||
| BasicLogging(); | ||
|
|
||
| /** | ||
| * Set the enabled log level. | ||
| * | ||
| * @return A reference to this builder. | ||
| */ | ||
| BasicLogging& Level(LogLevel level); | ||
|
|
||
| /** | ||
| * Set a tag for this logger. This tag will be included at the start | ||
| * of log entries in square brackets. | ||
| * | ||
| * If the name was "LaunchDarkly", then log entries will be prefixed | ||
| * with "[LaunchDarkly]". | ||
| * | ||
| * @param name | ||
| * @return | ||
| */ | ||
| BasicLogging& Tag(std::string name); | ||
|
|
||
| private: | ||
| LogLevel level_; | ||
| std::string tag_; | ||
| friend class LoggingBuilder; | ||
| }; | ||
|
|
||
| class CustomLogging { | ||
| public: | ||
| /** | ||
| * Set the backend to use for logging. The provided back-end should | ||
| * be thread-safe. | ||
| * @param backend The implementation of the backend. | ||
| * @return A reference to this builder. | ||
| */ | ||
| CustomLogging& Backend(std::shared_ptr<ILogBackend> backend); | ||
|
|
||
| private: | ||
| std::shared_ptr<ILogBackend> backend_; | ||
| friend class LoggingBuilder; | ||
| }; | ||
|
|
||
| class NoLogging {}; | ||
|
|
||
| using LoggingType = std::variant<BasicLogging, CustomLogging, NoLogging>; | ||
|
|
||
| /** | ||
| * Construct a logging builder. | ||
| */ | ||
| LoggingBuilder() = default; | ||
|
|
||
| /** | ||
| * Construct a logging builder from a custom logging builder. | ||
| * @param custom The custom logging builder to construct a builder from. | ||
| */ | ||
| LoggingBuilder(CustomLogging custom); | ||
|
|
||
| /** | ||
| * Construct a logging builder from a basic logging builder. | ||
| * @param basic The basic logging builder to construct a builder from. | ||
| */ | ||
| LoggingBuilder(BasicLogging basic); | ||
|
|
||
| /** | ||
| * Construct a logging builder from a no logging builder. | ||
| * @param no The no logging builder to construct a builder from. | ||
| */ | ||
| LoggingBuilder(NoLogging no); | ||
|
|
||
| /** | ||
| * Set the type of logging to use. | ||
| * | ||
| * Disable logging: | ||
| * ``` | ||
| * builder.Logging(LoggingBuilder::NoLogging()) | ||
| * ``` | ||
| * | ||
| * Custom logging level: | ||
| * ``` | ||
| * builder.Logging(LoggingBuilder::BasicLogging().Level(LogLevel::kDebug)) | ||
| * ``` | ||
| * | ||
| * @param logging | ||
| * @return | ||
| */ | ||
| LoggingBuilder& Logging(LoggingType logging); | ||
|
|
||
| /** | ||
| * Build a logger configuration. Intended for use by the SDK implementation. | ||
| * | ||
| * @return A built logging configuration. | ||
| */ | ||
| built::Logging Build() const; | ||
|
|
||
| private: | ||
| LoggingType logging_; | ||
| }; | ||
|
|
||
| } // namespace launchdarkly::config::shared::builders |
13 changes: 0 additions & 13 deletions
13
libs/common/include/launchdarkly/config/shared/builders/logging_bulder.hpp
This file was deleted.
Oops, something went wrong.
33 changes: 31 additions & 2 deletions
33
libs/common/include/launchdarkly/config/shared/built/logging.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,38 @@ | ||
| #pragma once | ||
|
|
||
| #include <launchdarkly/logging/log_backend.hpp> | ||
|
|
||
| #include <optional> | ||
|
|
||
| namespace launchdarkly::config::shared::built { | ||
|
|
||
| class Logging { | ||
| // TODO: Implement | ||
| /** | ||
| * Logging configuration. | ||
| */ | ||
| struct Logging { | ||
| /* | ||
| * True to disable logging. | ||
| */ | ||
| bool disable_logging; | ||
|
|
||
| /** | ||
| * Set to use a custom back-end. | ||
| * | ||
| * If set then name and level will not be used. | ||
| */ | ||
| std::shared_ptr<ILogBackend> backend; | ||
|
|
||
| /** | ||
| * When logging is enabled, and a custom backend is not | ||
| * in use, this will be the tag used for the logger. | ||
| */ | ||
| std::string tag; | ||
|
|
||
| /** | ||
| * When logging is enabled, and a custom backend is not | ||
| * in use, this will be the minimum log level. | ||
| */ | ||
| LogLevel level; | ||
| }; | ||
|
|
||
| } // namespace launchdarkly::config::shared::built |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,14 +19,14 @@ class ILogBackend { | |
| * @param level The log level to check. | ||
| * @return Returns true if the level is enabled. | ||
| */ | ||
| virtual bool Enabled(LogLevel level) = 0; | ||
| virtual bool Enabled(LogLevel level) noexcept = 0; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seemed like a good idea to make these noexcept. |
||
|
|
||
| /** | ||
| * Write a message to the specified level. | ||
| * @param level The level to write the message for. | ||
| * @param message The message to Write. | ||
| */ | ||
| virtual void Write(LogLevel level, std::string message) = 0; | ||
| virtual void Write(LogLevel level, std::string message) noexcept = 0; | ||
|
|
||
| virtual ~ILogBackend(){}; | ||
| }; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
There are some implicit constructors to make setting the logging method simpler. Here there is a basic logging builder getting converted into a LoggingBuilder.