mirror of
https://github.com/neovim/neovim.git
synced 2025-10-04 17:06:30 +00:00
log.c: include milliseconds
closes #8727 Before: INFO 180711.233956 11124 main:560: starting main loop After: INFO 180711.233956.807 11124 main:560: starting main loop Note: - Can't use uv_hrtime() nor uv_now(), they are not "since the epoch". Also, log.c can't assume a loop exists.
This commit is contained in:
@@ -7,6 +7,9 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#if !defined(WIN32)
|
||||||
|
# include <sys/time.h> // for gettimeofday()
|
||||||
|
#endif
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
|
|
||||||
#include "nvim/log.h"
|
#include "nvim/log.h"
|
||||||
@@ -271,14 +274,22 @@ static bool v_do_log_to_file(FILE *log_file, int log_level,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int millis = 0;
|
||||||
|
#if !defined(WIN32)
|
||||||
|
struct timeval curtime;
|
||||||
|
if (gettimeofday(&curtime, NULL) == 0) {
|
||||||
|
millis = (int)curtime.tv_usec / 1000;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Print the log message.
|
// Print the log message.
|
||||||
int64_t pid = os_get_pid();
|
int64_t pid = os_get_pid();
|
||||||
int rv = (line_num == -1 || func_name == NULL)
|
int rv = (line_num == -1 || func_name == NULL)
|
||||||
? fprintf(log_file, "%s %s %" PRId64 " %s", log_levels[log_level],
|
? fprintf(log_file, "%s %s.%-3d %" PRId64 " %s",
|
||||||
date_time, pid,
|
log_levels[log_level], date_time, millis, pid,
|
||||||
(context == NULL ? "?:" : context))
|
(context == NULL ? "?:" : context))
|
||||||
: fprintf(log_file, "%s %s %" PRId64 " %s%s:%d: ", log_levels[log_level],
|
: fprintf(log_file, "%s %s.%-3d %" PRId64 " %s%s:%d: ",
|
||||||
date_time, pid,
|
log_levels[log_level], date_time, millis, pid,
|
||||||
(context == NULL ? "" : context),
|
(context == NULL ? "" : context),
|
||||||
func_name, line_num);
|
func_name, line_num);
|
||||||
if (rv < 0) {
|
if (rv < 0) {
|
||||||
|
Reference in New Issue
Block a user