+static void yaz_log_open_check(struct tm *tm, int force)
+{
+ char new_filename[512];
+ static char cur_filename[512] = "";
+
+ if (!l_file)
+ l_file = stderr;
+
+ if (l_fname && *l_fname)
+ {
+ strftime(new_filename, sizeof(new_filename)-1, l_fname, tm);
+ if (strcmp(new_filename, cur_filename))
+ {
+ strcpy(cur_filename, new_filename);
+ force = 1;
+ }
+ if (l_max_size > 0 && (l_file && l_file != stderr))
+ {
+ long flen = ftell(l_file);
+ if (flen > l_max_size)
+ {
+ rotate_log(cur_filename);
+ force = 1;
+ }
+ }
+ if (force)
+ {
+ if (l_file && l_file != stderr)
+ fclose(l_file);
+ l_file = fopen(cur_filename, "a");
+ if (l_level & YLOG_FLUSH)
+ setvbuf(l_file, 0, _IONBF, 0);
+ }
+ }
+}
+
+void yaz_log_reopen()
+{
+ time_t cur_time = time(0);
+#if HAVE_LOCALTIME_R
+ struct tm tm0, *tm = &tm0;
+#else
+ struct tm *tm;
+#endif
+
+ nmem_mutex_enter(log_mutex);
+#if HAVE_LOCALTIME_R
+ localtime_r(&cur_time, tm);
+#else
+ tm = localtime(&cur_time);
+#endif
+ yaz_log_open_check(tm, 1);
+ nmem_mutex_leave(log_mutex);
+}
+