`RUBY_DEBUG_LOG_PID` for `RUBY_DEBUG_LOG()`

`RUBY_DEBUG_LOG=stderr RUBY_DEBUG_LOG_PID=1 ruby ...` will prints
debug logs with PID.
This commit is contained in:
Koichi Sasada 2023-04-26 16:54:34 +09:00
Родитель b90d87bf25
Коммит 457824e2d3
1 изменённых файлов: 11 добавлений и 0 удалений

11
debug.c
Просмотреть файл

@ -290,6 +290,7 @@ static struct {
unsigned int cnt;
struct debug_log_filter filters[MAX_DEBUG_LOG_FILTER_NUM];
unsigned int filters_num;
bool show_pid;
rb_nativethread_lock_t lock;
FILE *output;
} debug_log;
@ -406,6 +407,10 @@ setup_debug_log(void)
rb_nativethread_lock_initialize(&debug_log.lock);
setup_debug_log_filter();
if (getenv("RUBY_DEBUG_LOG_PID")) {
debug_log.show_pid = true;
}
}
}
@ -501,6 +506,12 @@ ruby_debug_log(const char *file, int line, const char *func_name, const char *fm
int len = 0;
int r = 0;
if (debug_log.show_pid) {
r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN, "pid:%d\t", getpid());
if (r < 0) rb_bug("ruby_debug_log returns %d\n", r);
len += r;
}
// message title
if (func_name && len < MAX_DEBUG_LOG_MESSAGE_LEN) {
r = snprintf(buff + len, MAX_DEBUG_LOG_MESSAGE_LEN, "%s\t", func_name);