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:
Vladimir DubrovinandClaude Opus 5.5 committed 2026-10-23 11:44:55 +03:00
1 parent 57818ad497
commit d613750b94
14 files changed
+996 -415

No files matched your search

+9 -1
View File
@@ -344,7 +344,15 @@ proxy on a client with FTP proxy support. Username format is one of
\fBY\fR Annually
.br
if logfile is not specified logging goes to stdout. You can specify individual logging options for gateway by using -l
option in gateway configuration.
option in gateway configuration: -l takes the same arguments, -l@ident, -l&odbc_string, -lradius or -lfilename, and -l
alone is stdout.
.br
A log is opened once for the same argument, whether given by log or by -l, and shared by every service using it; it
is kept open over a configuration reload while some service still uses it, and closed once none does. stdout,
stderr and syslog are opened at startup and never closed. rotate and archiver apply to the file of the last log
command. A log which fails to be written is reopened, and if it cannot be, its records go to stderr while it is
retried every minute. Errors and warnings with no connection go to stderr; after daemon (or as a Windows service)
nothing goes to stdout or stderr: logging to stdout is none, and errors go to the last log configured.
.br
log command supports same format specifications for filename template
as "logformat" (if filename contains \'%\' sign it\'s believed to be template).