-
-
Notifications
You must be signed in to change notification settings - Fork 259
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
Reduce log overhead when logging disabled #711
base: main
Are you sure you want to change the base?
Conversation
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.
Note: this doesn't compile, but it's reasonably close to a working impl
|
||
template <typename... Args> | ||
inline static void log(const std::string& tag, const std::string& formatString, Args&&... args) { | ||
std::string formattedString = string_format(formatString, std::forward<Args>(args)...); | ||
log(tag, formattedString); | ||
#ifdef DEBUG |
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.
this is redundant w/ the directive in iOS. It might be more correct to just guard iOS which has no concept of log levels, and leave Android based on log level. Or you could choose to have the directive here to have more similar behavior between iOS and Android
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.
thanks for your PR - but C++ build now fails (see other comments), and it's not linted properly (run yarn lint-cpp
)
|
||
public: | ||
static void log(const std::string& tag, const std::string& message); | ||
static void log(const std::string& tag, const std::string& formatString, Args... args); |
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.
This is not a template, you cannot use Args...
here. This is why the C++ build is now failing.
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.
yes, I understand, but I ended up not using this project for my work, so I don't have time to fully flesh out this patch. I was intending to simply illustrate some ways of avoiding the logging overhead and/or avoiding NSLog in release builds (which is discouraged)
@@ -8,9 +8,11 @@ | |||
#import "MmkvLogger.h" | |||
#import <Foundation/Foundation.h> | |||
|
|||
void MmkvLogger::log(const std::string& tag, const std::string& message) { | |||
void MmkvLogger::log(const std::string& tag, const std::string& formatString, Args... args) { |
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.
same here, not a template.
we can't even template this because our implementation is in two differnt spots (ios and android). so we might not be able to support Args...
.
@@ -8,9 +8,9 @@ | |||
#include "MmkvLogger.h" | |||
#include <android/log.h> | |||
|
|||
void MmkvLogger::log(const std::string& tag, const std::string& message) { | |||
void MmkvLogger::log(const std::string& tag, const std::string& formatString, Args... args) { |
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.
same here, not a template.
we can't even template this because our implementation is in two differnt spots (ios and android). so we might not be able to support Args...
.
Avoid a string format unless logging is enabled.
Fixes #710.