-
Notifications
You must be signed in to change notification settings - Fork 5.3k
logging: add option to use android logger for process logs #9767
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
8 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #include "common/common/logger_impl.h" | ||
|
|
||
| #include "spdlog/sinks/android_sink.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Logger { | ||
|
|
||
| AndroidLogger::AndroidLogger(const std::string& name) | ||
| : Logger(std::make_shared<spdlog::logger>( | ||
| name, std::make_shared<spdlog::sinks::android_sink<std::mutex>>())) {} | ||
|
|
||
| } // namespace Logger | ||
| } // namespace Envoy |
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,21 @@ | ||
| #pragma once | ||
|
|
||
| #include "common/common/base_logger.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Logger { | ||
|
|
||
| #define GENERATE_LOGGER(X) AndroidLogger(#X), | ||
|
|
||
| /** | ||
| * Logger that uses spdlog::sinks::android_sink. | ||
| */ | ||
| class AndroidLogger : public Logger { | ||
| private: | ||
| AndroidLogger(const std::string& name); | ||
|
|
||
| friend class Registry; | ||
| }; | ||
|
|
||
| } // namespace Logger | ||
| } // namespace Envoy |
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,17 @@ | ||
| #include "common/common/base_logger.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Logger { | ||
|
|
||
| const char* Logger::DEFAULT_LOG_FORMAT = "[%Y-%m-%d %T.%e][%t][%l][%n] %v"; | ||
|
|
||
| Logger::Logger(std::shared_ptr<spdlog::logger> logger) : logger_(logger) { | ||
| logger_->set_pattern(DEFAULT_LOG_FORMAT); | ||
| logger_->set_level(spdlog::level::trace); | ||
|
|
||
| // Ensure that critical errors, especially ASSERT/PANIC, get flushed | ||
| logger_->flush_on(spdlog::level::critical); | ||
| } | ||
|
|
||
| } // namespace Logger | ||
| } // namespace Envoy |
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,51 @@ | ||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "spdlog/spdlog.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Logger { | ||
|
|
||
| /** | ||
| * Logger wrapper for a spdlog logger. | ||
| */ | ||
| class Logger { | ||
| public: | ||
| /* This is simple mapping between Logger severity levels and spdlog severity levels. | ||
| * The only reason for this mapping is to go around the fact that spdlog defines level as err | ||
| * but the method to log at err level is called LOGGER.error not LOGGER.err. All other level are | ||
| * fine spdlog::info corresponds to LOGGER.info method. | ||
| */ | ||
| using Levels = enum { | ||
| trace = spdlog::level::trace, // NOLINT(readability-identifier-naming) | ||
| debug = spdlog::level::debug, // NOLINT(readability-identifier-naming) | ||
| info = spdlog::level::info, // NOLINT(readability-identifier-naming) | ||
| warn = spdlog::level::warn, // NOLINT(readability-identifier-naming) | ||
| error = spdlog::level::err, // NOLINT(readability-identifier-naming) | ||
| critical = spdlog::level::critical, // NOLINT(readability-identifier-naming) | ||
| off = spdlog::level::off // NOLINT(readability-identifier-naming) | ||
| }; | ||
|
|
||
| spdlog::string_view_t levelString() const { | ||
| return spdlog::level::level_string_views[logger_->level()]; | ||
| } | ||
| std::string name() const { return logger_->name(); } | ||
| void setLevel(spdlog::level::level_enum level) { logger_->set_level(level); } | ||
| spdlog::level::level_enum level() const { return logger_->level(); } | ||
|
|
||
| static const char* DEFAULT_LOG_FORMAT; | ||
|
|
||
| protected: | ||
| Logger(std::shared_ptr<spdlog::logger> logger); | ||
|
|
||
| private: | ||
| std::shared_ptr<spdlog::logger> logger_; // Use shared_ptr here to allow static construction | ||
| // of vector in Registry::allLoggers(). | ||
| // TODO(junr03): expand Logger's public API to delete this friendship. | ||
| friend class Registry; | ||
| }; | ||
|
|
||
| } // namespace Logger | ||
| } // namespace Envoy |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #pragma once | ||
|
|
||
| #include "common/common/base_logger.h" | ||
|
|
||
| namespace Envoy { | ||
junr03 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| namespace Logger { | ||
|
|
||
| #define GENERATE_LOGGER(X) StandardLogger(#X), | ||
|
|
||
| } // namespace Logger | ||
| } // namespace Envoy | ||
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.
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.
Given that the andoid sink in spdlog is
#ifdef __ANDROID__, does it make sense to gate this logger on the android equivalent of//bazel::windows_x86_64and//bazel:apple(instead of a flag that won't work in any other env) and following the pattern used forenvoy_cc_win32_library?(The file watcher lib should get the same treatment for apple, but that's another PR.)
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.
That was my first idea, but @goaway pointed out that there might be cases where we might want the StandardLogger when
__ANDROID__is defined, e.g running envoy as a process in an android device, rather than in a sandboxed application.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.
Ok. Do we want to pull the selection logic out into helpers?
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 also debated about this. Given that it was only used once now and for the foreseeable future I opted for not introducing more helpers into the build system until they are needed. But if you think it is worth it, I am happy to add!
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 think the thing I'm getting it is whether having an empty envoy_cc_library (logger_impl_lib_android) when android logging is disabled causes some kind of problem for bazel (particular the query subcommand). It seemed like there was something related to that with win32 libs, but I'm a bit out of my depth when it comes to bazel. I suppose it can always be fixed 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.
I see. I was copying the pattern from win32
envoy/bazel/envoy_library.bzl
Line 151 in b78fc4e