log4j not dsplaying the mapped urls in my controller - spring-mvc

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

Related

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.

Weblogic 12C sending logs to syslog

I want to send my weblogic log to syslog. here is what I have done so far.
1.Included following log4j.properties in managed server classpath -
log4j.rootLogger=DEBUG,syslog
log4j.appender.syslog=org.apache.log4j.net.SyslogAppender
log4j.appender.syslog.Threshold=DEBUG
log4j.appender.syslog.Facility=LOCAL7
log4j.appender.syslog.FacilityPrinting=false
log4j.appender.syslog.Header=true
log4j.appender.syslog.SyslogHost=localhost
log4j.appender.syslog.layout=org.apache.log4j.PatternLayout
log4j.appender.syslog.layout.ConversionPattern=[%p] %c:%L - %m%n
2. added following command to managed server arguments -
-Dlog4j.configuration=file :<path to log4j properties file> -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger -Dweblogic.log.Log4jLoggingEnabled=true
3. Added wllog4j.jar and llog4j-1.2.14.jar into domain's lib folder.
4.Then, from Admin console changed logging information by doing the following. "my_domain_name"--->Configuration--->Logging--->(Advanced options)-->Logging implementation: Log4J
Restart managed server.
I used this as refernce. But didnt get anaything in syslog(/var/log/message). What am I doing wrong?
I would recommend a couple items to check:
Remove the space in DEBUG, syslog in the file
Your last two server arguments have a space between the - and the D so make sure that wasn't just a copy and paste error in this post.
Double check that the log files are in the actual classpath.
Double check from a ps command, that the -D options made it correctly into the start command that was executed.
Make sure that the managed server has a copy of the JARs correctly as they would get synchornized from admin during the restart.
Hopefully something in there will help or give an idea of what to look for.
--John
I figured out the problem. My appender was working fine, the problem was in rsyslog.conf. Just uncommented following properties
# Provides UDP syslog reception
#$ModLoad imudp
#$UDPServerRun 514
We were appending the messages, but the listner was abesnt, so it didnt knew what to do with it.
and from *.debug;mail.none;authpriv.none;cron.none /var/log/messages it figures out where to redirect any (debug in this case) information to messages file.

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

log4j floods my console

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

Resources