migration from log4j1.x to log4j2 - 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.

Related

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.

Unable to automatically update log4j configuration with the External Configuration Reload Plugin

I recently added the External Configuration Reload Plugin to my Grails 2.3.11 project which is using standard log4j logging. I then tried adding the following snippet to my external config.groovy file:
log4j = {
debug 'grails.app'
}
At this point, I saw the below INFO Log Message:
java 2016-09-13 17:31:02,202 [Timer-0] INFO reloadconfig.ReloadConfigService -
Detected changed configuration in preprod-Config.groovy, reloading configuration
However, I did not start receiving DEBUG log messages at this time. When I restarted the application, DEBUG log messages started coming.
I also tried adding this list to my (internal) config.groovy and restarting, but it did not resolve the problem:
grails.plugins.reloadConfig.notifyPlugins = ["LoggingGrailsPlugin", "Log4j", "log4j"]

Log file not updated after manually writing into it

I have a Rails application running under Puma which is configured to log to a file called puma.stdout.log. I also have a Amazon Cloudwatch Logs agent that is monitoring this file so that I can access these logs for all my EC2 instances in the AWS Cloudwatch console.
When I write manually to this log file, it stops getting updated. When I open the log file, the last line is the line I added even though more logs should appear. Timestamps and file size don't change either.
The weird thing is: Cloudwatch is still getting updated with new logs from the agent monitoring this particular log file and the application runs just fine, so Puma keeps logging to this file but I can't see the changes.
When I restart Puma, I can see new logs into this log file and everything is back to normal.
Why can't I see this log file updated after writing manually to it?

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

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.

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