Not able to create log file using Log 4j in Module 7 | Selenium Forum
M
Posted on 04/10/2016
I tried creating Log file using Log4j Jar file. I have imported Log4j jar file in reference library and placed log4j.properties file under SRC folder but on executing i get below error message in console

Error: log4j:WARN No appenders could be found for logger (devpinoyLogger).
log4j:WARN Please initialize the log4j system properly.

How can i resolve this issue ?

M
Replied on 04/10/2016

[quote:3dph6xdk]log4j:WARN No appenders could be found for logger (devpinoyLogger).
log4j:WARN Please initialize the log4j system properly.
[/quote:3dph6xdk]

this is just warning and can be ignored.

try this q/a follow the steps.

http://stackoverflow.com/questions/3495443/how-to-implement-use-log4j


M
Replied on 05/10/2016

Hi..Has this issue got resolved. I am also facing the same eroor. Log4.propert file I have used is :-
#Application Logs
log4j.logger.devpinoyLogger=DEBUG, dest1
log4j.appender.dest1=org.apache.log4j.RollingFileAppender
log4j.appender.dest1.maxFileSize=5000KB
log4j.appender.dest1.maxBackupIndex=3
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
log4j.appender.dest1.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %c %m%n
log4j.appender.dest1.File=D:\\TestData\\Logs\\Application.log
#do not append the old file. Create a new log file everytime
log4j.appender.dest1.Append=false

Kindly help.


M
Replied on 05/10/2016

has this folder been created before you run the log4j?

D:\\TestData\\Logs


M
Replied on 05/10/2016

Yes, I have created the folder before running log4J. I want my test logs to be created under the folder Logs.


M
Replied on 06/10/2016

follow the steps here

http://stackoverflow.com/questions/3495443/how-to-implement-use-log4j

if this doesn't work, tell me.


M
Replied on 06/10/2016

I have done few changes:-
[b:4wrdgkbn]1.Added BasicConfigurator.configure(); in my Test_Log4j Class

Logger APPLICATION_LOGS = Logger.getLogger("devpinoyLogger");
APPLICATION_LOGS.debug("hello");
APPLICATION_LOGS.debug("We are wrinting in to a log file");
APPLICATION_LOGS.debug("starting the test case xyz test");

2.Added below in Log4j Properties:-[/b:4wrdgkbn]
# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, A1

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
#log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

Now, the debug logs are getting printed in the cosole. The waring is not coming, but I want to create log files in my folder which is not getting generated.

Please suggest.


M
Replied on 07/10/2016

use these and tell me if its working.

[quote:34yrxrir]#Application Logs
log4j.logger.devpinoyLogger=DEBUG, dest1
log4j.appender.dest1=org.apache.log4j.RollingFileAppender
log4j.appender.dest1.maxFileSize=5000KB
log4j.appender.dest1.maxBackupIndex=3
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
log4j.appender.dest1.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %c %m%n
log4j.appender.dest1.File=C:\\testing\\Application.log
#do not append the old file. Create a new log file everytime
log4j.appender.dest1.Append=false

[/quote:34yrxrir]

[code:34yrxrir]package com.soapuitutorial.propertie;
import org.apache.log4j.Logger;


public class Logging_Example {

/**
* @param args
*/
public static void main(String[] args) {

// add log4j.jar
// add log4j.propertie directly inside the src folder
// create the object in the code
Logger APPLICATION_LOGS = Logger.getLogger("devpinoyLogger");
APPLICATION_LOGS.debug("hello");
APPLICATION_LOGS.debug("We are wrinting in to a log file");
APPLICATION_LOGS.debug("starting the test case xyz test");


}

}
[/code:34yrxrir]