Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to delete rails log file after certain size

I have a daemon that runs constantly which fills up the log file(development.log or production.log) pretty quickly. What is the best way to delete the log file after certain size or delete the portion before certain day.

like image 550
Tam Avatar asked Jun 24 '09 07:06

Tam


People also ask

Can I delete development log?

you can delete the file itself if you are not going to need the history. Restart server and it will be automatically created back again. If you don't want to delete the file, emptying it is perfectly fine. Save this answer.

How do I delete a log file?

del *.log /a /s /q /f Step 1: Also run Command Prompt as administrator. Step 2: Type wevtutil el and press Enter to list all the logs. Step 3: TYpe wevtutil cl + the name of the log you want to delete and press Enter to remove the log file.

Where are rails logs stored?

In a Rails app, logs are stored under the /log folder. In development mode, the development. log file is used & you see log output on the terminal you're running rails server on.

What are rails logs?

Rails uses six different log levels: debug, info, warn, error, fatal, and unknown. Each level defines how much information your application will log: Debug: diagnostic information for developers and system administrators, including database calls or inspecting object attributes. This is the most verbose log level.


2 Answers

config.logger = Logger.new(config.log_path, 50, 1.megabyte)

but beware that multiple mongrels can have issues with this.

like image 77
srboisvert Avatar answered Sep 22 '22 15:09

srboisvert


The best way is to set up log rotation, but how you do this is very platform dependent, so you should add a comment about what you're using, both for development and production.

For our apps running on Linux, we have a file /etc/logrotate.d/appname for each app, that looks something like this:

/path/to/rails_root_for_app/log/production.log {
    daily
    missingok
    rotate 7
    compress
    delaycompress
    notifempty
    create 640 capistrano capistrano
}

This will move the log into a new file once a day, keeping a compressed backup file for each of the last 7 days.

If you just want to empty the file without keeping any of the data in it while the daemon is running, simply do this from a shell:

> /path/to/rails_root_for_app/log/development.log

This will truncate the file to 0 bytes length.

like image 28
Lars Haugseth Avatar answered Sep 22 '22 15:09

Lars Haugseth