mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-22 23:59:41 +08:00
Logs: a logger for each log string, shared and closed once unused
A logger (struct logger) is identified by the string log or -l gives it: "" stdout, "/dev/null" none, "@IDENT" syslog, "&DSN" ODBC, "radius", anything else a file. Each type (struct logtype) has init, formatting of a connection into a buffer, writing, close, and a periodic tick for rotation and flushing; ODBC and RADIUS register their types from 3proxy, which alone has them. Services and configurations hold the logger they use; the last to let go closes it, except the standard ones (none, stdout, stderr, syslog), which are opened at startup and kept. -l takes every log type now, and a file named by several services or by both log and -l is opened once. rotate and archiver are bound to the logger of the last log command when its configuration comes into force, and every file logger is rotated by the main loop. Errors with no connection go to a new stderr logger; after daemon, or as a Windows service, stdout logging writes nothing and errors go to the last log configured. A log whose writes keep failing is closed and reopened; while it cannot be, its lines go to stderr and it is retried every minute. ODBC's own reconnection throttle gives way to this. Formatting (logbuf) is separate from counting traffic and clearing the statistics, done once by logdo(), the services' log function, so a later step can format or copy a connection's line and write it from a thread of its own. dologname() and timechanged() move to log.c, which the standalone services link as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
57818ad497
commit
d613750b94
14 files changed
+996
-415
No files matched your search
+47
-8
@@ -244,6 +244,7 @@ struct symbol;
|
||||
struct pluginlink;
|
||||
struct srvparam;
|
||||
struct listener;
|
||||
struct logger;
|
||||
|
||||
typedef void (*LOGFUNC)(struct clientparam * param, const unsigned char *);
|
||||
typedef int (*AUTHFUNC)(struct clientparam * param);
|
||||
@@ -624,6 +625,47 @@ struct hashtable {
|
||||
uint32_t entropy;
|
||||
};
|
||||
|
||||
/* A log, named by the string the log command or -l gives it: "" standard
|
||||
output, "/dev/null" none, "@IDENT" syslog, "&DSN" ODBC, "radius" RADIUS
|
||||
accounting, anything else a file. One logger serves every service and
|
||||
configuration naming it the same way, and is closed once none uses it,
|
||||
the standard ones (none, standard output and error, syslog) excepted. */
|
||||
struct logtype {
|
||||
const char *name;
|
||||
int (*match)(const unsigned char *selector);
|
||||
/* opens what it writes to, lg->data: 0, an error, or < 0 if it cannot
|
||||
be reached now but is to be tried again */
|
||||
int (*init)(struct logger *lg);
|
||||
/* the line for a connection into buf, CLIENTTMPBUFSIZE: its length, -1
|
||||
for nothing to write; NULL if write() takes the connection itself */
|
||||
int (*format)(struct logger *lg, struct clientparam *param, const unsigned char *s, unsigned char *buf);
|
||||
/* 0, or an error */
|
||||
int (*write)(struct logger *lg, struct clientparam *param, const unsigned char *buf, int len);
|
||||
void (*close)(struct logger *lg);
|
||||
/* every second or so: rotation, flushing */
|
||||
void (*tick)(struct logger *lg, time_t t);
|
||||
int stacksize; /* the client thread stack its writing needs */
|
||||
int standard; /* kept open for the life of the process */
|
||||
int text; /* writes a line of text: errors can go there */
|
||||
};
|
||||
|
||||
struct logger {
|
||||
struct logger *next;
|
||||
const struct logtype *type;
|
||||
unsigned char *selector;
|
||||
void *data; /* the type's own */
|
||||
int refs;
|
||||
int errors; /* writes failed in a row */
|
||||
int failed; /* could not be reopened: lines go to standard error */
|
||||
time_t failtime;
|
||||
ROTATION rotation;
|
||||
int rotate, archiverc;
|
||||
unsigned char **archiver;
|
||||
time_t rotated; /* when the file in use was opened */
|
||||
int reopen; /* the rotation changed: the file name too */
|
||||
_3proxy_mutex_t mutex; /* writing, reopening */
|
||||
};
|
||||
|
||||
struct srvparam {
|
||||
struct sockfuncs so;
|
||||
struct srvparam *next;
|
||||
@@ -684,7 +726,7 @@ struct srvparam {
|
||||
_3proxy_mutex_t counter_mutex;
|
||||
_3proxy_sem_t childslots; /* maxchild of them, one held by each child */
|
||||
struct pollfd fds;
|
||||
FILE *stdlog;
|
||||
struct logger *logger; /* the log it writes to, held until srvfree() */
|
||||
unsigned char * target;
|
||||
#if defined SO_BINDTODEVICE || defined IP_BOUND_IF
|
||||
char * ibindtodevice;
|
||||
@@ -705,7 +747,6 @@ struct srvparam {
|
||||
struct auth *authfuncs;
|
||||
struct filter *filter;
|
||||
unsigned char * logformat;
|
||||
unsigned char * logtarget;
|
||||
unsigned char * nonprintable;
|
||||
uint16_t targetport;
|
||||
unsigned char replace;
|
||||
@@ -902,8 +943,8 @@ struct extparam {
|
||||
int poolmax, pooltimeout; /* threadpool: idle workers kept, -1 automatic */
|
||||
int gracetraf, gracenum, gracedelay;
|
||||
int maxseg;
|
||||
unsigned char *logname, **archiver;
|
||||
ROTATION logtype, countertype;
|
||||
unsigned char **archiver;
|
||||
ROTATION logtype, countertype; /* logtype: the rotation of the last log */
|
||||
char * counterfile;
|
||||
PROXYSOCKADDRTYPE intsa;
|
||||
#ifndef NOIPV6
|
||||
@@ -916,13 +957,12 @@ struct extparam {
|
||||
LOGFUNC logfunc;
|
||||
BANDLIMFUNC bandlimfunc;
|
||||
TRAFCOUNTFUNC trafcountfunc;
|
||||
unsigned char *logtarget, *logformat;
|
||||
unsigned char *logformat;
|
||||
struct logger *logger; /* the last log, the services' default */
|
||||
struct filemon * fmon;
|
||||
struct filter * filters;
|
||||
struct auth *authfuncs;
|
||||
FILE *stdlog;
|
||||
unsigned char **stringtable;
|
||||
time_t logtime;
|
||||
unsigned logdumpsrv, logdumpcli;
|
||||
char delimchar;
|
||||
struct nserver authnserver;
|
||||
@@ -933,7 +973,6 @@ struct extparam {
|
||||
freed when none does and it is no longer the one in force */
|
||||
int refs;
|
||||
struct hashtable pwl_table; /* users */
|
||||
int havelog; /* log was configured */
|
||||
int resolvmode; /* RESOLVE_*: the last read, each service taking the one read before it */
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user