mirror of
https://github.com/tmux/tmux.git
synced 2024-12-12 17:38:48 +00: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, "started %s", tim);
|
||||||
cmdq_print(cmdq, "socket path %s", socket_path);
|
cmdq_print(cmdq, "socket path %s", socket_path);
|
||||||
cmdq_print(cmdq, "debug level %d", debug_level);
|
|
||||||
cmdq_print(cmdq, "protocol version %d", PROTOCOL_VERSION);
|
cmdq_print(cmdq, "protocol version %d", PROTOCOL_VERSION);
|
||||||
|
|
||||||
return (1);
|
return (1);
|
||||||
|
35
log.c
35
log.c
@ -22,30 +22,53 @@
|
|||||||
#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;
|
||||||
|
|
||||||
@ -65,7 +88,7 @@ log_close(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 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;
|
||||||
|
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");
|
fatalx("event_reinit failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
logfile(name);
|
log_open(name);
|
||||||
setproctitle("%s (%s)", name, socket_path);
|
setproctitle("%s (%s)", name, socket_path);
|
||||||
|
|
||||||
log_debug("%s started (%ld): socket %s, protocol %d", name,
|
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]);
|
close(pair[0]);
|
||||||
|
|
||||||
if (debug_level > 3)
|
if (log_get_level() > 3)
|
||||||
tty_create_log();
|
tty_create_log();
|
||||||
if (pledge("stdio rpath wpath cpath fattr unix getpw recvfd proc exec "
|
if (pledge("stdio rpath wpath cpath fattr unix getpw recvfd proc exec "
|
||||||
"tty ps", NULL) != 0)
|
"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;
|
struct environ *global_environ;
|
||||||
|
|
||||||
char *shell_cmd;
|
char *shell_cmd;
|
||||||
int debug_level;
|
|
||||||
time_t start_time;
|
time_t start_time;
|
||||||
char socket_path[PATH_MAX];
|
char socket_path[PATH_MAX];
|
||||||
|
|
||||||
@ -61,18 +60,6 @@ usage(void)
|
|||||||
exit(1);
|
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 *
|
const char *
|
||||||
getshell(void)
|
getshell(void)
|
||||||
{
|
{
|
||||||
@ -243,7 +230,7 @@ main(int argc, char **argv)
|
|||||||
flags |= CLIENT_UTF8;
|
flags |= CLIENT_UTF8;
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
debug_level++;
|
log_add_level();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
|
8
tmux.h
8
tmux.h
@ -1432,10 +1432,8 @@ extern struct options *global_s_options;
|
|||||||
extern struct options *global_w_options;
|
extern struct options *global_w_options;
|
||||||
extern struct environ *global_environ;
|
extern struct environ *global_environ;
|
||||||
extern char *shell_cmd;
|
extern char *shell_cmd;
|
||||||
extern int debug_level;
|
|
||||||
extern time_t start_time;
|
extern time_t start_time;
|
||||||
extern char socket_path[PATH_MAX];
|
extern char socket_path[PATH_MAX];
|
||||||
void logfile(const char *);
|
|
||||||
const char *getshell(void);
|
const char *getshell(void);
|
||||||
int checkshell(const char *);
|
int checkshell(const char *);
|
||||||
int areshell(const char *);
|
int areshell(const char *);
|
||||||
@ -2210,8 +2208,10 @@ char *utf8_padcstr(const char *, u_int);
|
|||||||
char *get_proc_name(int, char *);
|
char *get_proc_name(int, char *);
|
||||||
|
|
||||||
/* log.c */
|
/* log.c */
|
||||||
void log_open(const char *);
|
void log_add_level(void);
|
||||||
void log_close(void);
|
int log_get_level(void);
|
||||||
|
void log_open(const char *);
|
||||||
|
void log_close(void);
|
||||||
void printflike(1, 2) log_debug(const char *, ...);
|
void printflike(1, 2) log_debug(const char *, ...);
|
||||||
__dead void printflike(1, 2) fatal(const char *, ...);
|
__dead void printflike(1, 2) fatal(const char *, ...);
|
||||||
__dead void printflike(1, 2) fatalx(const char *, ...);
|
__dead void printflike(1, 2) fatalx(const char *, ...);
|
||||||
|
Loading…
Reference in New Issue
Block a user