Log4J throws illegal char <:> exception while processing Appender File in Springboot WebApp - java

I am using Log4J along with Springboot in my J2EE based WebApp.
It throws illegal char <:> exception while processing Appender File.
Log4J version: 2.11.1
The logger properties in my application.properties file are as below
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n
logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n
logging.file=log\\web.log
I understand that it's because of the character colon ':' , but even after trying out different patterns, I still get the same error message.
I don't know where the ${sys:LOG_PATH} part is coming from and how to fix this.
Can someone please help.
Attaching the error stack trace as well.
Thanks in advance :)

Related

Having space in front of logged messages in logback

My Logback pattern in logback.xml file as follows
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} ${LOG_LEVEL_PATTERN:-%5p} %yellow([%X{Auth-Scopes:-},%X{Auth-Principal:-},%X{Auth-Organization:-}]) %magenta(${PID:-}) --- [%15.15t] %cyan(%-40.40logger{39}) : %m %n ${LOG_EXCEPTION_CONVERSION_WORD:-%xEx}</pattern>
My problem is there is space in front of log lines from above pattern as follows
2021-08-18 03:40:00.017 DEBUG [test-service,,,] [,,] 1 --- [test-7] a.b.c.Test : Test
I am still trying to figure out what this cause for some time. Any help would be really appreciated .
Last parameter causes the problem.
You can try this one;
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} ${LOG_LEVEL_PATTERN:-%5p} %yellow([%X{Auth-Scopes:-},%X{Auth-Principal:-},%X{Auth-Organization:-}]) %magenta(${PID:-}) --- [%15.15t] %cyan(%-40.40logger{39}) : %m ${LOG_EXCEPTION_CONVERSION_WORD:-%xEx} %n</Pattern>

Log4j2 SmtpAppender to include exceptions without the stack trace source code location

We have a SmtpAppender configured with a custom RateLimiter filter and ERROR log level, everything is working as expected except for the exceptions format, they are including the source code location which we would like to remove, we add such appender programmatically to each logger after the logging facility has been initialized, example of log:
2019-05-03 10:39:58,871 Thread-9 ERROR s.utils.Startup - Testing error
java.lang.RuntimeException: Testing error
at com.somepackage.SomeClass.lambda$enableEmailLogging$0(Startup.java:619) ~[classes/:?]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_212]
The ~[classes/:?] and [?:1.8.0_212] are annoying to us, also; in general we would like our logging to always include the exceptions which is well accomplished in our RollingRandomAccessFile appender as well, but having the same problem of stack trace source code location being included, here is also a snippet of our rolling file appender:
<Appenders>
<RollingRandomAccessFile name="RollingFile" fileName="/opt/tomcat/logs/some-webapp.log"
filePattern="/opt/tomcat/logs/some-webapp.log-%d{yyMMdd-HH}"
ignoreExceptions="false">
<PatternLayout>
<Pattern>%d{DEFAULT} %15.15t %-5p %15.15c - %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy/>
</Policies>
</RollingRandomAccessFile>
</Appenders>
I have looked all over for a way to accomplish this with no luck.
Changing the PatternLayout's pattern from:
%d{DEFAULT} %15.15t %-5p %15.15c - %m%n
to
%d{DEFAULT} %15.15t %-5p %15.15c - %m%n%throwable
and removing the option ignoreExceptions from the appenders seem to accomplish what I wanted.

After disabling console appender in log4j still getting info message in catalina.out

I initialize root logger with level ALL for R.
log4j.rootLogger=ALL, R
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d [%t] %-5p (%F:%L) - %m%n
log4j.appender.R.File=${catalina.home}/logs/synconextcontroller.log
log4j.appender.R.DatePattern='-'yyyyMMdd'.log'
log4j.appender.R.Threshold=ERROR
log4j.logger.org.apache.catalina=DEBUG, R
log4j.logger.org.hibernate=ERROR
log4j.logger.org.quartz=ERROR
log4j.logger.com.mchange=ERROR
jersey.level=INFO
Despite this, logs are getting written to file.
How can I prevent this from happening?

What are the possible reasons behind "log4j: Error Could not find value for key log4j.appender.SQL_APPENDER"

I am wondering why I have this error when deploying my web application.
log4j: Error Could not find value for key log4j.appender.SQL_APPENDER
Here is my log4j.properties file.
log4j.rootLogger=error, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Print the date in ISO 8601 format
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=application.log
log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
log4j.logger.org.hibernate.SQL=DEBUG, SQL_APPENDER
log4j.additivity.org.hibernate.SQL=false
Do I have to do some configuration in the server side? I am running my application on a Tomcat 7 server. I added this dependency to the pom.xml file:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
You need to define log.appender.SQL_APPENDER, since you assign it in the line
log4j.logger.org.hibernate.SQL=DEBUG, SQL_APPENDER
You are defining appender R but no SQL_APPENDER
As SJuan mentioned you need to define
log.appender.SQL_APPENDER
and that is done something like this :
log4j.appender.SQL_APPENDER=org.apache.log4j.RollingFileAppender
and might as well add these while you are at it...
log4j.appender.SQL_APPENDER.File=c:/EC_sql.log
log4j.appender.SQL_APPENDER.MaxFileSize=1000KB
log4j.appender.SQL_APPENDER.MaxBackupIndex=62
log4j.appender.SQL_APPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.SQL_APPENDER.layout.ConversionPattern=[%d] %5p [%t]
(%F:%L) - %m%n
Hope this helps someone!

Log4j SMTP Appender

Hi I am a novice and the application I am currently coding for uses struts 1.2 and java. We currently use Log4j for log files but I need to implement SMTP Appender so that our errors are emailed to us.
I've tried everything to get errors to be emailed with no luck. Below is our log4j.properties file.
Any suggestions?
Thanks!
log4j.rootLogger= INFO, stdout, logfile, mail
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
# Keep three backup files
log4j.appender.logfile.MaxBackupIndex=3
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - <%m>%n
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=C:/LOGS/WIRE.log
log4j.appender.logfile.MaxFileSize=2048KB
#email appender
log4j.appender.mail=org.apache.log4j.net.SMTPAppender
log4j.appender.mail.BufferSize=1
log4j.appender.mail.SMTPHost=smtp.serverhere.com
log4j.appender.mail.From=johndoe#serverhere.com
log4j.appender.mail.To=johndoe#serverhere.com
log4j.appender.mail.Subject=Application Error
log4j.appender.mail.threshold=error
log4j.appender.mail.layout=org.apache.log4j.PatternLayout
log4j.appender.mail.layout.ConversionPattern=%d %p [%c] - <%m>%n
# Hibernates use of the org.apache classes spews out stuff like mad.
log4j.logger.org.apache=INFO
# Springframework is very talkative too.
log4j.logger.org.springframework=INFO
# acegisecurity
#log4j.logger.org.acegisecurity = INFO
# Quartz trigger checking
log4j.logger.org.quartz.impl.jdbcjobstore=INFO
#log4j.logger.org.springframework.scheduling.quartz=INFO
By default, the appender only sends an email when something is logged at the ERROR or FATAL levels.
As a side note, it appears that your threshold property may have improper case. I believe:
log4j.appender.mail.threshold=error
should be
log4j.appender.mail.Threshold=error
Edit...
Log4j can be put into debug mode by configuring the log4j.debug configuration property. This might provide some output regarding the SMTP appender.
Define the root logger in error level and override this for selected packages. The mail appender will remain in the error level.
# Log appenders
#log4j.rootLogger=INFO, CONSOLE
log4j.rootLogger=ERROR, FILE, MAIL
# Log levels
log4j.logger.com.example.application=INFO
log4j.logger.com.example.application.package=DEBUG
# CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5r %-5p [%t] %c{2} - %m%n
log4j.appender.CONSOLE.Encoding=UTF-8
# FILE
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.File=/tmp/application.log
log4j.appender.FILE.MaxFileSize=1000KB
log4j.appender.FILE.MaxBackupIndex=99
log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5r %-5p [%t] %c{2} - %m%n
log4j.appender.FILE.Encoding=UTF-8
# MAIL
log4j.appender.MAIL=org.apache.log4j.net.SMTPAppender
log4j.appender.MAIL.BufferSize=1
log4j.appender.MAIL.SMTPHost=smtp.example.com
log4j.appender.MAIL.From=application#example.com
log4j.appender.MAIL.To=developer#example.com
log4j.appender.MAIL.Subject=Exception in Application
log4j.appender.MAIL.layout=org.apache.log4j.PatternLayout
log4j.appender.MAIL.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5r %-5p [%t] %c{2} - %m%n

Categories