Clear specific logs when using `rake log:clear` #8964

Merged
merged 1 commit into from Jan 16, 2013

Conversation

Projects
None yet
2 participants
Contributor

mdespuits commented Jan 16, 2013

There are times when I want to clear only one of the logs or just two of the logs rather than all of the logs. You can now accomplish this with:

$ LOGS=test rake log:clear

Or multiple:

$ LOGS=test,staging rake log:clear

Wasn't sure the best way to test this. I couldn't find any tests for it, so if there are any suggestions, I am more than willing to add them or provide a sample app with this successfully running in it.

Can you explain your use case a little bit more please? I wasn't even aware that we had a task for clearing the logs, since a simple rm logs/* would do most of the time I think (I know this doesn't rm, but there's no much difference on the result).

Contributor

mdespuits commented Jan 16, 2013

Use case:

I want to preserve the contents development.log and clear the test.log and stage.log. Right now, the rake log:clear task will completely empty all of the log files. I wanted a way to limit which logs were cleared when running this task.

Yes, there isn't much difference in the result, I just like using rake when I can.

@carlosantoniodasilva carlosantoniodasilva commented on an outdated diff Jan 16, 2013

guides/source/command_line.md
@@ -355,7 +355,7 @@ rake assets:clean # Remove compiled assets
rake assets:precompile # Compile all the assets named in config.assets.precompile
rake db:create # Create the database from config/database.yml for the current Rails.env
...
-rake log:clear # Truncates all *.log files in log/ to zero bytes
+rake log:clear # Truncates all *.log files in log/ to zero bytes (Narrow specific files: `LOGS=test,development rake log:clear`
@carlosantoniodasilva

carlosantoniodasilva Jan 16, 2013

Owner

Please use narrow (lowercase).

@carlosantoniodasilva carlosantoniodasilva and 1 other commented on an outdated diff Jan 16, 2013

railties/lib/rails/tasks/log.rake
@@ -1,9 +1,23 @@
namespace :log do
- desc "Truncates all *.log files in log/ to zero bytes"
+ desc "Truncates all *.log files in log/ to zero bytes (Narrow specific files: `LOGS=test,development rake log:clear`"
@carlosantoniodasilva

carlosantoniodasilva Jan 16, 2013

Owner

How about specify which logs with LOGS=test,development, wdyt?

@mdespuits

mdespuits Jan 16, 2013

Contributor

I like that a lot better. I'll update docs and desc

@mdespuits

mdespuits Jan 16, 2013

Contributor

Wait, is that clear enough that you can specify other environments?

@carlosantoniodasilva

carlosantoniodasilva Jan 16, 2013

Owner

I think so, other ideas?

@mdespuits

mdespuits Jan 16, 2013

Contributor

No, I really like your phrasing better. Just making sure clarity is good enough.

@carlosantoniodasilva

carlosantoniodasilva Jan 16, 2013

Owner

We could also use LOGS=file,names,here, not sure it's necessary though :)

@mdespuits

mdespuits Jan 16, 2013

Contributor

Maybe staging instead of development, but I don't think there's a huge benefit to any specific set of words.

@carlosantoniodasilva carlosantoniodasilva commented on an outdated diff Jan 16, 2013

railties/lib/rails/tasks/log.rake
end
end
+
+ def log_files
+ if ENV['LOGS'].nil?
+ FileList["log/*.log"]
+ else
+ ENV['LOGS'].split(',')
+ .map { |file| "log/#{file.strip}.log" }
+ .select { |file| File.exists?(file) }
+ end
@carlosantoniodasilva

carlosantoniodasilva Jan 16, 2013

Owner

I think inverting the logic would be simpler. Also fix the indentation.

Contributor

mdespuits commented Jan 16, 2013

Would you like me to update the CHANGELOG as well?

Yes, a changelog entry would be good.

Contributor

mdespuits commented Jan 16, 2013

CHANGELOG update added

carlosantoniodasilva merged commit f5aa4d9 into rails:master Jan 16, 2013

Thanks.

mdespuits deleted the unknown repository branch Jan 17, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment