This is my log4j.properties file:
# LOG4J configuration
log4j.rootLogger=INFO, Appender1,Appender2
log4j.logger.org.hibernate=info
log4j.logger.org.quartz=info
log4j.appender.Appender1=org.apache.log4j.ConsoleAppender
log4j.appender.Appender1.layout=org.apache.log4j.PatternLayout
log4j.appender.Appender1.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n
log4j.appender.Appender2=org.apache.log4j.FileAppender
log4j.appender.Appender2.File=/home/diego/proyect/log/general.log
log4j.appender.Appender2.layout=org.apache.log4j.PatternLayout
log4j.appender.Appender2.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n
Locally works on my windows machine, but on the server (ubuntu 16.04) side the web application cannot write on the .log file, already modified permissions for the file:
chmod 777 /home/diego/proyect/log/general.log
this is the resuls of ls -lhs on the log directory:
-rwxrwxrwx 1 diego diego 0 Nov 16 14:23 general.log
Also not sure which is the tomcat user on the server.
I solved, it seems I need to add the log4j.properties files into the classpath, my project has the following structure:
main
src/main/java
src/main/resources/log4j.properties
webapp
WEB-INF/log4j.properties
So I put the file under src/main/resources directory and it works.
The fact that it is working on local environment mean that your configuration is correct. I think there is an issue with your environment. Here are a few things to check:
Does the tomcat process has permissions to write in file . i.e. are administrator rights required to write?
Check that there aren't any temporary files near tomcat's directories which may be preventing your changes.
Check that you don't have any other log4j config files on your classpath, as these could override your log4j file and preventing it . To double check this, you could try temporarily removing your log4j.properties file .
Related
I am using AWS Step Functions Local for testing Step Functions on my local machine, but the level of logging has significantly increased the time for my test suite to run. I cannot find any configuration options on the AWS website to control the log level so I have been trying to roll my own with no success.
The logging I am trying to hide looks like this:
2022-12-15 12:11:36.562: CreateStateMachine => {"requestClientOptions":{"readLimit":131073,"skipAppendUriPath":false},"requestMetricCollector":null,"customRequestHeaders":null,"customQueryParameters":null,"cloneSource":null,"sdkRequestTimeout":null,"sdkClientExecutionTimeout":null,"name":"<MY STEP FUNCTION NAME","definition":"{MY STEP FUNCTION DEFINITION}"...}
2022-12-15 12:11:36.782: [200] CreateStateMachine <= {"sdkResponseMetadata":null,"sdkHttpMetadata":null,"stateMachineArn":"arn:aws:states:eu-west-1:123456789012:stateMachine:MY_STEP_FUNCTION_NAME","creationDate":1671106296763}
I downloaded the Zip file containing the Step Functions Local JAR file, extracted the zip file, extracted StepFunctionsLocal.jar, and found there was a log4j.properties file. "Excellent!", I thought, I can provide my own configuration file and it will be great. So I created a Docker image with the following Dockerfile:
FROM amazoncorretto:11
WORKDIR /jar
COPY . /jar
RUN yum -y install unzip zip && yum -y clean all && rm -rf /var/cache
RUN mkdir -p /jar/extracted
RUN unzip StepFunctionsLocal.zip -d /jar/extracted
ENV SFN_MOCK_CONFIG=""
ENV LAMBDA_ENDPOINT=""
ENV AWS_DEFAULT_REGION=""
EXPOSE 8083
CMD ["java", "-Dlog4j2.configurationFile=file:/jar/log4j.properties", "-jar", "/jar/extracted/StepFunctionsLocal.jar"]
With the following log4.properties file which is in the same directory as the Dockerfile:
# console is set to be a ConsoleAppender.
log4j.appender.console=org.apache.log4j.ConsoleAppender
# console uses PatternLayout.
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
log4j.appender.APPLOG=amazon.platform.logging.PeriodicConcurrentFileAppender
log4j.appender.APPLOG.layout=amazon.platform.logging.SanitizingPatternLayout
log4j.appender.APPLOG.File=../logs/application.log
log4j.appender.APPLOG.DatePattern='.'yyyy-MM-dd-HH
log4j.appender.APPLOG.layout.ConversionPattern=%p %d{D/HH:mm:ss:SSS} %t %c - %m%n
# Set root logger level to INFO and its only appender to console.
log4j.rootLogger=ERROR, APPLOG
#log4j.logger.com.amazon.coral.reflect=WARN
#log4j.logger.httpclient.wire=OFF
# Enable this to see everything that httpclient does.
#log4j.logger.org.apache.commons.httpclient=WARN
#log4j.logger.org.springframework=WARN
#log4j.logger.org.apache=WARN
#log4j.logger.com.amazonaws.swf.console=ERROR
#log4j.logger.com.amazonaws.console.auth=ERROR
This is the same file I found in the extracted StepFunctionsLocal.jar except all of the lines which configure the log level have been commented out and the root logger level set to ERROR.
I built the image and ran it, but the same logging still appeared. At this point I'm stumped. Am I going about this the right way? Have I missed something obvious?
I'm currently writing a bash script to copy log files from one host server to another host server. I have an application installed and running on a Websphere application server. The script would copy both the Server logs as well as application log to a remote staging directory. I can retrieve the server log files' path using wsadmin. I'm facing a challenge to retrieve the application log file path from log4j.properties under WEB-INF/classes directory.
Currently, I'm hard coding the log file path in a csv and from the csv, I'm retrieving it and using the command :
find <LOG_FILE_PATH> -type f -name $filename -newermt "$user_date_from" ! -newermt "$user_date_to"
Sample csv file content:
user#server_IP,AppServerName,LogFilePath,IdentifierToDifferentiateWhetherFileisServerLogOrAppLog
I want to do away with this csv file hard coding option because:
I know that log4j.properties already stores the log file paths.
I want to retrieve the log file path from log4j.properties instead at runtime, just to make sure that I do not have to update the csv hard coded value in case there is any change in log4j.properties.
Sample log4j.properties file content:
logFileLoc=<AbsoluteLogFilePath>
log4j.rootLogger=INFO,RollingAppender,stdout
log4j.appender.RollingAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RollingAppender.File=${logFileLoc}/<logFileName>.log
log4j.appender.RollingAppender.append=true
log4j.appender.RollingAppender.DatePattern='.'yyyy-MM-dd
log4j.appender.RollingAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.RollingAppender.layout.ConversionPattern=[%p] %d %c %M - %m%n
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{2}:%L - %m%n
So, I wonder if there exists any wsadmin like admin service available with log4j that can serve my purpose? Any help will be much appreciated.
I'm having a code running on Linux, and using Tomcat 9.
I'm using log4j as the to record the log.
However, whenever I delete the file manually from the log folder :
/var/lib/tomcat9/logs , once I access the application, the log is not created.
Same goes when I deploy my code and accessing the application on 11.10.2019, today when I access the application again, log was not created.
But program working-I saw new record added today.
FYI, on 11 Oct 2019, archieve file was created.
-rw-r----- 1 tomcat tomcat 615 Oct 11 17:12 Restful.log.gz
May I know is there any other setting or configuration that I missed out during my deployment.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/var/lib/tomcat9/logs/Restful.log
log4j.appender.file.MaxFileSize=100MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.Append=true
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
I have maven application with log4j.properties in it with setting to write the logs to a specified file instead of console. When I run the EAR on one of the websphere servers it is creating the file as expected and writing logs to it. But, when I am running the same EAR on other webspehere server it is writing to console instead of writing the logs to the specified file. I have checked the permissions and everything seems to be fine. Please help me in identifying what the issue is. Thanks in advance.
# CONSOLE APPENDER (stdout)
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Threshold=DEBUG
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d] [%t] %-5p %20c - %m%n
# ROLLING FILE APPENDER (on the file system) for memberpolicyattributesservice code
log4j.appender.xxxxService=org.apache.log4j.RollingFileAppender
log4j.appender.xxxxService.Threshold=DEBUG
log4j.appender.xxxxService.File=/var/logs/xxxServer1/xxxServiceLog.log
log4j.appender.xxxxService.layout=org.apache.log4j.PatternLayout
log4j.appender.xxxxService.layout.ConversionPattern=%d{MM-dd#HH:mm:ss} %-5p (%13F:%L) %3x - %m%n
log4j.appender.xxxxService.MaxFileSize=10000KB
log4j.appender.xxxxService.MaxBackupIndex=30
log4j.appender.xxxxService.layout=org.apache.log4j.PatternLayout
log4j.appender.xxxxService.layout.ConversionPattern=[%d] [%t] %-5p %20c - %m%n
# ROLLING FILE APPENDER (on the file system) for hiberate, open source code log files
log4j.appender.open_source_code=org.apache.log4j.RollingFileAppender
log4j.appender.open_source_code.layout=org.apache.log4j.PatternLayout
log4j.appender.open_source_code.Threshold=DEBUG
#message format:YYYY-MM-DD HH:mm:ss,ms [ThreadId] <PRIORITY> classname.message
log4j.appender.open_source_code.layout.ConversionPattern=%d [%t]<%-5p> %c.%m \r\n
#file that will be logged to
log4j.appender.open_source_code.File=/var/logs/xxxServer1/open_source_code.log
log4j.appender.open_source_code.Append=true
log4j.appender.open_source_code.MaxFileSize=1024KB
log4j.appender.open_source_code.MaxBackupIndex=5
#turn on log4j verbose mode
log4j.debug = true
# Set root logger level to INFO and its appender to DSInstrumentor,stdout.
log4j.rootLogger=DEBUG,stdout,xxxxService
# YOUR CATEGORIES (to customize logging per class/pkg/project/etc)
log4j.category.fatal=FATAL,xxxxService
log4j.category.error=ERROR,xxxxService
#This will also enable the logging for all the children (packages and classes) of this package
log4j.logger.com.xxxxx=ALL,xxxxService
# Print only messages of level INFO in the open source code
log4j.logger.org=INFO,open_source_code
You have multiple loggers defined in your root logger (DEBUG, stdout, xxxxService) but the xxxxService loggers look like they're bound to the file system on one of the systems:
log4j.appender.open_source_code.File=/var/logs/xxxServer1/open_source_code.log
Make sure that path is valid for each server in your WAS cluster.
As a side note, you should probably avoid using debug and stdout on a remote server. This is fine for local development in your workstation, but not on a remote box. Instead, provide different log4j properties on your various deployment tiers. This lets you customize the log location or appender (say c:\temp or CONSOLE on your desktop, but /var/logs ... on all remote machines) as well as your log levels (DEBUG for desktop, maybe INFO for QA or Staging, and WARN or ERROR for Production).
I'm not able to get output with priority lower than INFO from a webapp. Everything other is being logged correctly.
Log shows the following, yet actual settings put in to the file are seem to be ignored:
INFO: Initializing log4j from
[/var/lib/tomcat-7-main/webapps/myapp/WEB-INF/log4j.properties]
Content of the file is following:
log4j.rootLogger=TRACE, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.conversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.logger.my.webapp=TRACE
log4j.logger.org.springframework.security=TRACE
This configuration works correctly with another machine running openSUSE (while the issue is related to machine running Gentoo). Both of them running Tomcat 7 under Oracle JDK 1.7. Any ideas?