xref: /freebsd/usr.sbin/newsyslog/newsyslog.8 (revision 24e4dcf4ba5e9dedcf89efd358ea3e1fe5867020)
1.\" This file contains changes from the Open Software Foundation.
2.\"
3.\" Copyright 1988, 1989 by the Massachusetts Institute of Technology
4.\"
5.\" Permission to use, copy, modify, and distribute this software
6.\" and its documentation for any purpose and without fee is
7.\" hereby granted, provided that the above copyright notice
8.\" appear in all copies and that both that copyright notice and
9.\" this permission notice appear in supporting documentation,
10.\" and that the names of M.I.T. and the M.I.T. S.I.P.B. not be
11.\" used in advertising or publicity pertaining to distribution
12.\" of the software without specific, written prior permission.
13.\" M.I.T. and the M.I.T. S.I.P.B. make no representations about
14.\" the suitability of this software for any purpose.  It is
15.\" provided "as is" without express or implied warranty.
16.\"
17.Dd September 22, 2025
18.Dt NEWSYSLOG 8
19.Os
20.Sh NAME
21.Nm newsyslog
22.Nd maintain system log files to manageable sizes
23.Sh SYNOPSIS
24.Nm
25.Op Fl CFNPnrsv
26.Op Fl a Ar directory
27.Op Fl d Ar directory
28.Op Fl f Ar config_file
29.Op Fl I Ar signal
30.Op Fl S Ar pidfile
31.Op Fl t Ar timefmt
32.Op Oo Fl R Ar tagname Oc Ar
33.Sh DESCRIPTION
34The
35.Nm
36utility should be scheduled to run periodically by
37.Xr cron 8 .
38When it is executed it archives log files if necessary.
39If a log file
40is determined to require archiving,
41.Nm
42rearranges the files so that
43.Dq Va logfile
44is empty,
45.Dq Va logfile Ns Li \&.0
46has
47the last period's logs in it,
48.Dq Va logfile Ns Li \&.1
49has the next to last
50period's logs in it, and so on, up to a user-specified number of
51archived logs.
52It is also possible to let archived log filenames be created using the
53time the log file was archived instead of the sequential number using
54the
55.Fl t
56option.
57Optionally the archived logs can be compressed to save
58space.
59.Pp
60A log can be archived for three reasons:
61.Bl -enum -offset indent
62.It
63It is larger than the configured size (in kilobytes).
64.It
65A configured number of hours have elapsed since the log was last
66archived.
67.It
68This is the specific configured hour for rotation of the log.
69.El
70.Pp
71The granularity of
72.Nm
73is dependent on how often it is scheduled to run by
74.Xr cron 8 .
75Since the program is quite fast, it may be scheduled to run every hour
76without any ill effects,
77and mode three (above) assumes that this is so.
78.Sh OPTIONS
79The following options can be used with
80.Nm :
81.Bl -tag -width indent
82.It Fl f Ar config_file
83Instruct
84.Nm
85to use
86.Ar config_file
87instead of
88.Pa /etc/newsyslog.conf
89for its configuration file.
90.It Fl a Ar directory
91Specify a
92.Ar directory
93into which archived log files will be written.
94If a relative path is given,
95it is appended to the path of each log file
96and the resulting path is used as the directory
97into which the archived log for that log file will be written.
98If an absolute path is given,
99all archived logs are written into the given
100.Ar directory .
101If any component of the path
102.Ar directory
103does not exist,
104it will be created when
105.Nm
106is run.
107.It Fl d Ar directory
108Specify a
109.Ar directory
110which all log files will be relative to.
111To allow archiving of logs outside the root, the
112.Ar directory
113passed to the
114.Fl a
115option is unaffected.
116.It Fl v
117Place
118.Nm
119in verbose mode.
120In this mode it will print out each log and its
121reasons for either trimming that log or skipping it.
122.It Fl n
123Cause
124.Nm
125not to trim the logs, but to print out what it would do if this option
126were not specified.
127This option implies the
128.Fl r
129option.
130.It Fl r
131Remove the restriction that
132.Nm
133must be running as root.
134Of course,
135.Nm
136will not be able to send a signal to
137.Xr syslogd 8
138so this option should only be used in debugging.
139.It Fl s
140Specify that
141.Nm
142should not send any signals to any daemon processes that it would
143normally signal when rotating a log file.
144For any log file which is rotated, this option will usually also
145mean the rotated log file will not be compressed if there is a
146daemon which would have been signalled without this option.
147However, this option is most likely to be useful when specified
148with the
149.Fl R
150option, and in that case the compression will be done.
151.It Fl t Ar timefmt
152If specified
153.Nm
154will create the
155.Dq rotated
156logfiles using the specified time format instead of the default
157sequential filenames.
158The filename used will be kept until it is deleted.
159The time format is described in the
160.Xr strftime 3
161manual page.
162If the
163.Ar timefmt
164argument is set to an empty string or the string
165.Dq DEFAULT ,
166the default built in time format
167is used.
168If the
169.Ar timefmt
170string is changed the old files created using the previous time format
171will not be automatically removed (unless the new format is very
172similar to the old format).
173This is also the case when changing from sequential filenames to time
174based file names, and the other way around.
175The time format should contain at least year, month, day, and hour to
176make sure rotating of old logfiles can select the correct logfiles.
177.It Fl C
178If specified once, then
179.Nm
180will create any log files which do not exist, and which have the
181.Sy C
182flag specified in their config file entry.
183If specified multiple times, then
184.Nm
185will create all log files which do not already exist.
186If log files are given on the command-line, then the
187.Fl C
188or
189.Fl CC
190will only apply to those specific log files.
191.It Fl F
192Force
193.Nm
194to trim the logs, even if the trim conditions have not been met.
195This
196option is useful for diagnosing system problems by providing you with
197fresh logs that contain only the problems.
198.It Fl N
199Do not perform any rotations.
200This option is intended to be used with the
201.Fl C
202or
203.Fl CC
204options when creating log files is the only objective.
205.It Fl P
206Prevent further action if we should send signal but the
207.Dq pidfile
208is empty or does not exist.
209.It Fl R Ar tagname
210Specify that
211.Nm
212should rotate a given list of files, even if trim conditions are not
213met for those files.
214The
215.Ar tagname
216is only used in the messages written to the log files which are
217rotated.
218This differs from the
219.Fl F
220option in that one or more log files must also be specified, so that
221.Nm
222will only operate on those specific files.
223This option is mainly intended for the daemons or programs which write
224some log files, and want to trigger a rotate based on their own criteria.
225With this option they can execute
226.Nm
227to trigger the rotate when they want it to happen, and still give the
228system administrator a way to specify the rules of rotation (such as how
229many backup copies are kept, and what kind of compression is done).
230When a daemon does execute
231.Nm
232with the
233.Fl R
234option, it should make sure all of the log files are closed before
235calling
236.Nm ,
237and then it should re-open the files after
238.Nm
239returns.
240Usually the calling process will also want to specify the
241.Fl s
242option, so
243.Nm
244will not send a signal to the very process which called it to force
245the rotate.
246Skipping the signal step will also mean that
247.Nm
248will return faster, since
249.Nm
250normally waits a few seconds after any signal that is sent.
251.It Fl I Ar signal
252Specify signal to send for entries that do not have signal configured.
253This option accepts either a signal number or a name as argument.
254The default value is HUP.
255.It Fl S Ar pidfile
256Use
257.Ar pidfile
258as
259.Xr syslogd 8 Ns 's
260pidfile.
261.El
262.Pp
263If additional command line arguments are given,
264.Nm
265will only examine log files that match those arguments; otherwise, it
266will examine all files listed in the configuration file.
267.Sh FILES
268.Bl -tag -width /usr/local/etc/newsyslog.conf.d -compact
269.It Pa /etc/newsyslog.conf
270.Nm
271configuration file
272.It Pa /etc/newsyslog.conf.d
273By default each file in this directory ending in '.conf' and not beginning with
274a '.' will be included by the default
275.Pa newsyslog.conf .
276.It Pa /usr/local/etc/newsyslog.conf.d
277By default each file in this directory ending in '.conf' and not beginning with
278a '.' will be included by the default
279.Pa newsyslog.conf .
280.El
281.Sh COMPATIBILITY
282Previous versions of the
283.Nm
284utility used the dot (``.'') character to
285distinguish the group name.
286Beginning with
287.Fx 3.3 ,
288this has been changed to a colon (``:'') character so that user and group
289names may contain the dot character.
290The dot (``.'') character is still
291accepted for backwards compatibility.
292.Sh SEE ALSO
293.Xr bzip2 1 ,
294.Xr gzip 1 ,
295.Xr xz 1 ,
296.Xr zstd 1 ,
297.Xr syslog 3 ,
298.Xr newsyslog.conf 5 ,
299.Xr chown 8 ,
300.Xr syslogd 8
301.Sh HISTORY
302The
303.Nm
304utility originated from
305.Nx
306and first appeared in
307.Fx 2.2 .
308.Sh AUTHORS
309.An Theodore Ts'o ,
310MIT Project Athena
311.Pp
312Copyright 1987, Massachusetts Institute of Technology
313