Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is log4j's default log file dumping path

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!!

like image 437
manisha Avatar asked Jun 27 '13 06:06

manisha


People also ask

Where is log4j log file location Windows?

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.

Where is Apache log4j located?

Locate the log4j. xml file under the oarm/WEB-INF/classes/ directory. Update the log output path for each appender.

How do you set log file path in log4j properties dynamically?

System. setProperty("{my. log", "C:/logfile. log");


2 Answers

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/

like image 106
Juned Ahsan Avatar answered Oct 05 '22 22:10

Juned Ahsan


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

like image 22
Jubin Patel Avatar answered Oct 05 '22 22:10

Jubin Patel