+ if (i == 0) {
+ strcpy(sname, "unknown");
+ } else {
+ sname[i] = '\0';
+ }
+ }
+ now = time(NULL);
+ t = localtime(&now);
+ /* ISO 8601 International Standard Date format */
+ strftime(nfmt, sizeof nfmt, "%Y-%m-%d %T ", t);
+ rlen = sizeof(nfmt) - strlen(nfmt);
+ if (rlen <= 0 || snprintf(nfmt + strlen(nfmt), rlen,
+ "[%s:%s%s] %s\n", sname, Which[which], Modes[mode],
+ fmt) >= rlen) {
+ warnx("log format overflow, user name=%s", sname);
+ } else {
+ va_start(argp, fmt);
+ vfprintf(logfile, nfmt, argp);
+ va_end(argp);
+ fflush(logfile);