You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.7 KiB

  1. From 7b4587818564aa667f868249e9a8f1dc1d095fd3 Mon Sep 17 00:00:00 2001
  2. From: "Bjarni R. Einarsson" <bre@klaki.net>
  3. Date: Tue, 25 Feb 2020 16:10:11 +0000
  4. Subject: [PATCH] Omit redundant times when logging to syslog
  5. ---
  6. libpagekite/pklogging.c | 19 ++++++++++++++-----
  7. 1 file changed, 14 insertions(+), 5 deletions(-)
  8. diff --git a/libpagekite/pklogging.c b/libpagekite/pklogging.c
  9. index cf353f8..6129c30 100644
  10. --- a/libpagekite/pklogging.c
  11. +++ b/libpagekite/pklogging.c
  12. @@ -55,16 +55,25 @@ int pk_log(int level, const char* fmt, ...)
  13. #else
  14. struct timeval t;
  15. char tsbuf[30];
  16. +# ifdef HAVE_DS_LOG_FORMAT
  17. gettimeofday(&t, NULL);
  18. strftime(tsbuf, sizeof(tsbuf), "%Y-%m-%d %H:%M:%S", localtime(&t.tv_sec));
  19. -# ifdef HAVE_DS_LOG_FORMAT
  20. len = snprintf(output, 4000, "[%s.%03d][%x] ",
  21. tsbuf, (int)t.tv_usec / 1000, (int) pthread_self());
  22. # else
  23. - len = sprintf(output, "t=%s.%03d; ts=%x; tid=%x; ll=%x; msg=",
  24. - tsbuf, (int)t.tv_usec / 1000,
  25. - (int) time(0), (int) pthread_self(),
  26. - logged_lines++);
  27. + if (log_file != NULL) {
  28. + gettimeofday(&t, NULL);
  29. + strftime(tsbuf, sizeof(tsbuf), "%Y-%m-%d %H:%M:%S", localtime(&t.tv_sec));
  30. + len = sprintf(output, "t=%s.%03d; ts=%x; tid=%x; ll=%x; msg=",
  31. + tsbuf, (int)t.tv_usec / 1000,
  32. + (int) time(0), (int) pthread_self(),
  33. + logged_lines++);
  34. + }
  35. + else {
  36. + /* For syslog, we omit the times, syslog handles that. */
  37. + len = sprintf(output, "tid=%x; ll=%x; msg=",
  38. + (int) pthread_self(), logged_lines++);
  39. + }
  40. # endif
  41. #endif
  42. va_start(args, fmt);