diff --git a/doc/sphinx_source/using/core.rst b/doc/sphinx_source/using/core.rst index 8c1e88e8f..eb71d9795 100644 --- a/doc/sphinx_source/using/core.rst +++ b/doc/sphinx_source/using/core.rst @@ -1,4 +1,4 @@ -Last revised: August 29, 2023 +Last revised: Feb 25, 2025 ===================== Eggdrop Core Settings @@ -185,8 +185,9 @@ logfile "logs/logfile" set timestamp-format "[%H:%M:%S]" Set the following to the timestamp for the logfile entries. Popular times - might be "[%H:%M]" (hour, min), or "[%H:%M:%S]" (hour, min, sec). - Read 'man strftime' for more formatting options. Keep it below 32 chars. + might be "[%H:%M]" (hour, min), or "[%H:%M:%S]" (hour, min, sec). Read + 'man strftime' for more formatting options. Additionally eggdrop supports "%f" + for milliseconds. Keep it below 32 chars. set keep-all-logs 0 If you want to keep your logfiles forever, turn this setting on. All diff --git a/eggdrop.conf b/eggdrop.conf index 93ea11253..340b58dc6 100755 --- a/eggdrop.conf +++ b/eggdrop.conf @@ -181,8 +181,9 @@ logfile mco * "logs/eggdrop.log" set log-time 1 # Set the following to the timestamp for the logfile entries. Popular times -# might be "[%H:%M]" (hour, min), or "[%H:%M:%S]" (hour, min, sec). -# Read `man strftime' for more formatting options. Keep it below 32 chars. +# might be "[%H:%M]" (hour, min), or "[%H:%M:%S]" (hour, min, sec). Read +# 'man strftime' for more formatting options. Additionally eggdrop supports %f +# for milliseconds. Keep it below 32 chars. set timestamp-format {[%H:%M:%S]} # If you want to keep your logfiles forever, turn this setting on. All @@ -1503,7 +1504,7 @@ set xfer-timeout 30 #loadmodule compress # Allow compressed sending of user files? The user files are compressed with -# the compression level defined in `compress-level'. +# the compression level defined in 'compress-level'. set share-compressed 1 # This is the default compression level used. These levels are the same as diff --git a/src/misc.c b/src/misc.c index b970e6e8b..27310fcb8 100644 --- a/src/misc.c +++ b/src/misc.c @@ -513,11 +513,13 @@ void putlog (int type, char *chname, const char *format, ...) { static int inhere = 0; int i, tsl = 0; - char s[LOGLINELEN], path[PATH_MAX], *out, ct[81], *s2, stamp[34]; + char s[LOGLINELEN], path[PATH_MAX], *out, ct[81], *s2, stamp[34], + stamp2[sizeof stamp], *f, c; va_list va; time_t now2 = time(NULL); static time_t now2_last = 0; /* cache expensive localtime() */ static struct tm t; + struct timeval tv; if (now2 != now2_last) { now2_last = now2; @@ -528,12 +530,24 @@ void putlog (int type, char *chname, const char *format, ...) /* Create the timestamp */ if (shtime) { - tsl = strftime(stamp, sizeof(stamp) - 2, log_ts, &t); - stamp[tsl++] = ' '; - stamp[tsl] = 0; - } - else - *stamp = '\0'; + strlcpy(stamp, log_ts, sizeof stamp); + + /* handle millisecond specifier %f */ + if ((f = strstr(stamp, "%f")) && ((f - 1) != (strstr(stamp, "%%f")))) { + memmove(f + 3, f + 2, strlen(f + 2) + 1); + c = f[3]; /* save the char the following snprintf() will overwrite with + * null terminator + */ + gettimeofday(&tv, NULL); + snprintf(f, sizeof stamp - (f - stamp), "%03i", (int) tv.tv_usec / 1000); + f[3] = c; + } + + tsl = strftime(stamp2, sizeof(stamp2) - 2, stamp, &t); + stamp2[tsl++] = ' '; + stamp2[tsl] = 0; + } else + *stamp2 = 0; /* Format log entry at offset 'tsl,' then i can prepend the timestamp */ out = s + tsl; @@ -565,7 +579,7 @@ void putlog (int type, char *chname, const char *format, ...) } /* Place the timestamp in the string to be printed */ if (out[0] && shtime) { - memcpy(s, stamp, tsl); + memcpy(s, stamp2, tsl); out = s; } strcat(out, "\n"); @@ -599,7 +613,7 @@ void putlog (int type, char *chname, const char *format, ...) * then reset repeats. We want the current time here, * so put that in the file first. */ - fprintf(logs[i].f, "%s", stamp); + fprintf(logs[i].f, "%s", stamp2); fprintf(logs[i].f, MISC_LOGREPEAT, logs[i].repeats); logs[i].repeats = 0; /* No need to reset logs[i].szlast here