log4j floods my console - spring-mvc

This is the log4j.properties that i have in my app
log4j.rootLogger=B C
log4j.logger.A=INFO, A1
log4j.debug=false
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %C - %m%n
log4j.logger.B=INFO, A2
log4j.debug=false
log4j.appender.A2=org.apache.log4j.FileAppender
log4j.appender.A2.file=PRIME-log.txt
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%d [%t] %-5p %C - %m%n
log4j.logger.C=INFO, A3
log4j.appender.A3=org.apache.log4j.FileAppender
log4j.appender.A3.file=employee_pass_regeneration-log.txt
log4j.appender.A3.layout=org.apache.log4j.PatternLayout
log4j.appender.A3.layout.ConversionPattern=%d [%t] %-5p %C - %m%n
I only want File appender so i only use that , but some how my console is always flooded with DEBUG messages which i have never used
8704 [http-8080-2] DEBUG
org.springframework.web.servlet.view.JstlView
- Rendering view with name 'passIndex' with model null and static attributes
{}
I guess these are all system messages , but with these debug messages its really hard to debug actually i mean i cannot find my own sysouts i tried log4j.debug=false but still i get these messages

I got rid of debug messages ... in one particular file i had this
BasicConfigurator.configure();
This used to send all DEBUG messages to console

First of all make sure the property files you're looking at is the one read by your application.
System.out.println(this.getClass().getClassLoader().getResource("commons-logging.properties").toString());
System.out.println(this.getClass().getClassLoader().getResource("log4.jeroen").toString());
System.out.println(this.getClass().getClassLoader().getResource("log4j.properties").toString());
System.out.println(this.getClass().getClassLoader().getResource("org/apache/log4j/Logger.class").toString());
System.out.println(this.getClass().getClassLoader().getResource("org/apache/commons/logging/Log.class").toString());
Then make sure your have the debug level in the root of your logger:
log4j.rootLogger=INFO, stdout

Related

log4j not dsplaying the mapped urls in my controller

I am completely new to Spring MVC and log4j.
In a project that I referred, log4j outputs all the mapped URLs in the console at server startup.
But when I tried, it is not displaying anything about the controller methods.
I tried to change the level from INFO to DEBUG but that's too deep and not what I needed.
I wrote a single API for example purpose.
sample api
And these are my log4j properties
log4j.rootLogger=INFO, stdout, file
#log4j.rootLogger=DEBUG, stdout, file
# Direct log messages to stdout
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{yyyy-MM-dd
HH:mm:ss} %-5p %c{1}:%L - %m%n
### direct messages to file or.log ###
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=${user.home}/Documents/rough/
hermesTmp/hermes.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy
HH:mm:ss,SSS} %5p %c{1} - %m%n
log4j.appender.file.append=true
log4j.appender.file.MaxFileSize=10000KB
log4j.appender.file.MaxBackupIndex=10
This is my output
doesnt show mapped url
I need the API to be listed as shown in the project I referred
Working code's output
Any suggestions...?
Thanks in advance..
The debug() method you are using on the log object in your controller will log on DEBUG level. So you can either change the method you invoke to info():
log.info("Everything will work this way")
Or you can change the level in log4j configuration to:
log4j.rootLogger=DEBUG, stdout, file
You can check out the documentation here

log4j file is not getting created

I have created log4j properties file within resource folder.Here is my log4j properties file code.
# LOG4J configuration
log4j.rootLogger = INFO, Appender1, Appender2
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 = C:/arnab/Logs/llllooooogggooo.log
log4j.appender.Appender2.layout = org.apache.log4j.PatternLayout
log4j.appender.Appender2.layout.ConversionPattern = %-7p %d [%t] %c %x - %m%n
but the problem is in my destination folder log4j file is not getting created. I am using JBoss server.I tried a lot but did not get any result. Can anyone help me pls?
The log4j.properties file should be placed in the proper classpath.
If you are using maven project, then it should be under, src/main/resources/. Make sure you have the following dependencies, available in the application classpath,
jboss-logmanager
jboss-logging
slf4j-log4j2

How to configure log4j

How to configure log4j to show only my
log.debug("test log");
messages in console without other system generated information?
It's very disturbing when in small app your console is messed with tons of useless ( at least for me) information like
DEBUG org.springframework.beans.CachedIntrospectionResults: Getting BeanInfo for class [org.thymeleaf.spring4.view.ThymeleafView]
my log4j.properties file:
log4j.rootLogger=DEBUG, stdout, file
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{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
You can use the LoggerMatchFilter and DenyAllFilter to restrict your logging appender to messages coming from your code only.
LoggerMatchFilter filter = new LoggerMatchFilter();
filter.setLoggerToMatch("Your.Root.Namespace");
filter.setAcceptOnMatch(true);
log4j.appender.stdout.addFilter(filter); // Match your messages only.
log4j.appender.stdout.addFilter(new DenyAllFilter()); // Don't match anything else.
Is your application using log4j or yet to configure??
log4j configure steps
If already log4j is in use, change the logger level to ERROR
Check whether your applications is using any xml configuration file for log4j or properties file so you can change in it.
logger level configuration steps.

Logging in Custom Jar in Jasper reports

I have included a custom jar for one of my jasper reports and it is working fine.Now for debugging purposes I want to implement log4j/slf4j in my classes in this custom jar so that when report is previewed in Jaspersodt Studio or run on JasperSoft server i can see the logging statements in a file.
Right now I have added all configuration but loggers are not printing in the file.My guess is that log4j is not getting triggered.
1)Is there any more setting/configuration is required?
2) I checked Jaspersoft server has default implementation for log4j and it logs but only various queries.Is there any particular setting/logger to set so that it includes custom jar loggers as well?
Below log4j.properties is put into resources folder of my maven project(custom jar)
log4j.rootLogger=DEBUG, stdout, file
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{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\log4j-application.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
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
EDIT:
Below is Java code.This is exported in a jar and added in classpath in my jasper project.When I preview my report chart is created and this customizer is excuted but I do not see any log statements in the file I have given in log4j.properties above :
public class BarChartDemo {
static Logger LOGGER = Logger.getLogger(BarChartDemo.class);
public void customize(JFreeChart chart, JRChart jasperChart) {
LOGGER.debug("debug");
LOGGER.info("info");
LOGGER.warn("warn");
LOGGER.error("error");
?/customizer code
}
}

How to configure log4qt to append logs

I am using log4qt with RollingFileAppender in my QT application. Everytime I restart my application logs are not appended to the log file, the file is simply overwritten.
Below is my log4qt.properties file.
log4j.rootLogger = DEBUG, File
log4j.appender.File=org.apache.log4j.RollingFileAppender
log4j.appender.File.File=logs/log.out
log4j.appender.File.MaxFileSize=3072KB
log4j.appender.File.MaxBackupIndex=3
log4j.appender.File.layout=org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern=%d [%t] [%p] %m%n
I tried to add the append property log4j.appender.File.Append=true , but i got error Property 'append' does not exist.
By exploring the code, I myself figured out the property that needs to be configured for appending the logs to the file.
The correct property is:
log4j.appender.File.AppendFile=true

Resources