Skip to content

Commit c5df1a8

Browse files
committed
Fix code review.
1 parent 919ec2d commit c5df1a8

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

examples/SampleCustomLoggerCApi.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,26 @@
1919

2020
#include <pulsar/c/client.h>
2121
#include <stdio.h>
22+
#include <stdlib.h>
2223
#include <string.h>
2324
#include <time.h>
2425

25-
void format_time(char *output){
26-
time_t rawtime;
27-
struct tm * timeinfo;
28-
29-
time(&rawtime);
30-
timeinfo = localtime(&rawtime);
31-
32-
sprintf(output, "%d %d %d %d:%d:%d",
33-
timeinfo->tm_year + 1900, timeinfo->tm_mon + 1, timeinfo->tm_mday,
34-
timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
26+
char* current_time(){
27+
char *time_str = malloc(128);
28+
struct tm *p;
29+
time_t now = time(0);
30+
p=gmtime(&now);
31+
strftime(time_str, 128, "%Y-%m-%d %H:%M:%S", p);
32+
return time_str;
3533
}
3634

3735
void custom_logger(pulsar_logger_level_t level, const char *file, int line, const char *message,
3836
void *ctx) {
39-
time_t mytime = time(NULL);
40-
char * time_str = ctime(&mytime);
4137
// Control the log level yourself.
4238
if (level >= pulsar_DEBUG) {
43-
format_time(time_str);
39+
char * time_str = current_time();
4440
printf("[%s] [%u] [%s] [%d] [%s] \n", time_str, level, file, line, message);
41+
free(time_str);
4542
}
4643
}
4744

lib/c/c_ClientConfiguration.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class PulsarCLogger : public pulsar::Logger {
7878
PulsarCLogger(const std::string &file, pulsar_logger logger, void *ctx)
7979
: file_(file), logger_(logger), ctx_(ctx) {}
8080

81-
bool isEnabled(Level level) { return level >= pulsar::Logger::LEVEL_DEBUG; }
81+
bool isEnabled(Level level) { return true; }
8282

8383
void log(Level level, int line, const std::string &message) {
8484
logger_((pulsar_logger_level_t)level, file_.c_str(), line, message.c_str(), ctx_);

0 commit comments

Comments
 (0)