![]() |
fuse_kafka
|
00001 00009 #ifndef TRACE_C 00010 #define TRACE_C 00011 #include "trace.h" 00012 #include "context.c" 00013 int trace_debug_enabled() 00014 { 00015 kafka_t *private_data = (kafka_t*) fuse_get_context()->private_data; 00016 if(private_data == NULL) return 0; 00017 config* conf = (config*)private_data->conf; 00018 return (conf->debug_n > 0); 00019 } 00020 char* trace_log_path_get() 00021 { 00022 kafka_t *private_data = (kafka_t*) fuse_get_context()->private_data; 00023 if(private_data == NULL) return NULL; 00024 config* conf = (config*)private_data->conf; 00025 printf("%d\n", (int) conf->log_n); 00026 if(conf->log_n != 1) return NULL; 00027 return conf->log[0]; 00028 } 00029 static int trace(const char* fmt, ...) 00030 { 00031 char* str; 00032 int res; 00033 va_list ap; 00034 va_start(ap, fmt); 00035 vasprintf(&str, fmt, ap); 00036 va_end(ap); 00037 //res = actual_kafka_write("./fuse_kafka.log", str, strlen(str), 0); 00038 char* path = trace_log_path_get(); 00039 if(path == NULL) 00040 { 00041 printf("%s\n", str); 00042 } 00043 else 00044 { 00045 FILE* f = fopen(path, "a+"); 00046 if(f != NULL) 00047 { 00048 fprintf(f, "%u %s\n", (unsigned)time(NULL), str); 00049 fclose(f); 00050 } 00051 } 00052 free(str); 00053 return res; 00054 } 00055 #endif