log4j file is not getting created - spring-mvc

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

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

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

Application cannot create log file in UNIX?

I have developed a web project. Which is generating log file using log4j. But the same application is deployed in UNIX, it is not able to create log file also..
I'm new to unix. Why it is not creating log file?
This is the code....
log4j.rootLogger = INFO,CA, FA
#Console Appender
log4j.appender.CA = org.apache.log4j.ConsoleAppender
log4j.appender.CA.layout = org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern = %d %5p %c{1}:%L - %m%n
#File Appender
log4j.appender.FA = org.apache.log4j.FileAppender
log4j.appender.FA.File =correspondence.log
log4j.appender.FA.layout = org.apache.log4j.PatternLayout
log4j.appender.FA.layout.ConversionPattern = %d %5p [%t] - %m%n
It is creating log file in server installation folder. But not creating in UNIX.. Any changes I have to do?
try changing the line:
log4j.appender.FA.File =correspondence.log
to:
log4j.appender.FA.File = /tmp/correspondence.log
If it works, then create a log dir in the home directory of the user running the application server, chmod it at least to be executable and writable by owner and then put the log in that directory.

Resources