Skip to content

Commit

Permalink
CGreen test
Browse files Browse the repository at this point in the history
  • Loading branch information
KGronek-Pubnub committed Jan 13, 2025
1 parent 0ecd88d commit 694d5b0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
4 changes: 2 additions & 2 deletions core/pubnub_log.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* -*- c-file-style:"stroustrup"; indent-tabs-mode: nil -*- */
#include "pubnub_log.h"

void (*pubnub_log_callback)(enum pubnub_log_level log_level, const char* message) = NULL;

#if PUBNUB_USE_LOG_CALLBACK

#include <stddef.h>
Expand All @@ -11,8 +13,6 @@ void pubnub_set_log_callback(void (*callback)(enum pubnub_log_level log_level, c
pubnub_log_callback = callback;
}

void (*pubnub_log_callback)(enum pubnub_log_level log_level, const char* message) = NULL;

void log_with_callback(enum pubnub_log_level log_level, const char* format, ...) {
//Check needed buffer size for the message
va_list args;
Expand Down
37 changes: 18 additions & 19 deletions core/pubnub_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,21 @@ enum pubnub_log_level {
#define PUBNUB_LOG_PRINTF(...) printf(__VA_ARGS__)
#endif

/** Generic logging macro, logs to given @a LVL using a printf-like
interface.
*/
#define PUBNUB_LOG(LVL, ...) do { if (LVL <= PUBNUB_LOG_LEVEL) PUBNUB_LOG_PRINTF(__VA_ARGS__); } while(0)

#if PUBNUB_USE_LOG_CALLBACK

#include "../lib/pb_extern.h"

/** A global variable to store log function provided by the user.
This shouldn't be accessed or set directly. Use pubnub_set_log_callback instead.
*/
extern void (*pubnub_log_callback)(enum pubnub_log_level log_level, const char* message);

/** Replaces default logging function "printf" with provided callback.
@param callback The callback that will be executed instead of default log
*/
PUBNUB_EXTERN void pubnub_set_log_callback(void (*callback)(enum pubnub_log_level log_level, const char* message));

/** A global variable to store log function provided by the user.
This shouldn't be accessed or set directly. Use pubnub_set_log_callback instead.
*/
extern void (*pubnub_log_callback)(enum pubnub_log_level log_level, const char* message);

void log_with_callback(enum pubnub_log_level log_level, const char* format, ...);

//Redefine this macro to include callback functionality
Expand All @@ -71,16 +66,20 @@ void log_with_callback(enum pubnub_log_level log_level, const char* format, ...)
is set.
*/
#define PUBNUB_LOG(LVL, ...) \
do { \
if (LVL <= PUBNUB_LOG_LEVEL) { \
if (pubnub_log_callback) { \
log_with_callback(LVL, __VA_ARGS__); \
} else { \
PUBNUB_LOG_PRINTF(__VA_ARGS__); \
} \
do { \
if (LVL <= PUBNUB_LOG_LEVEL) { \
if (pubnub_log_callback) { \
log_with_callback(LVL, __VA_ARGS__); \
} else { \
PUBNUB_LOG_PRINTF(__VA_ARGS__); \
} \
} while(0)

} \
} while(0)
#else
/** Generic logging macro, logs to given @a LVL using a printf-like
interface.
*/
#define PUBNUB_LOG(LVL, ...) do { if (LVL <= PUBNUB_LOG_LEVEL) PUBNUB_LOG_PRINTF(__VA_ARGS__); } while(0)
#endif /* PUBNUB_USE_LOG_CALLBACK */


Expand Down

0 comments on commit 694d5b0

Please sign in to comment.