Hi i am new to programming concepts and i am tend to work out something with log4j. So i am reading Log4j tutorials where i found the following code:
package test; import org.apache.log4j.Logger; import java.io.*; import java.sql.SQLException; public class Log4jExample { /* Get actual class name to be printed on */ static Logger log = Logger.getLogger(Log4jExample.class.getName()); public static void main(String[] args)throws IOException,SQLException { log.debug("Hello this is an debug message"); log.info("Hello this is an info message"); } }
But after running this in eclipse i am not able to locate the generated log file. Can anybody tell where is the file being dumped? Also help me with some best sites wherefrom i can learn Log4j and Java Doc from the scratch. Thanks!!
log file location is Install Dir /server/logs. If you are using IBM® WebSphere® Application Server, the default xxx . log file location is WebSphere Install Dir /profiles/AppSrv01/logs. The location of the xxx log file is determined by the log4j.
Locate the log4j. xml file under the oarm/WEB-INF/classes/ directory. Update the log output path for each appender.
System. setProperty("{my. log", "C:/logfile. log");
To redirect your logs output to a file, you need to use the FileAppender and need to define other file details in your log4j.properties/xml file. Here is a sample properties file for the same:
# Root logger option log4j.rootLogger=INFO, file # Direct log messages to a log file log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=C:\\loging.log log4j.appender.file.MaxFileSize=1MB log4j.appender.file.MaxBackupIndex=1 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
Follow this tutorial to learn more about log4j usage:
http://www.mkyong.com/logging/log4j-log4j-properties-examples/
You have copy this sample code from Here,right?
now, as you can see there property
file they have define, have you done same thing? if not then add below code in your project with property file for log4j
So the content of log4j.properties file would be as follows:
# Define the root logger with appender file log = /usr/home/log4j log4j.rootLogger = DEBUG, FILE # Define the file appender log4j.appender.FILE=org.apache.log4j.FileAppender log4j.appender.FILE.File=${log}/log.out # Define the layout for file appender log4j.appender.FILE.layout=org.apache.log4j.PatternLayout log4j.appender.FILE.layout.conversionPattern=%m%n
make changes as per your requirement like log
path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With