Skip to content

Commit

Permalink
completely compile out the logging statements
Browse files Browse the repository at this point in the history
  • Loading branch information
cwaldren-ld committed Jun 12, 2024
1 parent 3ca6094 commit bbafc12
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/hello-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
smoketest:
strategy:
matrix:
logging: [ "OFF", "ON" ]
logging: [ "0", "1" ]
fail-fast: false
runs-on: "windows-2022"
steps:
Expand All @@ -35,4 +35,4 @@ jobs:
env:
BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}
OPENSSL_ROOT_DIR: ${{ steps.install-openssl.outputs.OPENSSL_ROOT_DIR }}
LD_DEBUG_LOGGING: ${{ matrix.logging }}
CFLAGS: "-D_LD_DEBUG_LOGGING=${{ matrix.logging }}"
20 changes: 11 additions & 9 deletions examples/hello-c-client/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@

char const* get_with_env_fallback(char const* source_val,
char const* env_variable,
char const* error_msg);
char const* error);

#define print(...) \
if (strcmp(logging, "ON") == 0) { \
printf(__VA_ARGS__); \
}
#if LD_DEBUG_LOGGING
#define print(...) printf(__VA_ARGS__)
#else
#define print(...) \
do { \
} while (0)
#endif

int main() {
char const* mobile_key = get_with_env_fallback(
Expand All @@ -35,10 +38,9 @@ int main() {
"variable.\n"
"The value of MOBILE_KEY in main.c takes priority over LD_MOBILE_KEY.");

char const* logging = get_with_env_fallback(
"", "LD_DEBUG_LOGGING", "set LD_DEBUG_LOGGING to ON or OFF");

printf("Logging is: %s\n", logging);
#if LD_DEBUG_LOGGING
printf("Debug logging enabled\n");
#endif

print("using mobile key: %s\n", mobile_key);
LDClientConfigBuilder config_builder =
Expand Down

0 comments on commit bbafc12

Please sign in to comment.