-
Notifications
You must be signed in to change notification settings - Fork 12
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
Added print callback/redirect support to the C library to route C prints to glog in C++. #63
base: master
Are you sure you want to change the base?
Conversation
add2df5
to
fee4425
Compare
@@ -236,11 +282,18 @@ void Polaris_Free(PolarisContext_t* context) { CloseSocket(context, 1); } | |||
|
|||
/******************************************************************************/ | |||
void Polaris_SetLogLevel(int log_level) { | |||
#if !defined(POLARIS_NO_PRINT) | |||
#if !POLARIS_NO_PRINT |
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.
are you sure we dont want ifndef....this just invest the value of POLARIS_NO_PRINT (which i guess by default is 0?)
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 a little more flexible in practice. !defined(POLARIS_NO_PRINT)
would disable prints if the POLARIS_NO_PRINT
macro is defined, no matter what its value is.
If you don't use defined()
and just use the macro in an expression like !POLARIS_NO_PRINT
and the macro is not defined, the compiler will treat it as 0. So in this case you get:
- Don't define
POLARIS_NO_PRINT
at all -- Prints enabled #define POLARIS_NO_PRINT 0
-- Prints enabled#define POLARIS_NO_PRINT 1
-- Prints disabled
This makes it a little easier to turn prints on/off in a CMakeLists.txt
file for example by having it change the value it uses in a -DPOLARIS_NO_PRINT=${foo}
statement instead of having to remove the line entirely.
if (str_length != 0) { | ||
str[str_length++] = '\0'; | ||
if (__print_callback) { | ||
__print_callback("polaris.c", __LINE__, POLARIS_LOG_LEVEL_TRACE, str); |
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.
if using line, we should use FILE
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 above should be the c style thing with two underscore in front and behind, github is formatting it instead lol
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.
In theory, yes. We did this just to simplify/shorten the print since __FILE__
always includes the full path to the file (src/...
) and this is the only source file in the repo that prints anything. Unfortunately there's no macro to get just the filename, and you can't do string manipulation in the pre-processor.
I can switch it to __FILE__
if you think that's better?
} | ||
#endif | ||
|
||
/******************************************************************************/ | ||
#if !defined(P1_NO_PRINT) && defined(POLARIS_USE_TLS) | ||
#if !P1_NO_PRINT && POLARIS_USE_TLS |
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.
ifndef
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.
See my explanation above. This makes it a lot easier to set these macros in CMake or Bazel by changing the value of a -D
statement instead of having to actually conditionally remove the -D
altogether.
examples/simple_polaris_client.cc
Outdated
DEFINE_string( | ||
polaris_api_hostname, "", | ||
"Specify an alternate hostname to use when connecting to the Polaris " | ||
"authentication API server. If blank, use the default hostname."); |
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.
we should add to this comment that changes this is almost never necessary (for the public)
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.
@anathan how's this?
DEFINE_string(
polaris_api_hostname, "",
"Specify an alternate hostname to use when connecting to the Polaris "
"authentication API server. Specifying a custom API hostname is not "
"common, and is intended primarily for development purposes. If blank, use "
"the default hostname.");
examples/simple_polaris_client.cc
Outdated
DEFINE_string( | ||
polaris_hostname, "", | ||
"Specify an alternate hostname to use when connecting to the Polaris " | ||
"corrections network. If blank, use the default hostname."); |
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.
hint that is useful for regional endpoints in the EU and APAC.
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.
@anathan Is this clear, or would you suggest anything else?
DEFINE_string(
polaris_hostname, "",
"Specify an alternate hostname to use when connecting to the Polaris "
"corrections network. This may be useful when connecting to a regional "
"endpoint in the EU or APAC. If blank, use the default hostname.");
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 only nit is that it makes it so we have to print debug prints as lines, which introduces overhead in some embedded cases where you may be printing out as your loop goes. This is overall though a better structure.
@anathan Not totally sure I follow the concern here? You can still print from within a loop if you want. Do you have an example? |
v1 of these actions was marked deprecated in June 2024, and can no longer be used as of Oct 2024. https://github.blog/changelog/2024-02-13-deprecation-notice-v1-and-v2-of-the-artifact-actions/
New Features
Changes
Fixed