-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Changes from 7 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -133,10 +133,40 @@ envoy_cc_library( | |||
| hdrs = ["logger.h"], | ||||
| external_deps = ["abseil_synchronization"], | ||||
| deps = [ | ||||
| ":base_logger_lib", | ||||
| ":lock_guard_lib", | ||||
| ":macros", | ||||
| ":non_copyable", | ||||
| ], | ||||
| ] + select({ | ||||
| "//bazel:android_logger": ["logger_impl_lib_android"], | ||||
| "//conditions:default": ["logger_impl_lib_standard"], | ||||
| }), | ||||
| ) | ||||
|
|
||||
| envoy_cc_library( | ||||
| name = "base_logger_lib", | ||||
| srcs = ["base_logger.cc"], | ||||
| hdrs = ["base_logger.h"], | ||||
| ) | ||||
|
|
||||
| envoy_cc_library( | ||||
| name = "logger_impl_lib_standard", | ||||
| hdrs = ["standard/logger_impl.h"], | ||||
| strip_include_prefix = "standard", | ||||
| ) | ||||
|
|
||||
| envoy_cc_library( | ||||
| name = "logger_impl_lib_android", | ||||
| srcs = select({ | ||||
| "//bazel:android_logger": ["android/logger_impl.cc"], | ||||
| "//conditions:default": [], | ||||
| }), | ||||
| hdrs = select({ | ||||
| "//bazel:android_logger": ["android/logger_impl.h"], | ||||
| "//conditions:default": [], | ||||
| }), | ||||
| strip_include_prefix = "android", | ||||
| deps = [":base_logger_lib"], | ||||
|
Member
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. Given that the andoid sink in spdlog is (The file watcher lib should get the same treatment for apple, but that's another PR.)
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. That was my first idea, but @goaway pointed out that there might be cases where we might want the StandardLogger when
Member
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. Ok. Do we want to pull the selection logic out into helpers?
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. 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!
Member
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. 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.
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. I see. I was copying the pattern from win32 Line 151 in b78fc4e
|
||||
| ) | ||||
|
|
||||
| envoy_cc_library( | ||||
|
|
||||
| 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 |
| 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 |
| 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 |
| 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 constant vector below. | ||
|
junr03 marked this conversation as resolved.
Outdated
|
||
| // TODO(junr03): expand Logger's public API to delete this friendship. | ||
| friend class Registry; | ||
| }; | ||
|
|
||
| } // namespace Logger | ||
| } // namespace Envoy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #pragma once | ||
|
|
||
| namespace Envoy { | ||
|
junr03 marked this conversation as resolved.
|
||
| namespace Logger { | ||
|
|
||
| #define GENERATE_LOGGER(X) StandardLogger(#X), | ||
|
|
||
| } // namespace Logger | ||
| } // namespace Envoy | ||
Uh oh!
There was an error while loading. Please reload this page.