daemon_set_flag(DF_LOG_TIME);
daemon_set_flag(DF_LOG_HOSTNAME);
daemon_set_flag(DF_LOG_LL);
+ if (conf.log_timing_given)
+ daemon_set_flag(DF_LOG_TIMING);
if (conf.logfile_given) {
daemon_set_logfile(conf.logfile_arg);
daemon_open_log_or_die();
#include <pwd.h>
#include <sys/types.h> /* getgrnam() */
#include <grp.h>
+#include <sys/time.h>
+#include <stdbool.h>
#include "para.h"
#include "daemon.h"
me->flags &= ~flag;
}
-static unsigned daemon_test_flag(unsigned flag)
+static bool daemon_test_flag(unsigned flag)
{
return me->flags & flag;
}
va_list argp;
FILE *fp;
struct tm *tm;
- time_t t1;
char *color;
+ bool log_time = daemon_test_flag(DF_LOG_TIME), log_timing =
+ daemon_test_flag(DF_LOG_TIMING);
ll = PARA_MIN(ll, NUM_LOGLEVELS - 1);
ll = PARA_MAX(ll, LL_DEBUG);
color = daemon_test_flag(DF_COLOR_LOG)? me->log_colors[ll] : NULL;
if (color)
fprintf(fp, "%s", color);
- if (daemon_test_flag(DF_LOG_TIME)) { /* print date and time */
- char str[100];
- time(&t1);
- tm = localtime(&t1);
- strftime(str, sizeof(str), "%b %d %H:%M:%S", tm);
- fprintf(fp, "%s ", str);
+ if (log_time || log_timing) {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ if (daemon_test_flag(DF_LOG_TIME)) { /* print date and time */
+ time_t t1 = tv.tv_sec;
+ char str[100];
+ tm = localtime(&t1);
+ strftime(str, sizeof(str), "%b %d %H:%M:%S", tm);
+ fprintf(fp, "%s%s", str, log_timing? ":" : " ");
+ }
+ if (log_timing) /* print milliseconds */
+ fprintf(fp, "%04lu ", (long unsigned)tv.tv_usec / 1000);
}
if (daemon_test_flag(DF_LOG_HOSTNAME)) {
if (!me->hostname)
--- /dev/null
+<qu>
+option "log-timing" T
+#~~~~~~~~~~~~~~~~~~~~
+"show milliseconds in log messages"
+flag off
+details = "
+ Selecting this option causes milliseconds to be included in
+ the log message output. This allows to measure the interval
+ between log messages in milliseconds which is useful for
+ identifying timing problems.
+"
+</qu>
$(ggo_dir)/loglevel.m4 $(ggo_dir)/color.m4 \
$(ggo_dir)/config_file.m4 $(ggo_dir)/logfile.m4 \
$(ggo_dir)/daemon.m4 $(ggo_dir)/user.m4 \
- $(ggo_dir)/group.m4
+ $(ggo_dir)/group.m4 $(ggo_dir)/log_timing.m4
$(ggo_dir)/afh.ggo: $(ggo_dir)/loglevel.m4
$(ggo_dir)/audioc.ggo: $(ggo_dir)/loglevel.m4
daemon_set_flag(DF_LOG_PID);
daemon_set_flag(DF_LOG_LL);
daemon_set_flag(DF_LOG_TIME);
+ if (conf.log_timing_given)
+ daemon_set_flag(DF_LOG_TIMING);
ret = 1;
out:
free(cf);