- fprintf(stdout, "[%s] [%d] ", level_string, (int)pthread_self());
- vfprintf(stdout, format, ap);
- fprintf(stdout, "\n");
+
+ /* Prevent another thread from interrupting the two printfs(). */
+ flockfile(stderr);
+
+ fprintf(stderr,
+#ifdef DEBUG
+ "%-12s:%-3d "
+#endif
+ "[%s] [%d] ",
+#ifdef DEBUG
+ file, line,
+#endif
+ level_string, (int)pthread_self());
+ va_start(ap, format);
+ vfprintf(stderr, format, ap);