mirror of
https://github.com/tmate-io/tmate.git
synced 2024-11-08 01:04:06 +01:00
Make the log stuff a bit tidier with some helper functions.
This commit is contained in:
parent
4ec61bef46
commit
9cccb8c115
@ -61,7 +61,6 @@ cmd_show_messages_server(struct cmd_q *cmdq)
|
||||
|
||||
cmdq_print(cmdq, "started %s", tim);
|
||||
cmdq_print(cmdq, "socket path %s", socket_path);
|
||||
cmdq_print(cmdq, "debug level %d", debug_level);
|
||||
cmdq_print(cmdq, "protocol version %d", PROTOCOL_VERSION);
|
||||
|
||||
return (1);
|
||||
|
35
log.c
35
log.c
@ -22,30 +22,53 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <vis.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
FILE *log_file;
|
||||
static FILE *log_file;
|
||||
static int log_level;
|
||||
|
||||
void log_event_cb(int, const char *);
|
||||
void log_vwrite(const char *, va_list);
|
||||
static void log_event_cb(int, const char *);
|
||||
static void log_vwrite(const char *, va_list);
|
||||
|
||||
/* Log callback for libevent. */
|
||||
void
|
||||
static void
|
||||
log_event_cb(__unused int severity, const char *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. */
|
||||
void
|
||||
log_open(const char *path)
|
||||
log_open(const char *name)
|
||||
{
|
||||
char *path;
|
||||
|
||||
if (log_level == 0)
|
||||
return;
|
||||
|
||||
if (log_file != NULL)
|
||||
fclose(log_file);
|
||||
|
||||
xasprintf(&path, "tmux-%s-%ld.log", name, (long)getpid());
|
||||
log_file = fopen(path, "w");
|
||||
free(path);
|
||||
if (log_file == NULL)
|
||||
return;
|
||||
|
||||
@ -65,7 +88,7 @@ log_close(void)
|
||||
}
|
||||
|
||||
/* Write a log message. */
|
||||
void
|
||||
static void
|
||||
log_vwrite(const char *msg, va_list ap)
|
||||
{
|
||||
char *fmt, *out;
|
||||
|
2
proc.c
2
proc.c
@ -188,7 +188,7 @@ proc_start(const char *name, struct event_base *base, int forkflag,
|
||||
fatalx("event_reinit failed");
|
||||
}
|
||||
|
||||
logfile(name);
|
||||
log_open(name);
|
||||
setproctitle("%s (%s)", name, socket_path);
|
||||
|
||||
log_debug("%s started (%ld): socket %s, protocol %d", name,
|
||||
|
2
server.c
2
server.c
@ -173,7 +173,7 @@ server_start(struct event_base *base, int lockfd, char *lockfile)
|
||||
}
|
||||
close(pair[0]);
|
||||
|
||||
if (debug_level > 3)
|
||||
if (log_get_level() > 3)
|
||||
tty_create_log();
|
||||
if (pledge("stdio rpath wpath cpath fattr unix getpw recvfd proc exec "
|
||||
"tty ps", NULL) != 0)
|
||||
|
15
tmux.c
15
tmux.c
@ -44,7 +44,6 @@ struct options *global_w_options; /* window options */
|
||||
struct environ *global_environ;
|
||||
|
||||
char *shell_cmd;
|
||||
int debug_level;
|
||||
time_t start_time;
|
||||
char socket_path[PATH_MAX];
|
||||
|
||||
@ -61,18 +60,6 @@ usage(void)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void
|
||||
logfile(const char *name)
|
||||
{
|
||||
char *path;
|
||||
|
||||
if (debug_level > 0) {
|
||||
xasprintf(&path, "tmux-%s-%ld.log", name, (long) getpid());
|
||||
log_open(path);
|
||||
free(path);
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
getshell(void)
|
||||
{
|
||||
@ -243,7 +230,7 @@ main(int argc, char **argv)
|
||||
flags |= CLIENT_UTF8;
|
||||
break;
|
||||
case 'v':
|
||||
debug_level++;
|
||||
log_add_level();
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
|
4
tmux.h
4
tmux.h
@ -1432,10 +1432,8 @@ extern struct options *global_s_options;
|
||||
extern struct options *global_w_options;
|
||||
extern struct environ *global_environ;
|
||||
extern char *shell_cmd;
|
||||
extern int debug_level;
|
||||
extern time_t start_time;
|
||||
extern char socket_path[PATH_MAX];
|
||||
void logfile(const char *);
|
||||
const char *getshell(void);
|
||||
int checkshell(const char *);
|
||||
int areshell(const char *);
|
||||
@ -2210,6 +2208,8 @@ char *utf8_padcstr(const char *, u_int);
|
||||
char *get_proc_name(int, char *);
|
||||
|
||||
/* log.c */
|
||||
void log_add_level(void);
|
||||
int log_get_level(void);
|
||||
void log_open(const char *);
|
||||
void log_close(void);
|
||||
void printflike(1, 2) log_debug(const char *, ...);
|
||||
|
Loading…
Reference in New Issue
Block a user