version 1.19, 2015/11/18 14:27:44 |
version 1.20, 2015/11/24 21:19:46 |
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
#include <unistd.h> |
#include <vis.h> |
#include <vis.h> |
|
|
#include "tmux.h" |
#include "tmux.h" |
|
|
FILE *log_file; |
static FILE *log_file; |
|
static int log_level; |
|
|
void log_event_cb(int, const char *); |
static void log_event_cb(int, const char *); |
void log_vwrite(const char *, va_list); |
static void log_vwrite(const char *, va_list); |
|
|
/* Log callback for libevent. */ |
/* Log callback for libevent. */ |
void |
static void |
log_event_cb(__unused int severity, const char *msg) |
log_event_cb(__unused int severity, const char *msg) |
{ |
{ |
log_debug("%s", msg); |
log_debug("%s", msg); |
} |
} |
|
|
|
/* Increment log level. */ |
|
void |
|
log_add_level(void) |
|
{ |
|
log_level++; |
|
} |
|
|
|
/* Get log level. */ |
|
int |
|
log_get_level(void) |
|
{ |
|
return (log_level); |
|
} |
|
|
/* Open logging to file. */ |
/* Open logging to file. */ |
void |
void |
log_open(const char *path) |
log_open(const char *name) |
{ |
{ |
|
char *path; |
|
|
|
if (log_level == 0) |
|
return; |
|
|
if (log_file != NULL) |
if (log_file != NULL) |
fclose(log_file); |
fclose(log_file); |
|
|
|
xasprintf(&path, "tmux-%s-%ld.log", name, (long)getpid()); |
log_file = fopen(path, "w"); |
log_file = fopen(path, "w"); |
|
free(path); |
if (log_file == NULL) |
if (log_file == NULL) |
return; |
return; |
|
|
|
|
} |
} |
|
|
/* Write a log message. */ |
/* Write a log message. */ |
void |
static void |
log_vwrite(const char *msg, va_list ap) |
log_vwrite(const char *msg, va_list ap) |
{ |
{ |
char *fmt, *out; |
char *fmt, *out; |