Now In the production.rb in environments I write code
config.logger = Logger.new("#{Rails.root.to_s}/log/production.log", 'daily')
So that do log file will rotate every day at midnight.
How do I write code for rotate log with define time?
https://stackoverflow.com/a/4883967/1241447 - using system logrotate.d
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html#method-c-new - using built-in functionality
Related
I am using Rails Logger with shift_age = 'daily', looks like it does not rotate the log file when the size is small or if logs do not populate daily.
It works fine in my production environment, but in staging environment it does not rotate, below is my code.
FileUtils.touch(Rails.root.join('log/custom_log.json'))
##custom_logger = Logger.new(Rails.root.join('log/custom_log.json'), shift_age = 'daily')
Does this work?
FileUtils.touch(Rails.root.join('log', 'custom_log.json'))
##custom_logger = Logger.new(Rails.root.join('log',
'custom_log.json'), 'daily')
This example from the docs might also work:
file = File.open(Rails.root.join('log', 'custom_log.json'), File::WRONLY | File::APPEND | File::CREAT)
logger = Logger.new(file)
Also note that most log examples seem to create files with the .log file format.
I'm a newbie in ruby on rails. I struggled to find the solution for writing multiple logs and the daily rolling file appender.
The output will be like that: (logfile in folder {my project}/log)
db_access.log
db_access.log.20200513
...
user_operator.log
user_operator.log.20200513
...
And I have found a simple solution.
Add gem 'multi_logger' in Gemfile and run bundle install.
Create file logger.rb in /config/initializers and add below code
MultiLogger.add_logger('user_operation', shift_age: 'daily', shift_period_suffix: '%Y%m%d')
MultiLogger.add_logger('db_access', shift_age: 'daily', shift_period_suffix: '%Y%m%d')
Now, you can write log in your project
Rails.logger.user_operation.info 'your_message'
Rails.logger.db_access.info 'your_message'
(write log in level info)
You can also customize your log by adding other options: logdev, shift_age, shift_size, level, progname, formatter, datetime_format, shift_period_suffix
I've been asked to remove any images duplicated in the war file our grails app is packaged in. The documentation suggests this is possible via the grails.assets.excludes property in Config.groovy, but it doesn't clearly state how this property is supposed to work.
Here's what the documentation says:
Optionally, assets can be excluded from processing if included by your require tree. This can dramatically reduce compile time for your assets. To do so simply leverage the excludes configuration option:
grails.assets.excludes = ["tiny_mce/src/*.js"]
The example is totally unclear to me. I've tried several permutations of this expression with no success; image assets continue to be preprocessed, causing duplicates of all of them in the resulting war file. Here are a few settings I've tried:
grails.assets.excludes = ["tiny_mce/src/*.jpg", "tiny_mce/src/*.jpg"]
grails.assets.excludes = ["<app_name>/src/*.jpg", "<app_name>/src/*.jpg"]
grails.assets.excludes = ["/images/*.jpg", "/images/*.png"]
grails.assets.excludes = ["**/*.jpg", "/images/**"]
What am I missing? How do I tell the asset pipeline to skip precompiling images?
This works for me:
grails.assets.excludes = ["**/*.jpg","**/*.png"]
I can't get any rule based on images/ to work...
First of all, i don't have access to the php.ini in the webserver.
In my local server I put date.timezone = "Europe/Lisbon" in my php.ini.
Is it possible to change this in .htaccess? or, what is the alternative?
At the moment I get this error in web server for phpmailer():
Strict Standards: date(): It is not safe to rely on the system's timezone settings. ....
On second thought, ini_set may not be the best way to go. Apparently E_STRICT standards say that you should use date_default_timezone_set instead.
Try something like:
date_default_timezone_set('Europe/Lisbon');
$tz = date_default_timezone_get();
More info can be found here about the issue:
http://answers.google.com/answers/threadview/id/739376.html
And here for the default_timezone functions:
http://us2.php.net/manual/en/function.date-default-timezone-set.php
Edit: I found this little gem while I was browsing github.
// has to be set to reach E_STRICT compatibility, does not affect system/app settings
date_default_timezone_set(date_default_timezone_get());
This seems like the best solution.
Try ini_set at the top of your script.
ini_set("date.timezone", "Europe/Lisbon");
Your problem is not difficult. You can change date.timezone in the php.ini and delete => ; <= is the comment in the php.ini
for example
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone =Europe/Paris
http://www.commentcamarche.net/forum/affich-14406518-probleme-avec-l-heure-en-php
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.
config.logger = Logger.new(config.log_path, 50, 1.megabyte)
but beware that multiple mongrels can have issues with this.
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.
I prefer a monthly log file in my production.rb file
config.logger = Logger.new(config.log_path, 'monthly')
Or even better, if all your environments are on either Mac or Linux, and have /usr/sbin/rotatelogs, just use that. It's much more flexible, and doesn't have the data loss issue that logrotate has (even if you use copytruncate).
Add this inside config/application.rb (or just config/environments/production.rb if you only want rotation in prod):
log_pipe = IO.popen("/usr/sbin/rotatelogs #{Rails.root}/log/#{Rails.env}.%Y%m%d.log 86400", 'a')
config.logger = Logger.new(log_pipe)
(From this blog post)
Or you can delegate logging to syslog