-
Notifications
You must be signed in to change notification settings - Fork 8
[20334] Configure the Log with a LogConfiguration #92
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
14 commits
Select commit
Hold shift + click to select a range
00bda84
Changes on CustomLogConsumer to accept LogFilter maps
LuciaEchevarria99 c5a151a
Rename variables log_filter_map_ and filter_map_
LuciaEchevarria99 f3dc2e6
Change if statements to booleans in accept_entry_ and unify paramete…
LuciaEchevarria99 dc4e84b
Correct uncrustify
LuciaEchevarria99 aaa7977
Include LogConfiguration struct in dev-utils
LuciaEchevarria99 ec3e17d
Change LogFilter to std::map<VerbosityKind, Fuzzy<std::string>> and a…
LuciaEchevarria99 28f4ca5
Add set_if_unset methods
LuciaEchevarria99 74f15c5
Set preference of log configuration via terminal over yaml and apply …
LuciaEchevarria99 2f714c3
Change ostream function
LuciaEchevarria99 cacb83c
Correct uncrustify
LuciaEchevarria99 5f83e14
Add includes for Windows compilation
LuciaEchevarria99 3ffd5fa
Change set method to fix Log Configuration when not parsing from yaml…
LuciaEchevarria99 87908b7
Change some comments
LuciaEchevarria99 64aef29
Refactor CustomStdLogConsumer constructor argument from reference to …
LuciaEchevarria99 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
100 changes: 100 additions & 0 deletions
100
cpp_utils/include/cpp_utils/logging/LogConfiguration.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,100 @@ | ||
| // Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License\. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cpp_utils/library/library_dll.h> | ||
| #include <cpp_utils/Log.hpp> | ||
| #include <cpp_utils/types/Fuzzy.hpp> | ||
|
|
||
| #include <map> | ||
| #include <ostream> | ||
| #include <string> | ||
|
|
||
| namespace eprosima { | ||
| namespace utils { | ||
|
|
||
| using VerbosityKind = Log::Kind; | ||
| using LogFilter = std::map<VerbosityKind, Fuzzy<std::string>>; | ||
|
|
||
| /** | ||
| * The collection of settings related to Logging. | ||
| * | ||
| * The Logging settings are: | ||
| * - Verbosity | ||
| * - Filter | ||
| */ | ||
| struct LogConfiguration | ||
| { | ||
| ///////////////////////// | ||
| // CONSTRUCTORS | ||
| ///////////////////////// | ||
|
|
||
| //! Default LogConfiguration constructor | ||
| CPP_UTILS_DllAPI LogConfiguration(); | ||
|
|
||
| ///////////////////////// | ||
| // METHODS | ||
| ///////////////////////// | ||
|
|
||
| /** | ||
| * @brief \c is_valid method. | ||
| */ | ||
| CPP_UTILS_DllAPI | ||
| virtual bool is_valid( | ||
| Formatter& error_msg) const noexcept; | ||
|
|
||
| /** | ||
| * @brief Replace verbosity with a given log_verbosity if verbosity has a lower fuzzy level. | ||
| */ | ||
| CPP_UTILS_DllAPI | ||
| void set( | ||
| const utils::Fuzzy<VerbosityKind>& log_verbosity) noexcept; | ||
|
|
||
| /** | ||
| * @brief Replace filter with a given log_filter if filter has a lower fuzzy level. | ||
| */ | ||
| CPP_UTILS_DllAPI | ||
| void set( | ||
| const LogFilter& log_filter); | ||
|
|
||
| ///////////////////////// | ||
| // VARIABLES | ||
| ///////////////////////// | ||
|
|
||
| //! Verbosity kind | ||
| Fuzzy<VerbosityKind> verbosity; | ||
| //! Log Filter | ||
| LogFilter filter; | ||
|
|
||
| }; | ||
|
|
||
| /** | ||
| * @brief \c VerbosityKind to stream Fuzzy level | ||
| */ | ||
| CPP_UTILS_DllAPI | ||
| std::ostream& operator <<( | ||
| std::ostream& os, | ||
| const Fuzzy<VerbosityKind>& kind); | ||
|
|
||
| /** | ||
| * @brief \c LogFilter to stream serialization | ||
| */ | ||
| CPP_UTILS_DllAPI | ||
| std::ostream& operator <<( | ||
| std::ostream& os, | ||
| const LogFilter& filter); | ||
|
|
||
| } /* namespace utils */ | ||
| } /* namespace eprosima */ |
|
tempate marked this conversation as resolved.
|
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 |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| // Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| /** | ||
| * @file LogConfiguration.cpp | ||
| * | ||
| */ | ||
|
|
||
| #include <cpp_utils/logging/LogConfiguration.hpp> | ||
| #include <cpp_utils/utils.hpp> | ||
|
|
||
| namespace eprosima { | ||
| namespace utils { | ||
|
|
||
|
|
||
| LogConfiguration::LogConfiguration() | ||
| : verbosity{VerbosityKind::Warning, FuzzyLevelValues::fuzzy_level_default} | ||
| { | ||
| filter[VerbosityKind::Info].set_value("", FuzzyLevelValues::fuzzy_level_default); | ||
| filter[VerbosityKind::Warning].set_value("", FuzzyLevelValues::fuzzy_level_default); | ||
| filter[VerbosityKind::Error].set_value("", FuzzyLevelValues::fuzzy_level_default); | ||
| } | ||
|
|
||
| bool LogConfiguration::is_valid( | ||
| Formatter& error_msg) const noexcept | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| void LogConfiguration::set( | ||
| const utils::Fuzzy<VerbosityKind>& log_verbosity) noexcept | ||
| { | ||
| if (verbosity.get_level() <= log_verbosity.get_level()) | ||
| { | ||
| verbosity = log_verbosity; | ||
| } | ||
| } | ||
|
|
||
| void LogConfiguration::set( | ||
| const LogFilter& log_filter) | ||
| { | ||
| if (filter[VerbosityKind::Error].get_level() <= log_filter.at(VerbosityKind::Error).get_level()) | ||
| { | ||
| filter[VerbosityKind::Error] = log_filter.at(VerbosityKind::Error); | ||
| } | ||
|
|
||
| if (filter[VerbosityKind::Warning].get_level() <= log_filter.at(VerbosityKind::Warning).get_level()) | ||
| { | ||
| filter[VerbosityKind::Warning] = log_filter.at(VerbosityKind::Warning); | ||
| } | ||
|
|
||
| if (filter[VerbosityKind::Info].get_level() <= log_filter.at(VerbosityKind::Info).get_level()) | ||
| { | ||
| filter[VerbosityKind::Info] = log_filter.at(VerbosityKind::Info); | ||
| } | ||
| } | ||
|
|
||
| std::ostream& operator <<( | ||
| std::ostream& os, | ||
| const Fuzzy<VerbosityKind>& kind) | ||
| { | ||
| os << "Fuzzy{Level(" << kind.get_level_as_str() << ") " << kind.get_reference() << "}"; | ||
| return os; | ||
| } | ||
|
|
||
| std::ostream& operator <<( | ||
| std::ostream& os, | ||
| const LogFilter& filter) | ||
| { | ||
| os << "Log Filter: {Kind: Error, Regex: " << filter.at(VerbosityKind::Error).get_value() << "}; " | ||
| << "{Kind: Warning, Regex: " << filter.at(VerbosityKind::Warning).get_value() << "}; " | ||
| << "{Kind: Info, Regex: " << filter.at(VerbosityKind::Info).get_value() << "}"; | ||
|
|
||
| return os; | ||
| } | ||
|
|
||
| } /* namespace utils */ | ||
| } /* namespace eprosima */ | ||
|
|
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.
Uh oh!
There was an error while loading. Please reload this page.