Unifying logging in chanserv

This commit adds:
* replace multiple logging macros with LOG and LOG_DEVEL
* logging configuration for chanserv
* logging configuration for console output
* logging configuration for per file or method log level filtering for
debug builds
* file, line, and method name in log message for debug builds
This commit is contained in:
Alexandre Quesnel
2020-10-08 01:55:08 +00:00
parent 19504da100
commit a9ec1ebd99
40 changed files with 1542 additions and 1667 deletions
+33 -73
View File
@@ -41,46 +41,6 @@
#include "xcommon.h"
#include "chansrv_fuse.h"
/* module based logging */
#define LOG_ERROR 0
#define LOG_INFO 1
#define LOG_DEBUG 2
#define LOG_LVL LOG_ERROR
#define log_error(_params...) \
{ \
g_write("[%10.10u]: CLIPFILE %s: %d : ERROR: ", \
g_time3(), __func__, __LINE__); \
g_writeln (_params); \
}
#define log_always(_params...) \
{ \
g_write("[%10.10u]: CLIPFILE %s: %d : ALWAYS: ", \
g_time3(), __func__, __LINE__); \
g_writeln (_params); \
}
#define log_info(_params...) \
{ \
if (LOG_INFO <= LOG_LVL) \
{ \
g_write("[%10.10u]: CLIPFILE %s: %d : ", \
g_time3(), __func__, __LINE__); \
g_writeln (_params); \
} \
}
#define log_debug(_params...) \
{ \
if (LOG_DEBUG <= LOG_LVL) \
{ \
g_write("[%10.10u]: CLIPFILE %s: %d : ", \
g_time3(), __func__, __LINE__); \
g_writeln (_params); \
} \
}
extern int g_cliprdr_chan_id; /* in chansrv.c */
extern struct clip_s2c g_clip_s2c; /* in clipboard.c */
@@ -152,7 +112,7 @@ clipboard_check_file(char *filename)
index++;
}
}
log_debug("[%s] [%s]", filename, lfilename);
LOG_DEVEL(LOG_LEVEL_DEBUG, "[%s] [%s]", filename, lfilename);
g_strcpy(filename, lfilename);
return 0;
}
@@ -209,14 +169,14 @@ clipboard_get_file(const char *file, int bytes)
g_snprintf(full_fn, 255, "%s/%s", pathname, filename);
if (g_directory_exist(full_fn))
{
log_error("clipboard_get_file: file [%s] is a directory, "
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_get_file: file [%s] is a directory, "
"not supported", full_fn);
flags |= CB_FILE_ATTRIBUTE_DIRECTORY;
return 1;
}
if (!g_file_exist(full_fn))
{
log_error("clipboard_get_file: file [%s] does not exist",
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_get_file: file [%s] does not exist",
full_fn);
return 1;
}
@@ -229,7 +189,7 @@ clipboard_get_file(const char *file, int bytes)
cfi->size = g_file_get_size(full_fn);
cfi->flags = flags;
cfi->time = (g_time1() + CB_EPOCH_DIFF) * 10000000LL;
log_debug("ok filename [%s] pathname [%s] size [%d]",
LOG_DEVEL(LOG_LEVEL_DEBUG, "ok filename [%s] pathname [%s] size [%d]",
cfi->filename, cfi->pathname, cfi->size);
}
return 0;
@@ -292,7 +252,7 @@ clipboard_send_data_response_for_file(const char *data, int data_size)
char fn[256];
struct cb_file_info *cfi;
log_debug("clipboard_send_data_response_for_file: data_size %d",
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_data_response_for_file: data_size %d",
data_size);
//g_hexdump(data, data_size);
if (g_files_list == 0)
@@ -355,17 +315,17 @@ clipboard_send_file_size(int streamId, int lindex)
if (g_files_list == 0)
{
log_error("clipboard_send_file_size: error g_files_list is nil");
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_send_file_size: error g_files_list is nil");
return 1;
}
cfi = (struct cb_file_info *)list_get_item(g_files_list, lindex);
if (cfi == 0)
{
log_error("clipboard_send_file_size: error cfi is nil");
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_send_file_size: error cfi is nil");
return 1;
}
file_size = cfi->size;
log_debug("clipboard_send_file_size: streamId %d file_size %d",
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_file_size: streamId %d file_size %d",
streamId, file_size);
make_stream(s);
init_stream(s, 8192);
@@ -392,10 +352,10 @@ clipboard_request_file_size(int stream_id, int lindex)
int size;
int rv;
log_debug("clipboard_request_file_size:");
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_request_file_size:");
if (g_file_request_sent_type != 0)
{
log_error("clipboard_request_file_size: warning, still waiting "
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_request_file_size: warning, still waiting "
"for CB_FILECONTENTS_RESPONSE");
}
make_stream(s);
@@ -434,29 +394,29 @@ clipboard_send_file_data(int streamId, int lindex,
if (g_files_list == 0)
{
log_error("clipboard_send_file_data: error g_files_list is nil");
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_send_file_data: error g_files_list is nil");
return 1;
}
cfi = (struct cb_file_info *)list_get_item(g_files_list, lindex);
if (cfi == 0)
{
log_error("clipboard_send_file_data: error cfi is nil");
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_send_file_data: error cfi is nil");
return 1;
}
log_debug("clipboard_send_file_data: streamId %d lindex %d "
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_file_data: streamId %d lindex %d "
"nPositionLow %d cbRequested %d", streamId, lindex,
nPositionLow, cbRequested);
g_snprintf(full_fn, 255, "%s/%s", cfi->pathname, cfi->filename);
fd = g_file_open_ex(full_fn, 1, 0, 0, 0);
if (fd == -1)
{
log_error("clipboard_send_file_data: file open [%s] failed",
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_send_file_data: file open [%s] failed",
full_fn);
return 1;
}
if (g_file_seek(fd, nPositionLow) < 0)
{
log_message(LOG_LEVEL_ERROR, "clipboard_send_file_data: seek error "
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_send_file_data: seek error "
"in file: %s", full_fn);
g_file_close(fd);
return 1;
@@ -466,7 +426,7 @@ clipboard_send_file_data(int streamId, int lindex,
size = g_file_read(fd, s->data + 12, cbRequested);
if (size < 1)
{
log_error("clipboard_send_file_data: read error, want %d got %d",
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_send_file_data: read error, want %d got %d",
cbRequested, size);
free_stream(s);
g_file_close(fd);
@@ -496,12 +456,12 @@ clipboard_request_file_data(int stream_id, int lindex, int offset,
int size;
int rv;
log_debug("clipboard_request_file_data: stream_id=%d lindex=%d off=%d request_bytes=%d",
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_request_file_data: stream_id=%d lindex=%d off=%d request_bytes=%d",
stream_id, lindex, offset, request_bytes);
if (g_file_request_sent_type != 0)
{
log_error("clipboard_request_file_data: warning, still waiting "
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_request_file_data: warning, still waiting "
"for CB_FILECONTENTS_RESPONSE");
}
make_stream(s);
@@ -539,7 +499,7 @@ clipboard_process_file_request(struct stream *s, int clip_msg_status,
int cbRequested;
//int clipDataId;
log_debug("clipboard_process_file_request:");
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_file_request:");
//g_hexdump(s->p, clip_msg_len);
in_uint32_le(s, streamId);
in_uint32_le(s, lindex);
@@ -569,13 +529,13 @@ clipboard_process_file_response(struct stream *s, int clip_msg_status,
int streamId;
int file_size;
log_debug("clipboard_process_file_response:");
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_file_response:");
if (g_file_request_sent_type == CB_FILECONTENTS_SIZE)
{
g_file_request_sent_type = 0;
in_uint32_le(s, streamId);
in_uint32_le(s, file_size);
log_debug("clipboard_process_file_response: streamId %d "
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_file_response: streamId %d "
"file_size %d", streamId, file_size);
xfuse_file_contents_size(streamId, file_size);
}
@@ -587,7 +547,7 @@ clipboard_process_file_response(struct stream *s, int clip_msg_status,
}
else
{
log_error("clipboard_process_file_response: error");
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_process_file_response: error");
g_file_request_sent_type = 0;
}
return 0;
@@ -615,14 +575,14 @@ clipboard_c2s_in_file_info(struct stream *s, struct clip_file_desc *cfd)
ex_bytes -= 2;
in_uint8s(s, ex_bytes);
in_uint8s(s, 8); /* pad */
log_debug("clipboard_c2s_in_file_info:");
log_debug(" flags 0x%8.8x", cfd->flags);
log_debug(" fileAttributes 0x%8.8x", cfd->fileAttributes);
log_debug(" lastWriteTime 0x%8.8x%8.8x", cfd->lastWriteTimeHigh,
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_c2s_in_file_info:");
LOG_DEVEL(LOG_LEVEL_DEBUG, " flags 0x%8.8x", cfd->flags);
LOG_DEVEL(LOG_LEVEL_DEBUG, " fileAttributes 0x%8.8x", cfd->fileAttributes);
LOG_DEVEL(LOG_LEVEL_DEBUG, " lastWriteTime 0x%8.8x%8.8x", cfd->lastWriteTimeHigh,
cfd->lastWriteTimeLow);
log_debug(" fileSize 0x%8.8x%8.8x", cfd->fileSizeHigh,
LOG_DEVEL(LOG_LEVEL_DEBUG, " fileSize 0x%8.8x%8.8x", cfd->fileSizeHigh,
cfd->fileSizeLow);
log_debug(" num_chars %d cFileName [%s]", num_chars, cfd->cFileName);
LOG_DEVEL(LOG_LEVEL_DEBUG, " num_chars %d cFileName [%s]", num_chars, cfd->cFileName);
return 0;
}
@@ -639,17 +599,17 @@ clipboard_c2s_in_files(struct stream *s, char *file_list)
if (!s_check_rem(s, 4))
{
log_error("clipboard_c2s_in_files: parse error");
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_c2s_in_files: parse error");
return 1;
}
in_uint32_le(s, cItems);
if (cItems > 64 * 1024) /* sanity check */
{
log_error("clipboard_c2s_in_files: error cItems %d too big", cItems);
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_c2s_in_files: error cItems %d too big", cItems);
return 1;
}
xfuse_clear_clip_dir();
log_debug("clipboard_c2s_in_files: cItems %d", cItems);
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_c2s_in_files: cItems %d", cItems);
cfd = (struct clip_file_desc *)
g_malloc(sizeof(struct clip_file_desc), 0);
file_count = 0;
@@ -661,13 +621,13 @@ clipboard_c2s_in_files(struct stream *s, char *file_list)
if ((g_pos(cfd->cFileName, "\\") >= 0) ||
(cfd->fileAttributes & CB_FILE_ATTRIBUTE_DIRECTORY))
{
log_error("clipboard_c2s_in_files: skipping directory not "
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_c2s_in_files: skipping directory not "
"supported [%s]", cfd->cFileName);
continue;
}
if (xfuse_add_clip_dir_item(cfd->cFileName, 0, cfd->fileSizeLow, lindex) == -1)
{
log_error("clipboard_c2s_in_files: failed to add clip dir item");
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_c2s_in_files: failed to add clip dir item");
continue;
}