diff options
author | David Klempner <klempner@google.com> | 2015-02-11 13:07:19 -0800 |
---|---|---|
committer | David Klempner <klempner@google.com> | 2015-02-11 13:07:19 -0800 |
commit | 53eae7a3e06e4296e1557f2d3987c214f1620f10 (patch) | |
tree | a66cb88850b790b310fc449929e98a792b8d154b /src/core/support/log_win32.c | |
parent | baced4def008b3b03f89eef3f9d6da34e38b5f2a (diff) | |
parent | b7bfe698c52e65d6b2c26a45335088595609c302 (diff) |
Merge branch 'master' into epoll
Diffstat (limited to 'src/core/support/log_win32.c')
-rw-r--r-- | src/core/support/log_win32.c | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/src/core/support/log_win32.c b/src/core/support/log_win32.c index dc8c1d0785..840f24f68a 100644 --- a/src/core/support/log_win32.c +++ b/src/core/support/log_win32.c @@ -35,11 +35,16 @@ #ifdef GPR_WIN32 -#include <grpc/support/log.h> -#include <grpc/support/alloc.h> #include <stdio.h> #include <stdarg.h> +#include <grpc/support/alloc.h> +#include <grpc/support/log_win32.h> +#include <grpc/support/log.h> +#include <grpc/support/time.h> + +#include "src/core/support/string_win32.h" + void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format, ...) { char *message = NULL; @@ -74,8 +79,35 @@ void gpr_log(const char *file, int line, gpr_log_severity severity, /* Simple starter implementation */ void gpr_default_log(gpr_log_func_args *args) { - fprintf(stderr, "%s %s:%d: %s\n", gpr_log_severity_string(args->severity), + char time_buffer[64]; + gpr_timespec now = gpr_now(); + struct tm tm; + + if (localtime_s(&tm, &now.tv_sec)) { + strcpy(time_buffer, "error:localtime"); + } else if (0 == + strftime(time_buffer, sizeof(time_buffer), "%m%d %H:%M:%S", &tm)) { + strcpy(time_buffer, "error:strftime"); + } + + fprintf(stderr, "%s%s.%09u %5u %s:%d: %s\n", + gpr_log_severity_string(args->severity), time_buffer, + (int)(now.tv_nsec), GetCurrentThreadId(), args->file, args->line, args->message); } -#endif +char *gpr_format_message(DWORD messageid) { + LPTSTR tmessage; + char *message; + DWORD status = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, messageid, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)(&tmessage), 0, NULL); + message = gpr_tchar_to_char(tmessage); + LocalFree(tmessage); + return message; +} + +#endif /* GPR_WIN32 */ |