0

I have my systemd service file, which runs guncorn app, and that generates logs to a specific folder, But i want to create a logrotate for service file that generate my logs on daily basis and create separate folder based on the date. Like: master_std_err_dd-mm-yyyy.log

Here is my Systemd service:

[Unit]
Description=master daemon
After=network.target

[Service]
WorkingDirectory=/home/ubuntu/master
User=ubuntu
Group=ubuntu
Environment="PYTHONPATH=/home/ubuntu/venv"
ExecStart=/home/ubuntu/venv/bin/gunicorn -b 127.0.0.1:8000 app:app
StandardOutput=file:/home/ubuntu/logs/master_std_out.log
StandardError=file:/home/ubuntu/logs/master_std_err.log
KillMode=process
Restart=always
TimeoutSec=infinity
RestartPreventExitStatus=255

[Install]
WantedBy=multi-user.target
Alias=master.service

This file generates my logs at /home/ubuntu/logs/master_std_err.log

But I want to make a specific folder for this file and separate by date on daily basis.

/home/ubuntu/logs/master_std_out.log {
    daily
    create 644 root root
    rotate 12
    dateext
    dateformat -%d%m%Y
    postrotate
        echo "A rotation just took place." | mail root
    endscript
}

I have created a logrotate conf, but it didn't create any log.

0

To rotate the logs into a different directory, you want to use olddir in your logrotate configuration:

olddir directory

Logs are moved into directory for rotation. The directory must be on the same physical device as the log file being rotated, unless copy, copytruncate or renamecopy option is used. The directory is assumed to be relative to the directory holding the log file unless an absolute path name is specified. When this option is used all old versions of the log end up in directory. This option may be overridden by the noolddir option.


I have created a logrotate conf, but it didn't create any log.

If you run logrotate -d _filename_, logrotate will process the file in debug mode, telling you why it's making the decisions it makes, so you can usually see why a file isn't getting rotated. No actual rotation will be done in debug mode, so this is safe to run as often as needed to get your config working properly. Alternately, you can use -v instead of -d if you want it to perform a real rotation while also telling you what it's doing and why.

1
  • I tried using logrotate -f FILENAME this will forcefully rotate the file and creates new file specified by date, but i want it to automatically create as per the day. – Rajat jain Feb 9 '19 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.