seriously sir your tutorial got me out from 24 hrs wasted on checking from every where but your simple method solve my trouble of log 4j2 just 20 minutes thank you so much
Am tied up watching all log4j videos and didn't any solution for making log 4j in maven project. But from this video I was successfully created logs without any errors. Thank you so much for making this video sir....
This is exactly what I was looking for. This playlist is very helpful, helped me to PRACTICE before going out for interview. But in my opinion, this is not a beginner course......
This is a great "how to" video. What I am struggling to find is anything that tells me "when to". Can you give some real-world examples of what you should actually put in log messages of each level? Should we log every action, such as text entry and button-clicks? Should we put a log instruction in each method in our POM files? I'm looking for actual examples rather than technical instructions. Is there anywhere I can find "good practice" advice on deciding on logging messages?
Phil In a Selenium Java project using Log4J, it's essential to log messages appropriately based on their significance. Here are real-world examples for each log level: TRACE: Use this for very detailed messages that are useful for debugging. Example: logger.trace("Entering method loginUser (). User ID: {}", userId); DEBUG: Ideal for logging detailed information during development and testing. Example: logger.debug("Entered username: {}", username); INFO: Use this for general information about application flow. Example: logger.info("User {} logged in successfully.", username); WARN: Indicates potential issues that may need attention. Example: logger.warn("User {} attempted to access a restricted page.", username); ERROR: For logging error events that might still allow the application to continue running. Example: logger.error("Failed to find element by ID: {}", elementId); FATAL: For serious errors that might cause the application to terminate. Example: logger.fatal("System crash due to unhandled exception: {}", exception.getMessage()); Should You Log Every Action? Text Entry and Button Clicks: It is not necessary to log every single action, such as every text entry or button click, as this can lead to excessive log volume and make it difficult to find important information. Instead, focus on logging significant actions, like: User logins Form submissions Errors or exceptions Logging in Page Object Model (POM) Method Logging: It is advisable to log significant events within methods in your POM files, but avoid cluttering every method with log statements. Focus on: Entry and exit points of methods Key actions (e.g., navigating to a page, submitting a form) Errors or exceptions Good Practices for Logging Messages Clarity: Ensure log messages are clear and provide context. Consistency: Use a consistent format for log messages across your application. Avoid Sensitive Information: Do not log sensitive data like passwords or personal user information. Log Levels: Use the appropriate log level to reflect the severity of the message -
@@RaghavPal Thank you so much. You're amazing! I'd like to suggest you do a video on this. It's incredibly hard to find this kind of information. I've been looking for months. It would be very valuable and unique. I can't be the only one looking for this guidance. All the information out there is technical. There is barely anything practical like your answer here.
Very nice explanation, but a beginner's question, what is log4j's use in selenium automation scripting? didnt understand that.could you please explain.
Meena Log4j is a Java-based logging utility that allows developers to log events in their application. Why is Log4j used in Selenium? Log4j is used in Selenium to: Debug issues that arise during test execution Report errors and exceptions that occur during test execution Monitor test execution and provide insights into test performance How is Log4j used in Selenium? Log4j is configured using a properties or XML file, and is used to log events and errors during test execution. It can be used in conjunction with a testing framework like TestNG or JUnit.
Hi Raghav, First thanks for all efforts for us. I am facing a issue. As following this clip Log file is getting generate in logs folder but logs are not getting append inside the file. It show blank, where as logs are showing on console. Please guide on this. Thanks.
Is it possible to add multiple value for key?, I want to display log for multiple packages. How can I achieve this? I have created framework for my project which had multiple packages.
Hi Sathya, I have not tried this but you can create multiple log files. This may helpful - stackoverflow.com/questions/27941144/how-to-create-multiple-log-files-using-log4j examples.javacodegeeks.com/enterprise-java/log4j/log4j-writing-different-log-files-example/
@@RaghavPal These example explains log4j. Can u help me to find a solution for multiple packages? As Sathya said, Even i Want to integrate into the framework .
Sowjanya If your Run As menu in Eclipse IDE only shows "Run Configurations", but no Java application, here are a few things you can do: 1. Make sure that the Java project is properly configured. You can do this by right-clicking on the project and selecting "Properties". In the Properties window, select the "Run/Debug" tab and make sure that the "Project JDK" and "Project SDK" are set to the correct versions. 2. Make sure that the Java application is executable. You can do this by right-clicking on the Java file and selecting "Run As" > "Java Application". If the application does not start, it is likely not executable. 3. Make sure that the Java application is selected in the Run As menu. You can do this by clicking on the "Run Configurations" menu and selecting the Java application from the list. 4. If you are still having trouble, you can try creating a new Java project and see if that fixes the problem. Here are some additional things to check if you are still getting the error: * Make sure that the Java project is open. * Make sure that the Java application is in the project's source folder. * Make sure that the Java application has a main method. * Make sure that the Java application is not a library project. If you are still having trouble, you can try the following: 1. Restart Eclipse IDE. 2. Clear the Eclipse IDE cache. 3. Uninstall and reinstall Eclipse IDE. If you are still having trouble, please contact Eclipse support for help. Here are the steps on how to clear the Eclipse IDE cache: 1. Open Eclipse IDE. 2. Go to "Window" > "Preferences". 3. In the Preferences window, select "General" > "Workspace". 4. Click on the "Clear Cache" button. 5. Click on the "Apply" button and then the "OK" button. I hope this helps!
HI Raghav, MyLog file got created after program execution. but nothing is writing there. I can see logs only in console. Please help me on this. Note: I am not using Maven instead Java Project only.
Hi Raghav, I have done as you explained but in log4j2 properties, you mentioned the package name as demo.. If you want to use the same logger obj out of other java packages, it is not writing the logs in the file but in console it works. Can you help me out in this???
Hi Raghav, When I run the same code, I’m not getting any error but still log folder is not generated and also I got only logger.error and logger.fatal messages but not getting info and warn messages. Could you please suggest me? Thanks.
Thank you so much for this video but one question I have related to this... How we can generate different files in logs folder with timestamps...i want to implement in my framework
Hi Amit, pls check stackoverflow.com/questions/44753863/log4j-properties-create-new-log-file-with-timestamp-for-every-run#:~:text=You%20need%20to%20write%20(or,file%20hits%20the%20size%20limit
How to use Log4j in full-fledged selenium framework? As you used demo package in your example while in a framework there are multiple packages. Other than this do we not require to read the property file?
Hi Raghav, I followed your step exactly as showed in video, but still I am not getting trace, info and warn logs as well as not getting "log" folder and MyLogs file as well. kindly let me know how to fix it?
Hi Raghav, Thanks for this video which is generating logs for one of the class only. But If we want to generate for multiple classes then?? how dynamically we call this logger class / object? Please comment on this.
I created class in src/test/java i am not getting a file and I tried in src/main/java then I try to run but it's showing run configuration is not showing java application
Mounika It seems you're encountering an issue with Eclipse not showing the "Run as Java Application" option. Let's troubleshoot this: 1. Check Your Main Class: - Ensure that your main class has the correct syntax for the `main` method: ```java public static void main(String[] args) { // Your code here } ``` - Make sure the `String[] args` parameter is included. 2. Create a New Run Configuration: - Right-click on your Java file. - Choose "Run As" > "Run Configurations." - Select "Java Application" and click "New." - Configure the run settings and click "Run." 3. Shortcut Method: - Place the cursor in your class. - Press `Alt + Shift + X` to open the context menu. - Press `J` to run as a Java application. Remember to check if your project is set up correctly and that Eclipse recognizes it as a source folder -
Thanks for the prompt reply I have checked thisLink already But it doesn't seem to Help That much. Can you provide any other Solution. It will be really helpful.
It was a helpful video but you should have first created config files, it was confusing at the beginning, really. There was no need to create first java class.
Rajesh Let's break down the problem step by step Step 1: Identify the configuration file Log4j configuration is usually defined in a file called `log4j.xml` or `log4j.properties`. We need to locate this file in our project. Step 2: Understand the current timestamp format Check the current timestamp format in the Log4j configuration file. It might look something like this: ```xml ``` In this example, the timestamp format is `yyyy-MM-dd HH:mm:ss`. Step 3: Modify the timestamp format To add AM/PM notation, we need to modify the timestamp format. We can use the `a` conversion character to include AM/PM in the timestamp. Update the pattern layout to: ```xml ``` Here, we've changed `HH` (24-hour clock) to `hh` (12-hour clock) and added the `a` conversion character to include AM/PM notation. Step 4: Save and test the changes Save the updated `log4j.xml` or `log4j.properties` file. Then, run your application and check the log output. The timestamp should now include AM/PM notation, like this: ``` 2023-03-16 02:45:00 PM [main] INFO com.example.MyLogger - This is a log message. ``` That's it! We've successfully added AM/PM notation to the timestamp of Log4j -
@@RaghavPal Amazing thank you very much sir. I know you are the valid person to respond to your subscribers to reply like in this way I really appreciate that. I have been following you since 2018. You are such a nice person Raghav sir🫡😊
Hi Raghav thanks for this tutorial. I'm facing an issue my consol logs are generating. My file is also generating but inside file there are no logs appearing. could you please help me.
Hi Shilu, It depends, If you want to output logs at diff levels, Log4J will be helpful. Some dev just like to add some print statements in their code as part of troubleshooting. You can use TestNG and Log4J together
Hi Raghav sir, y we have to create Log4jDemo package in src/main/java...we wont add in src/test/java. one more,Log4j2.properties file ,if we keep in src/main/java or src/main/resources,then only logs folder creating and printing in the console also,if we keep other place its not working.. we should not keep in the src folder -under Libraries. if we keep in src folder ,how can use it in program,is there any logic,please help me Raghav sir...
Hi Raghav, it creates the file when run from the eclipse but does not generate file at the specified path when run using jar. Do you know why? Any other setting needs to be done? Like I gave the path appender.file.fileName=C:\\Maven_Log4JTest\\MyLogs.log. It generates the log file when run in eclipse but not using jar.
Doesn't work in Intellij. I just get the log.error displayed which is the default configuration. log.debg and log.info doesn't work. It only works when I place the log4j2.xml in the same path as my class files. It doesnt' work when it is placed anywhere else? I think it needs to be added to the build path. But I don't see an option in IntelliJ to add that resources/log4j2.xml in build path
@Raghav Thank you for sharing such courses and knowledge 🤗 , I tried to apply the video steps but i got an error while accessing the log file generated stating ( Log format is not recognized ) and it doesn't log anything into it , do you suggest any solution ?
My log file came out empty. I am following your steps on Maven Project with TestNg, not main method. I have lots of packages. I can I add package names in in log4j2.properties file?
hello Raghav sir, I have added log4j2.properties file in my project but still it is showing fatal or error log message and not showing info and warn message moreover that its not generating log file. Kindly help me to resolve this issue.
@@RaghavPal Thanks for your response Raghav. I have checked again but same result.is it required to set any path or any other configurations? Bcoz I think eclipse is not able to read log4j2.properties file
Hey Raghav, Nice explanation but I would like to know more when you said around 7:45ish that we can use the logger wherever/wherever we want in our class. My question is why cannot we use "System.out.println..." command than using a logger? Is there a significance over "System.out.println..."command?
Hi Udai, When you add loggers, you can control the logs levels like error, warning, information, etc and can get more useful information for troubleshooting
Hi Raghav, I am using eclipse version 4.17. I am not able to find any compatible version of log4j for this. Could you please suggest any workaround? Thanks.
Using log4j-1.2.17 jar file Im getting error og4j:WARN No appenders could be found for logger (className log4j:WARN Please initialize the log4j system properly. Please advise!!
What I observed is, logging is mainly being decided by "logger.file.level" and not by "rootLogger.level"... No matter what I write in rootLogger.level (Whether fatal/error/debug etc), final action is based on "logger.file.level"
Hi Ashwini Here are the steps on how to overwrite the log file in your Java project that uses Log4j: 1. Open your log4j configuration file. 2. Find the `appender` element that you want to overwrite. 3. Set the `append` attribute to `false`. 4. Save your configuration file. For example, if you have a log4j configuration file that looks like this: ```
``` To overwrite the log file instead of appending, you would need to change the `append` attribute of the `file` appender to `false`. The updated configuration file would look like this: ```
``` Once you have saved your configuration file, the log file will be overwritten each time the application is run. I hope this helps
Hello Ragav, Your tutorial helps me a lot. While doing this practical session i am getting the error as Exception in thread "main" java.lang.Error: Unresolved compilation problems: Cannot make a static reference to the non-static method info(String) from the type Logger Cannot make a static reference to the non-static method error(String) from the type Logger Cannot make a static reference to the non-static method warn(String) from the type Logger Cannot make a static reference to the non-static method fatal(String) from the type Logger at demo.Log4jDemo.main(Log4jDemo.java:14) Can you help with this? Thanks.
Hi Sachin, In java you can make methods and variables as static or non static. If you put the keyword static before their names or when declaring, they become static else they remain non static. Now leaving out the deeper details and coming to your issue, if any variable or method is non static, you cannot call it or create objects from a static method. That is what happening in your case. Just check the line mentioned in logs and see the method will be static. Also refer the video to check in detail
@@RaghavPal : How to implement Extent Report and Log4J as part of Framework. Like there is a Class called TestBase, Which Implements ITestListener And we have 4 test cases to be executed(TC01, TC02, TC03, TC04) where all of them extends to TestBase so that extent Reports and Log4J properties can be utilized across all the test cases.. Kindly let me know if I have provided clear information.
@@RaghavPal In fact, Please add implementation of Log4j and Extent Reports from Framework point of view for Selenium. That will be very useful as there no much info available for the same. Will be eagerly waiting for the reply, videos :)
Hi Salman, not sure if any setup or step was missed, I can suggest to check and try all steps again and if you still face issue can try checking online
seriously sir your tutorial got me out from 24 hrs wasted on checking from every where but your simple method solve my trouble of log 4j2 just 20 minutes thank you so much
So happy to know Onkar
Am tied up watching all log4j videos and didn't any solution for making log 4j in maven project. But from this video I was successfully created logs without any errors. Thank you so much for making this video sir....
Glad to know it helped Nadiya
Best tutorial for log4j on internet. Explained with great details...no doubts...
So glad to know this Nayan
As usual ver y well explained and never disappointed, I have been following your tutorials for my new job trials.
Great to hear Ashwini. Best wishes
just perfect ! clean and tidy explanation !thank you very much!
Most welcome
THE BEST VIDEO I HAVE SEEN ON THE SUBJECT!!
Thank you very much, it has helped me a lot.
The entire playlist is a gem.
Thanks Jaqueline, humbled
Simply
.......as wonderful as always .....thanku sir
Always welcome Ankur
You never disappoint.
Thanks and keep posting more.
Try covering end to end development videos
Sure Virendra, Thanks for watching
Thank you so much ..we learn alot of thing about automation .. really appreciate sir ...
I m very very thankful to you ..automation ko jitna mn mushkil smjha tha ..sir you make it easy for me..... You explain each everything..in detail
So happy to know it helped
This is exactly what I was looking for. This playlist is very helpful, helped me to PRACTICE before going out for interview. But in my opinion, this is not a beginner course......
Glad to know it helped Mostafizur. I will plan for more basic details
@@RaghavPal Bro do file handling reading and writing ops as there are new changes in Apche POi
Very good bro
Do more and more and boostup us
Sure Sridhar
Clearly explained thanks bro...........
most welcome
Very neat and clear explanation thanks for your help..
You are welcome Devi
This is a great "how to" video. What I am struggling to find is anything that tells me "when to". Can you give some real-world examples of what you should actually put in log messages of each level? Should we log every action, such as text entry and button-clicks? Should we put a log instruction in each method in our POM files?
I'm looking for actual examples rather than technical instructions. Is there anywhere I can find "good practice" advice on deciding on logging messages?
Phil
In a Selenium Java project using Log4J, it's essential to log messages appropriately based on their significance. Here are real-world examples for each log level:
TRACE:
Use this for very detailed messages that are useful for debugging.
Example:
logger.trace("Entering method loginUser (). User ID: {}", userId);
DEBUG:
Ideal for logging detailed information during development and testing.
Example:
logger.debug("Entered username: {}", username);
INFO:
Use this for general information about application flow.
Example:
logger.info("User {} logged in successfully.", username);
WARN:
Indicates potential issues that may need attention.
Example:
logger.warn("User {} attempted to access a restricted page.", username);
ERROR:
For logging error events that might still allow the application to continue running.
Example:
logger.error("Failed to find element by ID: {}", elementId);
FATAL:
For serious errors that might cause the application to terminate.
Example:
logger.fatal("System crash due to unhandled exception: {}", exception.getMessage());
Should You Log Every Action?
Text Entry and Button Clicks:
It is not necessary to log every single action, such as every text entry or button click, as this can lead to excessive log volume and make it difficult to find important information.
Instead, focus on logging significant actions, like:
User logins
Form submissions
Errors or exceptions
Logging in Page Object Model (POM)
Method Logging:
It is advisable to log significant events within methods in your POM files, but avoid cluttering every method with log statements.
Focus on:
Entry and exit points of methods
Key actions (e.g., navigating to a page, submitting a form)
Errors or exceptions
Good Practices for Logging Messages
Clarity: Ensure log messages are clear and provide context.
Consistency: Use a consistent format for log messages across your application.
Avoid Sensitive Information: Do not log sensitive data like passwords or personal user information.
Log Levels: Use the appropriate log level to reflect the severity of the message
-
@@RaghavPal Thank you so much. You're amazing!
I'd like to suggest you do a video on this. It's incredibly hard to find this kind of information. I've been looking for months. It would be very valuable and unique. I can't be the only one looking for this guidance. All the information out there is technical. There is barely anything practical like your answer here.
Sure, will do
thank you! this is exactly the video I was looking for
You're welcome Bruce
Hi Raghav, thanks a lot !!
The information you provided will enough to rock the technology..
Thanks once again 😃..
Most welcome
Hi raghav, You have explained in very neat manner, especially at the end of the video. Thanks, this will be very useful for me in company.
You are most welcome Kamaljit
well explained Raghav
Thanks Imtiaz
Thank you So Much Raghav....
Most welcome Atul
Very nice explanation, but a beginner's question, what is log4j's use in selenium automation scripting? didnt understand that.could you please explain.
Meena
Log4j is a Java-based logging utility that allows developers to log events in their application.
Why is Log4j used in Selenium? Log4j is used in Selenium to:
Debug issues that arise during test execution
Report errors and exceptions that occur during test execution
Monitor test execution and provide insights into test performance
How is Log4j used in Selenium? Log4j is configured using a properties or XML file, and is used to log events and errors during test execution. It can be used in conjunction with a testing framework like TestNG or JUnit.
good explanation
Thanks Sirisha
Clear video on log4j👍🏻
Happy to know it helped Sumitha
Really great tutorial! Good job guy!
Thanks
Hi Raghav,
First thanks for all efforts for us.
I am facing a issue. As following this clip Log file is getting generate in logs folder but logs are not getting append inside the file. It show blank, where as logs are showing on console. Please guide on this. Thanks.
will need to check the settings and configuration file
It's a very detailed explanations thank you.
You are welcome! Lucy
Is it possible to add multiple value for key?, I want to display log for multiple packages. How can I achieve this? I have created framework for my project which had multiple packages.
Hi Sathya, I have not tried this but you can create multiple log files. This may helpful - stackoverflow.com/questions/27941144/how-to-create-multiple-log-files-using-log4j
examples.javacodegeeks.com/enterprise-java/log4j/log4j-writing-different-log-files-example/
@@RaghavPal These example explains log4j. Can u help me to find a solution for multiple packages? As Sathya said, Even i Want to integrate into the framework .
This worked for me for adding multiple packages and particular classes for logs:
#loggers label
loggers= A,B
#loggerA configuration
#Package/Class: packages or classes path
logger.A.name= com.packageA
logger.A.name= com.packageB.classname1
#Level: debug
logger.A.level = fatal
#Using: file
logger.A.appenderRefs = file
#Settings reference: LOGFILE
logger.A.appenderRef.file.ref = LOGFILE
#False: only consider logger
logger.A.additivity = true
#loggerB configuration
#Package/Class: packages or classes path
logger.B.name= com.packageB.classname2
#Level: debug
logger.B.level = trace
#Using: file
logger.B.appenderRefs = file
#Settings reference: LOGFILE
logger.B.appenderRef.file.ref = LOGFILE
#False: only consider logger
logger.B.additivity = true
and below this you can add rootlogger
I will say just amazing explanation....
Thanks Md Shah
What should I do if my run as shows only 'Run Configurations', but no Java application?
Sowjanya
If your Run As menu in Eclipse IDE only shows "Run Configurations", but no Java application, here are a few things you can do:
1. Make sure that the Java project is properly configured. You can do this by right-clicking on the project and selecting "Properties". In the Properties window, select the "Run/Debug" tab and make sure that the "Project JDK" and "Project SDK" are set to the correct versions.
2. Make sure that the Java application is executable. You can do this by right-clicking on the Java file and selecting "Run As" > "Java Application". If the application does not start, it is likely not executable.
3. Make sure that the Java application is selected in the Run As menu. You can do this by clicking on the "Run Configurations" menu and selecting the Java application from the list.
4. If you are still having trouble, you can try creating a new Java project and see if that fixes the problem.
Here are some additional things to check if you are still getting the error:
* Make sure that the Java project is open.
* Make sure that the Java application is in the project's source folder.
* Make sure that the Java application has a main method.
* Make sure that the Java application is not a library project.
If you are still having trouble, you can try the following:
1. Restart Eclipse IDE.
2. Clear the Eclipse IDE cache.
3. Uninstall and reinstall Eclipse IDE.
If you are still having trouble, please contact Eclipse support for help.
Here are the steps on how to clear the Eclipse IDE cache:
1. Open Eclipse IDE.
2. Go to "Window" > "Preferences".
3. In the Preferences window, select "General" > "Workspace".
4. Click on the "Clear Cache" button.
5. Click on the "Apply" button and then the "OK" button.
I hope this helps!
HI Raghav, MyLog file got created after program execution. but nothing is writing there. I can see logs only in console. Please help me on this. Note: I am not using Maven instead Java Project only.
Hi Siddesh, I will need to check, will update
Hi Raghav, I have done as you explained but in log4j2 properties, you mentioned the package name as demo.. If you want to use the same logger obj out of other java packages, it is not writing the logs in the file but in console it works. Can you help me out in this???
Hi Mallikarjun, did you try to import the class wherever you want to use it
@@RaghavPal which files are you asking to import here and where are they supposed to be imported?
to the point explanation ...thank you
You're welcome Sonika
crystal clear
super
Thanks Poornima
Thanks manhhhh this video helped me to solve one silly doubt. Thanks much 😊
Most welcome Saurabh
your sessions are very useful
a querry :--- though I set levels to trace still log file is empty as it work on level off
will need to check on this
@@RaghavPal yes please
Great work Raghav. Very well explained :)
Thanks Mehak
Hi Raghav,
When I run the same code, I’m not getting any error but still log folder is not generated and also I got only logger.error and logger.fatal messages but not getting info and warn messages. Could you please suggest me?
Thanks.
Hi Rahul, try a diff ver, Also recheck that you followed all the steps
Hi Rahul, try a diff ver, Also recheck that you followed all the steps
hi. i am facing same error. can you tell me what worked with you?
Thank you so so much for this video ... it works flawlessly
You're welcome Dinesh
Beautifully clear. Thank you so much!
You're welcome
Loved the simple explanation, it would have been nice if this video covered the .xml config file also as that is widely used in industry.
Noted Suman
very helpful video
, can you also explain how to add test case for same.
I will plan on this Mani
Thank you so much for this video but one question I have related to this...
How we can generate different files in logs folder with timestamps...i want to implement in my framework
Hi Amit, pls check stackoverflow.com/questions/44753863/log4j-properties-create-new-log-file-with-timestamp-for-every-run#:~:text=You%20need%20to%20write%20(or,file%20hits%20the%20size%20limit
Топ индус, уважаю
Большое спасибо. Униженный
How to use Log4j in full-fledged selenium framework? As you used demo package in your example while in a framework there are multiple packages. Other than this do we not require to read the property file?
You can setup log4j in a separate class and then use it wherever you want to add logs
log folder generating but inside log files i am not able to see logs any guess?
Hi Vignesh, will need to see log4j setup and settings file
Hi Raghav, I followed your step exactly as showed in video, but still I am not getting trace, info and warn logs as well as not getting "log" folder and MyLogs file as well. kindly let me know how to fix it?
Hi Samuel, not sure if you missed something, I will suggest to check the official documentation or some online examples and try
@@RaghavPal Thanks Raghav
Thank you !!!. clearly understood
Glad it helped Yehen
Hi Raghav,
Thanks for this video which is generating logs for one of the class only.
But If we want to generate for multiple classes then?? how dynamically we call this logger class / object?
Please comment on this.
Hi Radha, I will try to do session on that, for now you can check some examples online
I created class in src/test/java i am not getting a file and I tried in src/main/java then I try to run but it's showing run configuration is not showing java application
Mounika
It seems you're encountering an issue with Eclipse not showing the "Run as Java Application" option. Let's troubleshoot this:
1. Check Your Main Class:
- Ensure that your main class has the correct syntax for the `main` method:
```java
public static void main(String[] args) {
// Your code here
}
```
- Make sure the `String[] args` parameter is included.
2. Create a New Run Configuration:
- Right-click on your Java file.
- Choose "Run As" > "Run Configurations."
- Select "Java Application" and click "New."
- Configure the run settings and click "Run."
3. Shortcut Method:
- Place the cursor in your class.
- Press `Alt + Shift + X` to open the context menu.
- Press `J` to run as a Java application.
Remember to check if your project is set up correctly and that Eclipse recognizes it as a source folder
-
Nicely explained,
If i want to generate a log file with current Timestamp as its name everytime we run the application
How to do that
Hi Ankit, this can help - stackoverflow.com/questions/44753863/log4j-properties-create-new-log-file-with-timestamp-for-every-run
Thanks for the prompt reply
I have checked thisLink already But it doesn't seem to Help That much. Can you provide any other Solution. It will be really helpful.
I got a solution for this problem
thank u so much exactly what i am finding
Glad I could help Kumar
Hi, I cant make logs folder in application after running application . even I set the log4j.properties ??
will need to check the setup Meghana, try some online examples
how did you use that properties file? I don't see that file being used anywhere in your code.
Hi Pratik, pls check earlier videos - th-cam.com/play/PLhW3qG5bs-L8oRay6qeS70vJYZ3SBQnFa.html
Oh thanks...
@@PBidwai can i know the video number or the name from the link Raghav posted for u?
@@RaghavPal can i please know either video number or name of the topic in your video?
Its playlist: th-cam.com/play/PLhW3qG5bs-L8oRay6qeS70vJYZ3SBQnFa.html
It was a helpful video but you should have first created config files, it was confusing at the beginning, really. There was no need to create first java class.
Thanks for the tip! I will improve
Hi Sir, How to add AM PM along with the timestamp of log 4j
Rajesh
Let's break down the problem step by step
Step 1: Identify the configuration file
Log4j configuration is usually defined in a file called `log4j.xml` or `log4j.properties`. We need to locate this file in our project.
Step 2: Understand the current timestamp format
Check the current timestamp format in the Log4j configuration file. It might look something like this:
```xml
```
In this example, the timestamp format is `yyyy-MM-dd HH:mm:ss`.
Step 3: Modify the timestamp format
To add AM/PM notation, we need to modify the timestamp format. We can use the `a` conversion character to include AM/PM in the timestamp.
Update the pattern layout to:
```xml
```
Here, we've changed `HH` (24-hour clock) to `hh` (12-hour clock) and added the `a` conversion character to include AM/PM notation.
Step 4: Save and test the changes
Save the updated `log4j.xml` or `log4j.properties` file. Then, run your application and check the log output. The timestamp should now include AM/PM notation, like this:
```
2023-03-16 02:45:00 PM [main] INFO com.example.MyLogger - This is a log message.
```
That's it! We've successfully added AM/PM notation to the timestamp of Log4j
-
@@RaghavPal Amazing thank you very much sir. I know you are the valid person to respond to your subscribers to reply like in this way I really appreciate that. I have been following you since 2018. You are such a nice person Raghav sir🫡😊
Hi Raghav thanks for this tutorial. I'm facing an issue my consol logs are generating. My file is also generating but inside file there are no logs appearing. could you please help me.
Hi, will need to check your setup, check some log4j example and try with that
Why we need Log4j Raghav, it just display log in test run. We also can make log by TestNG or extent report, it more convenience than Log4j only.
There are diff ways for logging. TestNG will be good for logging test related events. If your need if met using TestNG. you can skip log4j
Hi Raghav, after running the test the log folder is not getting created. I am working on the framework implementation.
Hi Nikita, will need to check the setup again
Thanks for the reply sir...but could you please explain how the log4j works with TestNg framework
Hi Nikita, log4j is a logging library so we just added it for controlling the logs.
Hello Raghav, how do we add comments in .properties file ?
Hi Yash, can use #
Hi , Everything is running fine just an issue that mylogs.log file under log folder is coming empty. What should I do ?
Hi Prince, can get some help here - stackoverflow.com/questions/15520014/log-file-is-created-but-file-is-empty
Wats the use of Log4, if we have extend report, whether both should be required,
can we use the logger message in extend report
Hi Shilu, It depends, If you want to output logs at diff levels, Log4J will be helpful. Some dev just like to add some print statements in their code as part of troubleshooting. You can use TestNG and Log4J together
Hi Raghav sir,
y we have to create Log4jDemo package in src/main/java...we wont add in src/test/java.
one more,Log4j2.properties file ,if we keep in src/main/java or src/main/resources,then only logs folder creating and printing in the console also,if we keep other place its not working..
we should not keep in the src folder -under Libraries.
if we keep in src folder ,how can use it in program,is there any logic,please help me Raghav sir...
I will plan a session on project structure
@@RaghavPal Thank you soo much...waiting for that..
Hi Raghav, it creates the file when run from the eclipse but does not generate file at the specified path when run using jar. Do you know why? Any other setting needs to be done? Like I gave the path appender.file.fileName=C:\\Maven_Log4JTest\\MyLogs.log. It generates the log file when run in eclipse but not using jar.
Hi Dhruv, can you provide the time in the video so I can check exactly what part are you facing problem with
what is the difference between log4j and extentreports and which is better?
Hi Santosh, log4j is to create logs at diff level, Extent reports is a reporting library
Doesn't work in Intellij. I just get the log.error displayed which is the default configuration. log.debg and log.info doesn't work.
It only works when I place the log4j2.xml in the same path as my class files. It doesnt' work when it is placed anywhere else? I think it needs to be added to the build path. But I don't see an option in IntelliJ to add that resources/log4j2.xml in build path
Ok Shivam, I will check on this, Not sure for IntelliJ
thank you
Most welcome
@Raghav Thank you for sharing such courses and knowledge 🤗 , I tried to apply the video steps but i got an error while accessing the log file generated stating ( Log format is not recognized ) and it doesn't log anything into it , do you suggest any solution ?
pls check this stackoverflow.com/questions/63300617/getting-issue-in-intellij-with-log4j-log-file-format
My log file came out empty. I am following your steps on Maven Project with TestNg, not main method. I have lots of packages. I can I add package names in in log4j2.properties file?
will need to check with more details, can try using some online examples
Thanks for the video..really helpful.
Is it mandatory to place log4j2.properties only inside src/main/resources
not mandatory
Really helped me, thank you :)
Glad to hear that István
Helpful
Thanks for watching Vaishali
hello Raghav sir, I have added log4j2.properties file in my project but still it is showing fatal or error log message and not showing info and warn message moreover that its not generating log file. Kindly help me to resolve this issue.
Hi Tarun, check the detailed logs and see the steps again
@@RaghavPal Thanks for your response Raghav. I have checked again but same result.is it required to set any path or any other configurations? Bcoz I think eclipse is not able to read log4j2.properties file
Kindly do the needful.
thank you for a helpful video
You're welcome Anchal
Hi, im able to view the logs output on the console, but the same is not getting written in MyLogs.log file.
Please help.
Hi Tanmay, I will have to check your setup. You can try some online help meanwhile
You need to give the name of your package in logger.file.name= in properties file
Thanks for this video.
You're welcome Odia
Hey Raghav, Nice explanation but I would like to know more when you said around 7:45ish that we can use the logger wherever/wherever we want in our class. My question is why cannot we use "System.out.println..." command than using a logger? Is there a significance over "System.out.println..."command?
Hi Udai, When you add loggers, you can control the logs levels like error, warning, information, etc and can get more useful information for troubleshooting
Thanks guru ❤😊✨
Always welcome Ilavarasan
Hi Raghav, I am using eclipse version 4.17. I am not able to find any compatible version of log4j for this. Could you please suggest any workaround?
Thanks.
Hi Aarti, how did you check the compatibility, Can you not update Eclipse ver
I tried diff versions of log4j to work with eclipse . When i am trying to create logger object, it doesnt show any supporting libraries for getlogger
okay, not sure if there can be some issue in the configurations. Can you separately try with a diff eclipse, Just to rule out Eclipse issues
Using log4j-1.2.17 jar file
Im getting error
og4j:WARN No appenders could be found for logger (className
log4j:WARN Please initialize the log4j system properly.
Please advise!!
Hi Hicham, pls check this stackoverflow.com/questions/12532339/no-appenders-could-be-found-for-loggerlog4j
13:46 Very important part. If you don't put package name after "logger.file.name=", your log file will come out empty!
Thanks for adding Marek
@@RaghavPal what if i don't want to pass package as i have multiple package how can i handle it
Correct
What I observed is, logging is mainly being decided by "logger.file.level" and not by "rootLogger.level"... No matter what I write in rootLogger.level (Whether fatal/error/debug etc), final action is based on "logger.file.level"
HI Manorama, thanks for adding your observations, I will too check on this
Hi Raghav, is there any test automation framework for testing an existing logging framework used by developers in a project?
Not sure on this Saranga
Why did we create this demo in src/main and not in src/test?
could have done that, you can continue in src/test
You have Maven Project. Why did you do this with main method?
Pls refer the time stamp in video for me to refer
Why we create class in main package Raghav? is this package any different with other?
main is the starting point in java program. Whatever we need to run at the start can put in main
Raghav also how can we generate the separate logs in parallel execution wit testng?
You can write logs as you wish using the log4j functions
How to overrite the file. Instead of appending
Hi Ashwini
Here are the steps on how to overwrite the log file in your Java project that uses Log4j:
1. Open your log4j configuration file.
2. Find the `appender` element that you want to overwrite.
3. Set the `append` attribute to `false`.
4. Save your configuration file.
For example, if you have a log4j configuration file that looks like this:
```
```
To overwrite the log file instead of appending, you would need to change the `append` attribute of the `file` appender to `false`. The updated configuration file would look like this:
```
```
Once you have saved your configuration file, the log file will be overwritten each time the application is run.
I hope this helps
log folder is not getting created automatically
Will have to check. Pls also verify with the video, you did not miss any step
you might have missed selenium dependencies
Yes Raghav, Log folder is not being created . followed all the steps as per expected. Could you please tell the workaround for it.
How can we change the time of logs to any particular timezone ? I think currently it is taking local time of the your machine
This should help stackoverflow.com/questions/9116425/apache-log4j-logging-with-specific-timezone
logging.apache.org/log4j/1.2/faq.html#a3.4
Automation Step by Step - Raghav Pal Thanks a lot bro
You're welcome
Liked
Thanks Java
Hello Ragav,
Your tutorial helps me a lot. While doing this practical session i am getting the error as
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Cannot make a static reference to the non-static method info(String) from the type Logger
Cannot make a static reference to the non-static method error(String) from the type Logger
Cannot make a static reference to the non-static method warn(String) from the type Logger
Cannot make a static reference to the non-static method fatal(String) from the type Logger
at demo.Log4jDemo.main(Log4jDemo.java:14)
Can you help with this?
Thanks.
Hi Sachin, In java you can make methods and variables as static or non static. If you put the keyword static before their names or when declaring, they become static else they remain non static.
Now leaving out the deeper details and coming to your issue, if any variable or method is non static, you cannot call it or create objects from a static method. That is what happening in your case.
Just check the line mentioned in logs and see the method will be static.
Also refer the video to check in detail
After writing the .properties file. All its components are showing as unused. What to do?
Hi Stuti, have you referred them in your scripts. It should be fine if not creating any error
what we learn is log4j or log4j2? plz clear m confused sir?
Hi Akash, this is a logging library to create and show logs during execution
Raghav, Can you please add Implementing Log4J into Framework having TestBase or something similar ?
Hi Tej, will need more info/details on your needs
@@RaghavPal : How to implement Extent Report and Log4J as part of Framework.
Like there is a Class called TestBase, Which Implements ITestListener
And we have 4 test cases to be executed(TC01, TC02, TC03, TC04) where all of them extends to TestBase so that extent Reports and Log4J properties can be utilized across all the test cases..
Kindly let me know if I have provided clear information.
Okay I will add more sessions related to this
@@RaghavPal : Thank you
@@RaghavPal In fact, Please add implementation of Log4j and Extent Reports from Framework point of view for Selenium. That will be very useful as there no much info available for the same.
Will be eagerly waiting for the reply, videos :)
Hi bro even while turning off log4j there's a file created under the log folder. is it possible to not create a file under the log folder
Yes, you can
@@RaghavPal how can you guide me
I will check, will try to add some session on this but for now, you will need to take online help
After refreshed project not getting log folder please let me know why??
Hi Salman, not sure if any setup or step was missed, I can suggest to check and try all steps again and if you still face issue can try checking online
@@RaghavPal thanks Sir already tried but still not solved i will check again.
Log folder is not created in my project , what should i do?
Check the setup again Chhavi
Thank you so much bro
You're welcome
You forget to mention additivity concept in log4j.
I will check
Hi I am getting the error:
log4j: WARN no appenders could be found for logger ( package.class)
Hi Vishal, can check this
stackoverflow.com/questions/12532339/no-appenders-could-be-found-for-loggerlog4j
I followed your steps, but my log file created is empty, why? please help
Hi Sameena, will need to check the code and setup. Pls check all the steps again
@@RaghavPal Its my mistake and corrected. Thank you so much