How can I get my grails app to log in a way that shows up in the AWS Elastic Beanstalk 'logs' tab - grails

According to http://docs.amazonwebservices.com/elasticbeanstalk/latest/dg/index.html?using-features.loggingS3.title.html only log entries logged into Tomcat logs via java.util.logging will be made accessible. Grails uses Log4J. How would I best bridge the two? I do not want to have to ssh into the instance every time I want to look at a log message.

There is a Log4J JUL bridge.
See: https://forums.aws.amazon.com/thread.jspa?threadID=64008 for discussion
The bridge: http://people.apache.org/~psmith/logging.apache.org/sandbox/jul-log4j-bridge
The relevant config (in .properties format) seems to be:
log4j.appender.jul=org.apache.log4j.jul.JULAppender
log4j.appender.jul.layout=org.apache.log4j.PatternLayout
log4j.appender.jul.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger = DEBUG, jul
Try around with various Config.groovy translated versions of that and see if that gets you anywhere.

Related

migration from log4j1.x to log4j2

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.

Separate logging for rails application in tomcat

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.

Rails default server logs along with json logstash logs

I am working on Rails app. I installed logstash and with help of gem logstash-logger I am able to get json logs output to a file log/logstash_#{Rails.env}.log
But along with this I want to have previous default server logs too in a separate file log/{Rails.env}.log.
Is it possible to do it? If yes then how?
logstash-logger overrides Rails.logger in it's railtie.
Try adding an initializer with:
Rails.logger.extend(
ActiveSupport::Logger.broadcast(
Logger.new(Rails.root.join("log/#{Rails.env}.log"))
)
)
(this should run after logstash has been initialized)
For familiar rails logger you may want to use something like
ActiveSupport::TaggedLogging.new(
ActiveSupport::Logger.new(output_filename_here).tap{|l|
l.formatter = Rails.application.config.log_formatter
}
)
instead of Logger above (add your usual logging configuration).

Stackdriver logging in a Rails app in GKE is not working

Ruby 2.3.6, Rails 4.2.6, Stackdriver 0.15.0
Following the directions at https://cloud.google.com/logging/docs/setup/ruby, I've added the stackdriver gem to Gemfile. From what I can tell, I shouldn't need to do anything else.
However, I'm not seeing any log messages from within Rails showing up in Stackdriver. I've even tried execing a shell in the container, running bundle exec rails console, and explicitly logging with Rails.logger.error "this is a log message".
config.google_cloud.use_logging = true and config.log_level = :debug, FWIW.
UPDATE: I took a closer look at the logger instance with pp Rails.logger, and it contains this:
#resource=
#<Google::Cloud::Logging::Resource:0x0000558b075d1f50
#labels={:cluster_name=>"onehq-cluster", :namespace_id=>"default"},
#type="container">,
My container is running in the staging namespace, which would explain why I'm not seeing log messages. When I look in the Stackdriver log viewer in the default namespace, lo, there are logs. Unfortunately, sending all messages to default won't do me any good, because I have apps running in two namespaces, and I need to be able to tell them apart.
I tried adding additional configuration:
config.google_cloud.logging.monitored_resource.type = "container"
config.google_cloud.logging.monitored_resource.labels = { cluster_name: "my-cluster", namespace_id: "staging" }
And now Rails.logger.error "this is a log message" doesn't show up anywhere.
UPDATE 2: After much web searching, I managed to turn up https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues/2025 which suggests that the namespace to which log messages are sent is determined by the value of an environment variable, and that said env var is not being set automatically in GKE containers. (It has supposedly been resolved by https://github.com/GoogleCloudPlatform/google-cloud-ruby/pull/2071 but I don't think that's live yet, at least not in my cluster.) I'll try forcing the env var in my deployment file, and if that works I'll convert the last part of this to an answer.
After much web searching, I managed to turn up https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues/2025 which suggests that the namespace to which log messages are sent is determined by the value of an environment variable, and that said env var is not being set automatically in GKE containers. (It has supposedly been resolved by https://github.com/GoogleCloudPlatform/google-cloud-ruby/pull/2071 but I don't think that's live yet, at least not in my cluster.) I forced the env var in my deployment file, and IIRC that worked. (I no longer have access to that cluster, so I can't verify that.)
Google-Cloud-Env gem has released this morning the version (1.0.2) you may update your bundle.

Logging configuration completely ignored in Config.groovy when deployed as a war?

When I run my application with run-app, logging seems to work correctly. When I deploy as a WAR in tomcat, all my logging configuration is ignored, and I only see
LOGLEVEL logmessage
Example:
INFO Hello world
What could possibly be causing this? I tried deleting tomcat's logging.properties, but that didn't seem to do anything.
Even after wiping the logging entirely, I still see this in catalina.out, while my logs to a log file are written correctly. A plugin or library, likely, is screwing up my logging, but tracing it down at this point isn't worth it.

Resources