Skip to content

Commit

Permalink
tweak log file name construction, support strftime pattern (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
mintty committed Apr 30, 2016
1 parent 0ac5e22 commit 1e7979e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions docs/mintty.1
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,11 @@ see the note for the -i option above.
The \fBLog\fP setting can be used to specify a log file that all output is
copied into. If it is empty, as it is by default, no logging is done.
If it contains \fB%d\fP it will be substituted with the process ID.
If it contains \fB%\fP placeholders other than a single \fB%d\fP,
the log file name will be constructed by calling strftime(3) on the
pattern; note that this is likely to fail if a placeholder expands with
"/" (%D).

See also the \fIscript\fP(1) utility for a more flexible logging solution.

.TP
Expand Down
16 changes: 12 additions & 4 deletions src/child.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,21 @@ child_create(char *argv[], struct winsize *winp)
char * log = path_win_w_to_posix(cfg.log);
char * format = strchr(log, '%');
if (format && * ++ format == 'd' && !strchr(format, '%')) {
char logf[strlen(log + 20)];
char * logf = newn(char, strlen(log) + 20);
sprintf(logf, log, getpid());
log_fd = open(logf, O_WRONLY | O_CREAT | O_TRUNC, 0600);
free(log);
log = logf;
}
else if (format) {
struct timeval now;
gettimeofday (& now, 0);
char * logf = newn(char, MAX_PATH + 1);
strftime (logf, MAX_PATH, log, localtime (& now.tv_sec));
free(log);
log = logf;
}
else
log_fd = open(log, O_WRONLY | O_CREAT | O_TRUNC, 0600);

log_fd = open(log, O_WRONLY | O_CREAT | O_EXCL, 0600);
if (log_fd < 0) {
// report message and filename:
childerror("could not open log file", false);
Expand Down

0 comments on commit 1e7979e

Please sign in to comment.