Skip to content

Instantly share code, notes, and snippets.

@partho222
Last active February 7, 2022 15:30
Show Gist options
  • Save partho222/d9e7079949ba799813b642dc40298be5 to your computer and use it in GitHub Desktop.
Save partho222/d9e7079949ba799813b642dc40298be5 to your computer and use it in GitHub Desktop.
Fetch program specific log from syslog to own log file
### Create rsyslog entry to catch log data [based on 'pgpool' name] in '/etc/rsyslog.d/pgpool2.conf'
if ( $programname == "pgpool" ) then {
action(type="omfile" fileOwner="postgres" fileGroup="postgres" fileCreateMode="0644" file="/var/log/pgpool2/pgpool2.log") stop
}
### Create logrotate configuration in '/etc/logrotate.d/pgpool2.conf'
/var/log/pgpool2/pgpool2.log {
daily
rotate 30
compress
delaycompress
notifempty
missingok
dateext
dateformat -%d%m%Y
copytruncate
create 0644 postgres postgres
}
REF:
https://en.linuxportal.info/tutorials/web-hosting/other/rotate-and-output-log-files-using-the-logrotate-program
https://www.tecmint.com/install-logrotate-to-manage-log-rotation-in-linux/
https://linuxconfig.org/logrotate
https://unix.stackexchange.com/questions/33447/why-we-should-use-create-and-copytruncate-together
### re-init rsyslog
# pkill -HUP rsyslog
### restart pgpool & rsyslog
# service rsyslog restart
# service pgpool2 restart
### cleanup log file [OPTIONAL]
# truncate -s 0 {log_file} EX: truncate -s 0 /var/log/syslog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment