+ struct log_stream *ls = log_new_stream(sizeof(struct file_stream));
+ struct file_stream *fs = (struct file_stream *) ls;
+ fs->fd = -1;
+ fs->flags = FF_CLOSE_FD | flags;
+ fs->orig_name = xstrdup(path);
+ if (strchr(path, '%'))
+ fs->flags |= FF_FORMAT_NAME;
+ 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;
+}
+
+int
+log_switch(void)
+{
+ time_t now = time(NULL);
+ struct tm *tm = localtime(&now);
+ ASSERT(tm);
+
+ int switched = 0;
+ for (int i=0; i < log_streams_after; i++)
+ if (log_streams.ptr[i]->handler == file_handler)
+ switched |= do_log_switch((struct file_stream *) log_streams.ptr[i], tm);
+ return switched;