- if (name)
- {
- if (log_name_patt)
- xfree(log_name_patt);
- if (log_filename)
- {
- xfree(log_filename);
- log_filename = NULL;
- }
- log_name_patt = xstrdup(name);
- log_params = !!strchr(name, '%');
- log_filename_size = strlen(name) + 64; /* 63 is an upper bound on expansion of % escapes */
- log_filename = xmalloc(log_filename_size);
- log_filename[0] = 0;
- log_switch();
- log_switch_hook = internal_log_switch;
- }
+ struct log_stream *ls = log_new_stream(sizeof(struct file_stream));
+ struct file_stream *fs = (struct file_stream *) ls;
+ fs->fd = -1;
+ fs->orig_name = xstrdup(path);
+ if (strchr(path, '%'))
+ fs->flags = FF_FORMAT_NAME;
+ fs->flags |= FF_CLOSE_FD | more_flags;
+ ls->msgfmt = LSFMT_DEFAULT;
+ ls->handler = file_handler;
+ ls->close = file_close;
+
+ time_t now = time(NULL);
+ struct tm *tm = localtime(&now);
+ ASSERT(tm);
+ do_log_switch(fs, tm); // die()'s on errors
+ return ls;