Rework logging code to be able to turn it off completely.
This commit is contained in:
@@ -147,7 +147,7 @@ int ip_convert_address(const char* text_address, int port, struct sockaddr* addr
|
||||
addr6.sin6_port = htons(port);
|
||||
if (net_string_to_address(AF_INET6, taddr, &addr6.sin6_addr) <= 0)
|
||||
{
|
||||
hub_log(log_fatal, "Unable to convert socket address (ipv6)");
|
||||
LOG_ERROR("Unable to convert socket address (ipv6)");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ int ip_convert_address(const char* text_address, int port, struct sockaddr* addr
|
||||
addr4.sin_port = htons(port);
|
||||
if (net_string_to_address(AF_INET, taddr, &addr4.sin_addr) <= 0)
|
||||
{
|
||||
hub_log(log_fatal, "Unable to convert socket address (ipv4)");
|
||||
LOG_ERROR("Unable to convert socket address (ipv4)");
|
||||
return 0;
|
||||
}
|
||||
memcpy(addr, &addr4, sockaddr_size);
|
||||
@@ -219,7 +219,7 @@ int ip_mask_create_left(int af, int bits, struct ip_addr_encap* result)
|
||||
|
||||
#ifdef IP_CALC_DEBUG
|
||||
char* r_str = hub_strdup(ip_convert_to_string(result));
|
||||
hub_log(log_debug, "Created left mask: %s", r_str);
|
||||
LOG_DUMP("Created left mask: %s", r_str);
|
||||
hub_free(r_str);
|
||||
#endif
|
||||
|
||||
@@ -272,7 +272,7 @@ int ip_mask_create_right(int af, int bits, struct ip_addr_encap* result)
|
||||
|
||||
#ifdef IP_CALC_DEBUG
|
||||
char* r_str = hub_strdup(ip_convert_to_string(result));
|
||||
hub_log(log_debug, "Created right mask: %s", r_str);
|
||||
LOG_DUMP("Created right mask: %s", r_str);
|
||||
hub_free(r_str);
|
||||
#endif
|
||||
|
||||
@@ -405,7 +405,7 @@ int ip_compare(struct ip_addr_encap* a, struct ip_addr_encap* b)
|
||||
#ifdef IP_CALC_DEBUG
|
||||
char* a_str = hub_strdup(ip_convert_to_string(a));
|
||||
char* b_str = hub_strdup(ip_convert_to_string(b));
|
||||
hub_log(log_debug, "Comparing IPs '%s' AND '%s' => %d", a_str, b_str, ret);
|
||||
LOG_DUMP("Comparing IPs '%s' AND '%s' => %d", a_str, b_str, ret);
|
||||
hub_free(a_str);
|
||||
hub_free(b_str);
|
||||
#endif
|
||||
|
||||
@@ -33,6 +33,31 @@ enum log_verbosity {
|
||||
log_protocol = 9,
|
||||
};
|
||||
|
||||
#define LOG_FATAL(format, ...) hub_log(log_fatal, format, ## __VA_ARGS__)
|
||||
#define LOG_ERROR(format, ...) hub_log(log_error, format, ## __VA_ARGS__)
|
||||
#define LOG_WARN(format, ...) hub_log(log_warning, format, ## __VA_ARGS__)
|
||||
#define LOG_USER(format, ...) hub_log(log_user, format, ## __VA_ARGS__)
|
||||
#define LOG_INFO(format, ...) hub_log(log_info, format, ## __VA_ARGS__)
|
||||
|
||||
#ifdef DEBUG
|
||||
# define LOG_DEBUG(format, ...) hub_log(log_debug, format, ## __VA_ARGS__)
|
||||
# define LOG_TRACE(format, ...) hub_log(log_trace, format, ## __VA_ARGS__)
|
||||
#else
|
||||
# define LOG_DEBUG(format, ...) do { } while(0)
|
||||
# define LOG_TRACE(format, ...) do { } while(0)
|
||||
#endif
|
||||
|
||||
#ifdef LOWLEVEL_DEBUG
|
||||
# define LOG_DUMP(format, ...) hub_log(log_dump, format, ## __VA_ARGS__)
|
||||
# define LOG_MEMORY(format, ...) hub_log(log_memory, format, ## __VA_ARGS__)
|
||||
# define LOG_PROTO(format, ...) hub_log(log_protocol, format, ## __VA_ARGS__)
|
||||
#else
|
||||
# define LOG_DUMP(format, ...) do { } while(0)
|
||||
# define LOG_MEMORY(format, ...) do { } while(0)
|
||||
# define LOG_PROTO(format, ...) do { } while(0)
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Specify a minimum log verbosity for what messages should
|
||||
* be printed in the log.
|
||||
|
||||
@@ -47,7 +47,7 @@ void internal_debug_print_leaks()
|
||||
size_t n = 0;
|
||||
size_t leak = 0;
|
||||
size_t count = 0;
|
||||
hub_log(log_memory, "--- exit (allocs: %d, size: %zu) ---", hub_alloc_count, hub_alloc_size);
|
||||
LOG_MEMORY("--- exit (allocs: %d, size: %zu) ---", hub_alloc_count, hub_alloc_size);
|
||||
|
||||
for (; n < UHUB_MAX_ALLOCS; n++)
|
||||
{
|
||||
@@ -55,11 +55,11 @@ void internal_debug_print_leaks()
|
||||
{
|
||||
leak += hub_allocs[n].size;
|
||||
count++;
|
||||
hub_log(log_memory, "leak %p size: %zu (bt: %p %p)", hub_allocs[n].ptr, hub_allocs[n].size, hub_allocs[n].stack1, hub_allocs[n].stack2);
|
||||
LOG_MEMORY("leak %p size: %zu (bt: %p %p)", hub_allocs[n].ptr, hub_allocs[n].size, hub_allocs[n].stack1, hub_allocs[n].stack2);
|
||||
}
|
||||
}
|
||||
|
||||
hub_log(log_memory, "--- done (allocs: %d, size: %zu, peak: %d/%zu, oom: %zu) ---", count, leak, hub_alloc_peak_count, hub_alloc_peak_size, hub_alloc_oom);
|
||||
LOG_MEMORY("--- done (allocs: %d, size: %zu, peak: %d/%zu, oom: %zu) ---", count, leak, hub_alloc_peak_count, hub_alloc_peak_size, hub_alloc_oom);
|
||||
}
|
||||
#endif /* REALTIME_MALLOC_TRACKING */
|
||||
|
||||
@@ -73,7 +73,7 @@ void* internal_debug_mem_malloc(size_t size, const char* where)
|
||||
/* Make sure the malloc info struct is initialized */
|
||||
if (!hub_alloc_count)
|
||||
{
|
||||
hub_log(log_memory, "--- start ---");
|
||||
LOG_MEMORY("--- start ---");
|
||||
for (n = 0; n < UHUB_MAX_ALLOCS; n++)
|
||||
{
|
||||
hub_allocs[n].ptr = 0;
|
||||
@@ -107,14 +107,14 @@ void* internal_debug_mem_malloc(size_t size, const char* where)
|
||||
hub_alloc_peak_count = MAX(hub_alloc_count, hub_alloc_peak_count);
|
||||
hub_alloc_peak_size = MAX(hub_alloc_size, hub_alloc_peak_size);
|
||||
|
||||
hub_log(log_memory, "%s %p (%d bytes) (bt: %p %p) {allocs: %d, size: %zu}", where, ptr, (int) size, hub_allocs[n].stack1, hub_allocs[n].stack2, hub_alloc_count, hub_alloc_size);
|
||||
LOG_MEMORY("%s %p (%d bytes) (bt: %p %p) {allocs: %d, size: %zu}", where, ptr, (int) size, hub_allocs[n].stack1, hub_allocs[n].stack2, hub_alloc_count, hub_alloc_size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hub_log(log_memory, "%s *** OOM for %d bytes", where, size);
|
||||
LOG_MEMORY("%s *** OOM for %d bytes", where, size);
|
||||
hub_alloc_oom++;
|
||||
return 0;
|
||||
}
|
||||
@@ -141,7 +141,7 @@ void internal_debug_mem_free(void* ptr)
|
||||
hub_allocs[n].size = 0;
|
||||
hub_allocs[n].stack1 = 0;
|
||||
hub_allocs[n].stack2 = 0;
|
||||
hub_log(log_memory, "free %p (bt: %p %p) {allocs: %d, size: %zu}", ptr, stack1, stack2, hub_alloc_count, hub_alloc_size);
|
||||
LOG_MEMORY("free %p (bt: %p %p) {allocs: %d, size: %zu}", ptr, stack1, stack2, hub_alloc_count, hub_alloc_size);
|
||||
malloc_slot = n;
|
||||
free(ptr);
|
||||
return;
|
||||
@@ -150,7 +150,7 @@ void internal_debug_mem_free(void* ptr)
|
||||
|
||||
malloc_slot = -1;
|
||||
abort();
|
||||
hub_log(log_memory, "free %p *** NOT ALLOCATED *** (bt: %p %p)", ptr, stack1, stack2);
|
||||
LOG_MEMORY("free %p *** NOT ALLOCATED *** (bt: %p %p)", ptr, stack1, stack2);
|
||||
#else
|
||||
free(ptr);
|
||||
#endif /* REALTIME_MALLOC_TRACKING */
|
||||
|
||||
@@ -179,26 +179,26 @@ int file_read_lines(const char* file, void* data, file_line_handler_t handler)
|
||||
|
||||
memset(buf, 0, MAX_RECV_BUF);
|
||||
|
||||
hub_log(log_trace, "Opening file %s for line reading.", file);
|
||||
LOG_TRACE("Opening file %s for line reading.", file);
|
||||
|
||||
fd = open(file, 0);
|
||||
if (fd == -1)
|
||||
{
|
||||
hub_log(log_error, "Unable to open file %s: %s", file, strerror(errno));
|
||||
LOG_ERROR("Unable to open file %s: %s", file, strerror(errno));
|
||||
return -2;
|
||||
}
|
||||
|
||||
ret = read(fd, buf, MAX_RECV_BUF);
|
||||
if (ret < 0)
|
||||
{
|
||||
hub_log(log_error, "Unable to read from file %s: %s", file, strerror(errno));
|
||||
LOG_ERROR("Unable to read from file %s: %s", file, strerror(errno));
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
else if (ret == 0)
|
||||
{
|
||||
close(fd);
|
||||
hub_log(log_warning, "File is empty.");
|
||||
LOG_WARN("File is empty.");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
@@ -212,7 +212,7 @@ int file_read_lines(const char* file, void* data, file_line_handler_t handler)
|
||||
pos[0] = '\0';
|
||||
if (*start)
|
||||
{
|
||||
hub_log(log_dump, "Line: %s", start);
|
||||
LOG_DUMP("Line: %s", start);
|
||||
if (handler(start, line_count+1, data) < 0)
|
||||
return -1;
|
||||
}
|
||||
@@ -223,7 +223,7 @@ int file_read_lines(const char* file, void* data, file_line_handler_t handler)
|
||||
if (*start)
|
||||
{
|
||||
buf[strlen(start)] = 0;
|
||||
hub_log(log_dump, "Line: %s", start);
|
||||
LOG_DUMP("Line: %s", start);
|
||||
if (handler(start, line_count+1, data) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user