-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
mobile: Pass the log level when setting a logger #32131
Conversation
04ab5e5
to
b8e6a16
Compare
Signed-off-by: Fredy Wijaya <fredyw@google.com>
/assign @abeyad |
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.
Nice!
@@ -30,8 +53,9 @@ LambdaDelegate::~LambdaDelegate() { | |||
logger_.release(logger_.context); | |||
} | |||
|
|||
void LambdaDelegate::log(absl::string_view msg, const spdlog::details::log_msg&) { | |||
logger_.log(Data::Utility::copyToBridgeData(msg), logger_.context); | |||
void LambdaDelegate::log(absl::string_view msg, const spdlog::details::log_msg& log_msg) { |
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 know LambdaDelegate
is what it's been called from before, but do you know why it's called that? I don't understand what it means. It seems like it has an envoy_logger
, which differs it from the DefaultDelegate
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.
My guess is because it takes a function pointer, hence lambda. I agree that it's probably not a very good name. LoggerDelegate
(to replace LambdaDelegate
) and StderrLoggerDelagate
(to replace DefaultDelegate
) will probably better names.
@@ -35,7 +35,7 @@ NS_ASSUME_NONNULL_BEGIN | |||
@param networkMonitoringMode Configure how the engines observe network reachability. | |||
*/ | |||
- (instancetype)initWithRunningCallback:(nullable void (^)())onEngineRunning | |||
logger:(nullable void (^)(NSString *))logger | |||
logger:(nullable void (^)(int, NSString *))logger |
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'm guessing the int
is meant to represent the log level? What does the NSString* represent? Should we make this a struct
that can also be used in Objective-C? Also, I thought we'd need to use a NSNumber
here
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.
The NSString*
represents the message. I think using a struct is probably overkill given that we only have 2 parameters. Plus, this structure is similar to the C++ function pointer definition. As for using NSNumber
, I think using NSInteger
is better given that LogLevel
is an Int
:
public enum LogLevel: Int { |
So, I updated the code to use
NSInteger
instead of int
.
logger.log("hello!"); | ||
logger.log("goodbye"); | ||
logger.log(EnvoyLogger.Level.INFO, "hello!"); | ||
logger.log(EnvoyLogger.Level.INFO, "goodbye"); |
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.
Do we need any tets for non-INFO level (I assume that's the default), e.g. log level set to DEBUG and make sure we get debug
but not trace
messages?
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.
The current CronvoyLogger
implementation doesn't actually care about the log level and it doesn't even delegate the logging to the underlying logging implementation. It simply logs the messages to disk. I have a plan to fix this in Cronvoy similar to how we can configure the logger with direct EngineBuilder
.
The tests that do log + level are in C++. See LambdaDelegateWithLevelTest
.
Signed-off-by: Fredy Wijaya <fredyw@google.com>
Signed-off-by: Fredy Wijaya <fredyw@google.com>
Head branch was pushed to by a user without write access
/retest |
1 similar comment
/retest |
Signed-off-by: Fredy Wijaya <fredyw@google.com>
This PR adds a feature to allow the underlying logging implementation log Envoy logs according to the log levels when setting the logger via
setLogger
.For example (for Android):
Risk Level: low
Testing: unit tests
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: mobile