- *flags = '\0';
- for (i = 0; level && mask_names[i].name; i++)
- if ( mask_names[i].mask & level)
- {
- if (*mask_names[i].name && mask_names[i].mask &&
- mask_names[i].mask != LOG_ALL)
+ if (l_max_size > 0 && yaz_global_log_file && yaz_file_type == use_file)
+ {
+ long flen = ftell(yaz_global_log_file);
+ if (flen > l_max_size)
+ {
+ rotate_log(cur_filename);
+ force = 1;
+ }
+ }
+ if (force && yaz_file_type == use_file && *cur_filename)
+ {
+ yaz_log_close();
+ yaz_global_log_file = fopen(cur_filename, "a");
+ if (l_level < 0) l_level = default_log_level();
+ if (l_level & YLOG_FLUSH)
+ setvbuf(yaz_global_log_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);
+}
+
+static void yaz_log_to_file(int level, FILE *file, const char *buf)
+{
+ time_t ti = time(0);
+ int i;
+#if HAVE_LOCALTIME_R
+ struct tm tm0, *tm = &tm0;
+#else
+ struct tm *tm;
+#endif
+
+ init_mutex();
+
+ nmem_mutex_enter(log_mutex);
+
+ #if HAVE_LOCALTIME_R
+ localtime_r(&ti, tm);
+#else
+ tm = localtime(&ti);
+#endif
+
+ yaz_log_open_check(tm, 0);
+ file = yaz_log_file(); /* file may change in yaz_log_open_check */
+
+ if (file)
+ {
+ char tbuf[TIMEFORMAT_LEN];
+ char flags[1024];
+
+ *flags = '\0';
+ for (i = 0; level && mask_names[i].name; i++)
+ if ( mask_names[i].mask & level)