(30 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Fedora Log Files == | == Fedora Log Files == | ||
This document describes the guidelines for log file(s), for use and inclusion in Fedora packages. | This document describes the guidelines for log file(s), for use and inclusion in Fedora packages. | ||
For the purposes of these guidelines, a log file is defined as an text file that an application outputs into in the /var/log/ directory. | |||
As of Fedora 19 systemd journal persistancy has been enabled by default. | |||
Node This guidelines only applies if you are going to support additional optional syslog solutions such as rsyslog or syslog-ng in your package. | |||
== Log Files on the filesystem == | == Log Files on the filesystem == | ||
Line 8: | Line 15: | ||
Each log file in that directory must end with .log filename. | Each log file in that directory must end with .log filename. | ||
Each package that ships log | Each package that ships log file(s) must also ship a logrotation file that rotates the log file(s). | ||
== | == Logrotate file == | ||
If a package contains a logfile then it needs to also include a properly installed logrotate file. | |||
Each logrotate file must end with the filename .conf. It must be placed /etc/logrotate.d/ and must have 0644 filepermission and be owned by root. | |||
.. | |||
Here are examples of an logrotate file. | |||
Example minimal logrotate file | === Example minimal logrotate file === | ||
<pre> | <pre> | ||
Line 45: | Line 36: | ||
</pre> | </pre> | ||
Example minimal logrotate log file with user create mode | === Example minimal logrotate log file with user create mode === | ||
<pre> | <pre> | ||
Line 57: | Line 48: | ||
</pre> | </pre> | ||
Example minimal logrotate file with daemon restart | === Example minimal logrotate file with daemon restart === | ||
<pre> | <pre> | ||
Line 72: | Line 63: | ||
</pre> | </pre> | ||
Example minimal logrotate file with user create mode and daemon restart | === Example minimal logrotate file with user create mode and daemon restart === | ||
<pre> | <pre> | ||
Line 90: | Line 81: | ||
{{admon/tip|Debugging logrotate file|You can debug your logrotate file by running | {{admon/tip|Debugging logrotate file|You can debug your logrotate file by running | ||
<pre># logrotate -d -f /etc/logrotate.d/example.conf</pre>from the command line.}} | <pre># logrotate -d -f /etc/logrotate.d/example.conf</pre>from the command line.}} | ||
== Rsyslog file == | |||
If package wants to use rsyslog as an additional optional syslog solution it also needs to contain an rsyslog conf file. | |||
Each rsyslog file must end with the filename .conf. It must be placed /etc/rsyslog.d/ directory and must have 0644 filepermission and be owned by root. | |||
Here is an examples of rsyslog file. | |||
=== Example minimal rsyslog file === | |||
<pre> | |||
# Log example generated log messages to file | |||
:syslogtag, isequal, "[EXAMPLE]" /var/log/example/example.log | |||
& ~ | |||
</pre> | |||
{{admon/tip|Debugging rsyslog file|You can debug your ryslog file by running | |||
<pre># rsyslogd -f /etc/rsyslog.d/example.conf -N1</pre>from the command line.}} | |||
== Log Files Packaging == | |||
If an package is going to provide additional optional syslog support then they must be placed into a separate $name-<syslogging option> subpackage as in $name-rsyslog or $name-syslog-ng | |||
=== Example of rsyslog subpackage === | |||
<pre> | |||
Name: | |||
..... | |||
Source1: %{name}.logrotate | |||
%package example-rsyslog | |||
Summary: Rsyslog support for %{name} | |||
Group: System Environment/Base | |||
Requires: %{name} = %{version}-%{release} | |||
Requires: logrotate | |||
Requires: rsyslog | |||
%description example-rsyslog | |||
Rsyslog support for %{name} | |||
%install | |||
mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/log/%{name} | |||
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d | |||
%{__install} -p -D -m 0700 %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/%{name}.conf | |||
%files example-rsyslog | |||
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}.conf | |||
%dir %attr(0700,root,root) %{_localstatedir}/log/%{name} | |||
</pre> | |||
=== Example of rsyslog subpackage with additional rsyslog file === | |||
<pre> | |||
Name: | |||
..... | |||
Source1: %{name}.logrotate | |||
Source2: %{name}.rsyslog | |||
%package example-rsyslog | |||
Summary: Rsyslog support for %{name} | |||
Group: System Environment/Base | |||
Requires: %{name} = %{version}-%{release} | |||
Requires: logrotate | |||
Requires: rsyslog | |||
%description example-rsyslog | |||
Rsyslog support for %{name} | |||
%install | |||
mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/log/%{name} | |||
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d | |||
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/rsyslog.d | |||
%{__install} -p -D -m 0700 %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/%{name}.conf | |||
%{__install} -p -D -m 0700 %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/rsyslog.d/%{name}.conf | |||
%files example-rsyslog | |||
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}.conf | |||
%config(noreplace) %{_sysconfdir}/rsyslog.d/%{name}.conf | |||
%dir %attr(0700,root,root) %{_localstatedir}/log/%{name} | |||
</pre> | |||
=== Example of syslog-ng subpackage === | |||
<pre> | |||
Name: | |||
..... | |||
Source1: %{name}.logrotate | |||
%package example-syslog-ng | |||
Summary: Syslog-ng support for %{name} | |||
Group: System Environment/Base | |||
Requires: %{name} = %{version}-%{release} | |||
Requires: logrotate | |||
Requires: syslog-ng | |||
%description example-syslog-ng | |||
Syslog-ng support for %{name} | |||
%install | |||
mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/log/%{name} | |||
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d | |||
%{__install} -p -D -m 0700 %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/%{name}.conf | |||
%files example-syslog-ng | |||
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}.conf | |||
%dir %attr(0700,root,root) %{_localstatedir}/log/%{name} | |||
</pre> |
Latest revision as of 19:31, 19 March 2013
Fedora Log Files
This document describes the guidelines for log file(s), for use and inclusion in Fedora packages.
For the purposes of these guidelines, a log file is defined as an text file that an application outputs into in the /var/log/ directory.
As of Fedora 19 systemd journal persistancy has been enabled by default.
Node This guidelines only applies if you are going to support additional optional syslog solutions such as rsyslog or syslog-ng in your package.
Log Files on the filesystem
Packages with log files must reside in their own directory under /var/log which must be named /var/log/$package_name
Each log file in that directory must end with .log filename.
Each package that ships log file(s) must also ship a logrotation file that rotates the log file(s).
Logrotate file
If a package contains a logfile then it needs to also include a properly installed logrotate file.
Each logrotate file must end with the filename .conf. It must be placed /etc/logrotate.d/ and must have 0644 filepermission and be owned by root.
Here are examples of an logrotate file.
Example minimal logrotate file
/var/log/example/*log { missingok # If the log file is missing, go on to the next one without issuing an error message notifempty # Don't do any rotation if the logfile is empty compress # Compress older files with gzip delaycompress # Don't compress yesterdays files }
Example minimal logrotate log file with user create mode
/var/log/example/*log { missingok # If the log file is missing, go on to the next one without issuing an error message notifempty # Don't do any rotation if the logfile is empty compress # Compress older files with gzip delaycompress # Don't compress yesterdays files create 640 owner group # Set create mode immediately after rotation }
Example minimal logrotate file with daemon restart
/var/log/example/*log { missingok # If the log file is missing, go on to the next one without issuing an error message notifempty # Don't do any rotation if the logfile is empty compress # Compress older files with gzip delaycompress # Don't compress yesterdays files sharedscripts # Scripts are only run once for all files in directory postrotate /usr/bin/systemctl restart example.service 2>/dev/null || true endscript }
Example minimal logrotate file with user create mode and daemon restart
/var/log/example/*log { missingok # If the log file is missing, go on to the next one without issuing an error message notifempty # Don't do any rotation if the logfile is empty compress # Compress older files with gzip delaycompress # Don't compress yesterdays files create 640 owner group # Set create mode immediately after rotation sharedscripts # Scripts are only run once for all files in directory postrotate /usr/bin/systemctl restart example.service 2>/dev/null || true endscript }
Rsyslog file
If package wants to use rsyslog as an additional optional syslog solution it also needs to contain an rsyslog conf file.
Each rsyslog file must end with the filename .conf. It must be placed /etc/rsyslog.d/ directory and must have 0644 filepermission and be owned by root.
Here is an examples of rsyslog file.
Example minimal rsyslog file
# Log example generated log messages to file :syslogtag, isequal, "[EXAMPLE]" /var/log/example/example.log & ~
Log Files Packaging
If an package is going to provide additional optional syslog support then they must be placed into a separate $name-<syslogging option> subpackage as in $name-rsyslog or $name-syslog-ng
Example of rsyslog subpackage
Name: ..... Source1: %{name}.logrotate %package example-rsyslog Summary: Rsyslog support for %{name} Group: System Environment/Base Requires: %{name} = %{version}-%{release} Requires: logrotate Requires: rsyslog %description example-rsyslog Rsyslog support for %{name} %install mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/log/%{name} mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d %{__install} -p -D -m 0700 %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/%{name}.conf %files example-rsyslog %config(noreplace) %{_sysconfdir}/logrotate.d/%{name}.conf %dir %attr(0700,root,root) %{_localstatedir}/log/%{name}
Example of rsyslog subpackage with additional rsyslog file
Name: ..... Source1: %{name}.logrotate Source2: %{name}.rsyslog %package example-rsyslog Summary: Rsyslog support for %{name} Group: System Environment/Base Requires: %{name} = %{version}-%{release} Requires: logrotate Requires: rsyslog %description example-rsyslog Rsyslog support for %{name} %install mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/log/%{name} mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/rsyslog.d %{__install} -p -D -m 0700 %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/%{name}.conf %{__install} -p -D -m 0700 %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/rsyslog.d/%{name}.conf %files example-rsyslog %config(noreplace) %{_sysconfdir}/logrotate.d/%{name}.conf %config(noreplace) %{_sysconfdir}/rsyslog.d/%{name}.conf %dir %attr(0700,root,root) %{_localstatedir}/log/%{name}
Example of syslog-ng subpackage
Name: ..... Source1: %{name}.logrotate %package example-syslog-ng Summary: Syslog-ng support for %{name} Group: System Environment/Base Requires: %{name} = %{version}-%{release} Requires: logrotate Requires: syslog-ng %description example-syslog-ng Syslog-ng support for %{name} %install mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/log/%{name} mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d %{__install} -p -D -m 0700 %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/%{name}.conf %files example-syslog-ng %config(noreplace) %{_sysconfdir}/logrotate.d/%{name}.conf %dir %attr(0700,root,root) %{_localstatedir}/log/%{name}