I am running Go binary as a service, and created a log file owned by syslog to maintain all logs.
This is my service file::
[Unit] Description=myapp [Service] Type=simple Restart=always RestartSec=30 WorkingDirectory= /home/go/src/myapp ExecStart=/home/go/src/myapp/myapp # myapp.log owned by syslog PermissionsStartOnly=true ExecStartPre=/bin/mkdir -p /var/log/myapp ExecStartPre=/bin/chown syslog:adm /var/log/myapp ExecStartPre=/bin/chmod 755 /var/log/myapp StandardOutput=syslog StandardError=syslog SyslogIdentifier=myapp [Install] WantedBy=multi-user.target
After this using rsyslog to manage syslogs, created a file inside /etc/rsyslog.d/myapp.conf with the following content:
if $programname == 'myapp' then /var/log/myapp/myapp.log & stop
After this I restarted service.It creates a log file for me. I have two questions regarding log file, as follows::
- Now I have to flush all log file data after every 15 days. Is there any method to do this??
- There are some api which will give response in every 3 minutes, so Is there any way to restrict some api from generating logs??
I am doing all this using systemd. Please suggest me if there method to create this type of log file attached with systemd service.