1
0
mirror of https://github.com/tmux/tmux.git synced 2025-04-21 11:58:48 +00:00

Do not use stderr for log file and don't call log_close when not needed.

This commit is contained in:
Nicholas Marriott 2012-05-30 15:01:57 +00:00
parent bf4b02cea2
commit eed7d9b473
2 changed files with 5 additions and 3 deletions

7
log.c
View File

@ -28,7 +28,7 @@
#include "tmux.h" #include "tmux.h"
/* Log file, if needed. */ /* Log file, if needed. */
FILE *log_file = stderr; FILE *log_file;
/* Debug level. */ /* Debug level. */
int log_level = 0; int log_level = 0;
@ -63,7 +63,7 @@ log_open(int level, const char *path)
void void
log_close(void) log_close(void)
{ {
if (log_file != stderr) if (log_file != NULL)
fclose(log_file); fclose(log_file);
event_set_log_callback(NULL); event_set_log_callback(NULL);
@ -75,6 +75,9 @@ log_vwrite(const char *msg, va_list ap)
{ {
char *fmt; char *fmt;
if (log_file == NULL)
return;
if (asprintf(&fmt, "%s\n", msg) == -1) if (asprintf(&fmt, "%s\n", msg) == -1)
exit(1); exit(1);
if (vfprintf(log_file, fmt, ap) == -1) if (vfprintf(log_file, fmt, ap) == -1)

1
tmux.c
View File

@ -73,7 +73,6 @@ logfile(const char *name)
{ {
char *path; char *path;
log_close();
if (debug_level > 0) { if (debug_level > 0) {
xasprintf(&path, "tmux-%s-%ld.log", name, (long) getpid()); xasprintf(&path, "tmux-%s-%ld.log", name, (long) getpid());
log_open(debug_level, path); log_open(debug_level, path);