We have three apps running in tomcat at different context path. I am using the default context settings in context.xml. We would like one one of the applications that logs to STDOUT to be able to log to its own file.
It is a ruby on rails application that creates the logger as below. It is built as war using jruby file and deployed to tomcat.
if ENV["LOG_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
We would like to redirect the output from the app to go to it's own file. At the moment, all output from the rails application goes to localhost.date.txt file. Other apps also log to the same file. For instance, a grails app logs unhandled exceptions to the same file.
Questions:
What is the easiest way to redirect the log output to STDOUT from an app at context path /rails/search it's own file without changing the application code?
I have tried with log4j.jar being copied to the appropriate folders if they exist or create the folders and copy of they dont as per the docmentation on tomcat website without much luck.
How can I stop the app at context /grails/hello to stop logging to the localhost.date.txt file.
I have disabled root logging to STDOUT in grails app log4j config, but it still logs unhandled exceptions. In its log file I have restricted the stacktrace to 5 lines, but in localhost.date.txt file it still prints the full stacktrace. I can disable all logging to consoleHandler, but I cannot do it unless I solve the first question. So any help is appreciated.
Things Tried:
Use log4j and slf4j to redirect logs to their own file using swallowOutput on context
Create new tomcat9 handler, but could'nt marry it to the logging class for rails app
Added properties files at appName/WEB_INF/classes/logging.properties and the file is created but no output is logged to the file.
Related
we are trying to migrate log4j version 1.x to 2.x because of log4j vulnerability. but after migration logs are not getting printed as previous. we have on file in which all console logs (system out) get printed and we have another file which uses TimedRollingFileAppender through java code to write to a file (this appender is in java note in log4j2 xml). but with log4j2 all logger logs coming into console file as well, which is supposed to write only system out logs. when we remove log4j2.xml file all logs comes in debug mode in both the files and when we provide log4j2.xml all logs come in Error mode in both files. we are blocked, anyone can please help here.
Currently the application that I'm working on is using Ruby on Rails. The application use delayed_job.log file to log the delayed job activity. However, the application is hosted in Openshift environment, using pod, and if the pod is deleted, and if a new pod is created, the application will make a new delayed_job.log file. One of the proposed solution from an engineer in the company is to write the log in terminal output. How can I do that? The goal is to save the information that written in delayed_job.log file to terminal output, so that I can see the log in the future, I can check the log, even the log from the deleted pod, using Kibana, instead of delayed_job.log file. Any help is appreciated.
Update :
We tried to put Delayed::Worker.logger = Rails.logger in delayed_job_config.rb but still did not work
You can change the logger in config/initializers/delayed_job_config.rb to something like:
Delayed::Worker.logger = Logger.new(STDOUT)
I have a jruby/rails (4.1) app that I want to deploy through Tomcat. I made the app log through stdout by adding
config.logger = Logger.new(STDOUT)
in config/application.rb, and the log lines are going to catalina.log.
We would like the app logs to go to a separate Tomcat logfile. Is it possible? how can it be configured?
Thanks!
if you do not set config.logger at all ... it will log to where servlet log goes
so simply do not do anything at all with config.logger (just leave the default) and it should work (assuming JRuby-Rack of course). otherwise there are 2 options :
use a Java logging library (in case of TC that is either JUL or Log4J) and configure JRuby-Rack to delegate
or simply config.logger = Logger.new('logs/rails.log') in this case make sure you set a formatter to include timestamps
NOTE: be aware that in the first case the Java logging library will receive all logs from Rails at the info level (loggers are not mapped "1-to-1") ... this might change in a future JRuby-Rack 1.2 release.
My rails app running in development environment stopped logging all of a sudden and I am not able to figure out why.
I tried logging into a new file by doing
config.logger = Logger.new('log/temp.log')
config.log_level = :debug
But still no luck. The new file temp.log was created but nothing is logged in the file. The thing is this happens on my development server running nginx (I run my rails app using "rails s -d" on this server). The exact same files, when I run on my local machine (my own computer), logging works fine.
So I feel the reason logging is not working is because of something specific to the server, but then I didn't do anything much on the server (e.g. I didn't install new gems, etc.) Logging has been working fine until few days ago.
When I go to rails console
rails c
> Rails.logger.debug "hello"
=> true
I do get "hello" logged into 'log/temp.log' specified above in config file.
I think permission on log directory or file is ok. What else could be wrong?
I believe it's a locking issue which you might be able to solve after removing the call to the logger which causes this.
I ran into this issue with Redmine 1.x,
I found newrelic_rpm entry in the production.log, saying it didn't run, and 1 line of a Redmine plugin init.
After removing both, newrelic_rpm from the environment.rb (config.gem line), and the plugin logger init message, the logging facility appears to be restored and log entries are appearing again.
I am running a Rails application on Apache using mod_passenger. I would like Rails.logger calls to write to the Apache error log rather than to the application's log file in log/production.log.
How can I do this?
In your config/environments/production.rb file you can add something like:
config.logger = Logger.new("/var/log/apache2/error.log")
Of course your app will need to have permissions to such a file. In addition intermixing Apache errors with your apps logs is definitely not a good idea.
This doesn't answer your question directly but I've just run a little test and STDERR.puts "meep" ended up in Apache's error log while using mod_passenger.
Perhaps then you could point config.logger at STDERR?