Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log only the filename, not the full path in LOGGER. #902

Merged
merged 1 commit into from
Jun 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions auto_tests/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@ static const char *tox_log_level_name(TOX_LOG_LEVEL level)
return "<unknown>";
}

static void print_debug_log(Tox *m, TOX_LOG_LEVEL level, const char *path, uint32_t line, const char *func,
static void print_debug_log(Tox *m, TOX_LOG_LEVEL level, const char *file, uint32_t line, const char *func,
const char *message, void *user_data)
{
if (level == TOX_LOG_LEVEL_TRACE) {
return;
}

uint32_t index = user_data ? *(uint32_t *)user_data : 0;
const char *file = strrchr(path, '/');
file = file ? file + 1 : path;
fprintf(stderr, "[#%d] %s %s:%d\t%s:\t%s\n", index, tox_log_level_name(level), file, line, func, message);
}

Expand Down
15 changes: 14 additions & 1 deletion toxcore/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


struct Logger {
Expand Down Expand Up @@ -111,7 +112,19 @@ void logger_write(const Logger *log, LOGGER_LEVEL level, const char *file, int l
return;
}

/* Format message */
// Only pass the file name, not the entire file path, for privacy reasons.
// The full path may contain PII of the person compiling toxcore (their
// username and directory layout).
const char *filename = strrchr(file, '/');
file = filename ? filename + 1 : file;
#if defined(_WIN32) || defined(__CYGWIN__)
// On Windows, the path separator *may* be a backslash, so we look for that
// one too.
const char *windows_filename = strrchr(file, '\\');
file = windows_filename ? windows_filename + 1 : file;
#endif

// Format message
char msg[1024];
va_list args;
va_start(args, format);
Expand Down