Selenium Framework for Beginners 14 | What is Log4j | How to add Log4j in java project

  Рет қаралды 151,420

Automation Step by Step

Automation Step by Step

Күн бұрын

Пікірлер: 335
@onkardhavale117
@onkardhavale117 2 жыл бұрын
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
@RaghavPal
@RaghavPal 2 жыл бұрын
So happy to know Onkar
@nadiyagone8431
@nadiyagone8431 5 жыл бұрын
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....
@RaghavPal
@RaghavPal 5 жыл бұрын
Glad to know it helped Nadiya
@NPRBEST
@NPRBEST 5 жыл бұрын
Best tutorial for log4j on internet. Explained with great details...no doubts...
@RaghavPal
@RaghavPal 5 жыл бұрын
So glad to know this Nayan
@ashwinireddy6832
@ashwinireddy6832 Жыл бұрын
As usual ver y well explained and never disappointed, I have been following your tutorials for my new job trials.
@RaghavPal
@RaghavPal Жыл бұрын
Great to hear Ashwini. Best wishes
@jaquelinecuatepitzibastida4163
@jaquelinecuatepitzibastida4163 2 жыл бұрын
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.
@RaghavPal
@RaghavPal 2 жыл бұрын
Thanks Jaqueline, humbled
@Nstyleonlineuk
@Nstyleonlineuk 2 жыл бұрын
just perfect ! clean and tidy explanation !thank you very much!
@RaghavPal
@RaghavPal 2 жыл бұрын
Most welcome
@virendrasinghbais9028
@virendrasinghbais9028 5 жыл бұрын
You never disappoint. Thanks and keep posting more. Try covering end to end development videos
@RaghavPal
@RaghavPal 5 жыл бұрын
Sure Virendra, Thanks for watching
@Mostafizur_rahman188
@Mostafizur_rahman188 4 жыл бұрын
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......
@RaghavPal
@RaghavPal 4 жыл бұрын
Glad to know it helped Mostafizur. I will plan for more basic details
@Shivakumar-nl2li
@Shivakumar-nl2li 4 жыл бұрын
@@RaghavPal Bro do file handling reading and writing ops as there are new changes in Apche POi
@shehlaabdullah5374
@shehlaabdullah5374 Жыл бұрын
Thank you so much ..we learn alot of thing about automation .. really appreciate sir ...
@shehlaabdullah5374
@shehlaabdullah5374 Жыл бұрын
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
@RaghavPal
@RaghavPal Жыл бұрын
So happy to know it helped
@sridharmamidipaka6252
@sridharmamidipaka6252 2 жыл бұрын
Very good bro Do more and more and boostup us
@RaghavPal
@RaghavPal 2 жыл бұрын
Sure Sridhar
@ankurmishra8508
@ankurmishra8508 4 жыл бұрын
Simply .......as wonderful as always .....thanku sir
@RaghavPal
@RaghavPal 4 жыл бұрын
Always welcome Ankur
@rhacker0007
@rhacker0007 3 жыл бұрын
Hi Raghav, thanks a lot !! The information you provided will enough to rock the technology.. Thanks once again 😃..
@RaghavPal
@RaghavPal 3 жыл бұрын
Most welcome
@deviyadlapalli3011
@deviyadlapalli3011 3 жыл бұрын
Very neat and clear explanation thanks for your help..
@RaghavPal
@RaghavPal 3 жыл бұрын
You are welcome Devi
@immuind2009
@immuind2009 3 жыл бұрын
well explained Raghav
@RaghavPal
@RaghavPal 3 жыл бұрын
Thanks Imtiaz
@brucemyklebust8886
@brucemyklebust8886 4 жыл бұрын
thank you! this is exactly the video I was looking for
@RaghavPal
@RaghavPal 4 жыл бұрын
You're welcome Bruce
@vigneshviky9248
@vigneshviky9248 2 жыл бұрын
Clearly explained thanks bro...........
@RaghavPal
@RaghavPal 2 жыл бұрын
most welcome
@kamaljitxSingh
@kamaljitxSingh 3 жыл бұрын
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.
@RaghavPal
@RaghavPal 3 жыл бұрын
You are most welcome Kamaljit
@sumithak9345
@sumithak9345 5 жыл бұрын
Clear video on log4j👍🏻
@RaghavPal
@RaghavPal 5 жыл бұрын
Happy to know it helped Sumitha
@philb4462
@philb4462 2 ай бұрын
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?
@RaghavPal
@RaghavPal 2 ай бұрын
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 -
@philb4462
@philb4462 2 ай бұрын
@@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.
@RaghavPal
@RaghavPal 2 ай бұрын
Sure, will do
@sirisham4992
@sirisham4992 2 жыл бұрын
good explanation
@RaghavPal
@RaghavPal 2 жыл бұрын
Thanks Sirisha
@atulthorat5670
@atulthorat5670 2 жыл бұрын
Thank you So Much Raghav....
@RaghavPal
@RaghavPal 2 жыл бұрын
Most welcome Atul
@poornimap3455
@poornimap3455 3 жыл бұрын
crystal clear super
@RaghavPal
@RaghavPal 3 жыл бұрын
Thanks Poornima
@manikandan-zb8kp
@manikandan-zb8kp 3 жыл бұрын
very helpful video , can you also explain how to add test case for same.
@RaghavPal
@RaghavPal 3 жыл бұрын
I will plan on this Mani
@ahsan322
@ahsan322 3 жыл бұрын
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.
@RaghavPal
@RaghavPal 3 жыл бұрын
will need to check the settings and configuration file
@lucylucy8517
@lucylucy8517 4 жыл бұрын
It's a very detailed explanations thank you.
@RaghavPal
@RaghavPal 4 жыл бұрын
You are welcome! Lucy
@radyshrek3954
@radyshrek3954 3 жыл бұрын
Really great tutorial! Good job guy!
@RaghavPal
@RaghavPal 3 жыл бұрын
Thanks
@mallikarjunaswamyb3765
@mallikarjunaswamyb3765 5 жыл бұрын
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???
@RaghavPal
@RaghavPal 5 жыл бұрын
Hi Mallikarjun, did you try to import the class wherever you want to use it
@Thuster
@Thuster 5 жыл бұрын
@@RaghavPal which files are you asking to import here and where are they supposed to be imported?
@sonikaraina8553
@sonikaraina8553 4 жыл бұрын
to the point explanation ...thank you
@RaghavPal
@RaghavPal 4 жыл бұрын
You're welcome Sonika
@EliasHossein799
@EliasHossein799 4 жыл бұрын
I will say just amazing explanation....
@RaghavPal
@RaghavPal 4 жыл бұрын
Thanks Md Shah
@saurabhdichwalkar6969
@saurabhdichwalkar6969 4 жыл бұрын
Thanks manhhhh this video helped me to solve one silly doubt. Thanks much 😊
@RaghavPal
@RaghavPal 4 жыл бұрын
Most welcome Saurabh
@MeenaK-i6w
@MeenaK-i6w 2 ай бұрын
Very nice explanation, but a beginner's question, what is log4j's use in selenium automation scripting? didnt understand that.could you please explain.
@RaghavPal
@RaghavPal 2 ай бұрын
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.
@sathyasachin1696
@sathyasachin1696 5 жыл бұрын
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.
@RaghavPal
@RaghavPal 5 жыл бұрын
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/
@Mithunkumar-kq3vt
@Mithunkumar-kq3vt 4 жыл бұрын
@@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 .
@akshay9751
@akshay9751 3 жыл бұрын
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
@Yaddalapudi
@Yaddalapudi 5 жыл бұрын
9:08 i am not getting any error there what ever i am printing that prints in console ,what the problem
@RaghavPal
@RaghavPal 5 жыл бұрын
Hi Krishna, I will need the error details/logs to troubleshoot
@Yaddalapudi
@Yaddalapudi 5 жыл бұрын
@@RaghavPal your getting in this video right,but I not getting any error,all ok
@RaghavPal
@RaghavPal 5 жыл бұрын
Okay, great.
@mohammedsaif7916
@mohammedsaif7916 4 жыл бұрын
Could you please check the version of log4j-api and log4j-core dependencies I also got the same doubt in the initial stage of practical session. After changing the version for both dependencies to 2.5, it worked for me Try to change the version and see. It might work
@dineshkmr269
@dineshkmr269 6 жыл бұрын
Thank you so so much for this video ... it works flawlessly
@RaghavPal
@RaghavPal 6 жыл бұрын
You're welcome Dinesh
@suma4m
@suma4m 3 жыл бұрын
13:46 Very important part. If you don't put package name after "logger.file.name=", your log file will come out empty!
@RaghavPal
@RaghavPal 3 жыл бұрын
Thanks for adding Marek
@rahulshinde437
@rahulshinde437 3 жыл бұрын
@@RaghavPal what if i don't want to pass package as i have multiple package how can i handle it
@siddeshb.b4617
@siddeshb.b4617 3 жыл бұрын
Correct
@100janyam
@100janyam Жыл бұрын
What should I do if my run as shows only 'Run Configurations', but no Java application?
@RaghavPal
@RaghavPal Жыл бұрын
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!
@siddeshb.b4617
@siddeshb.b4617 3 жыл бұрын
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.
@RaghavPal
@RaghavPal 3 жыл бұрын
Hi Siddesh, I will need to check, will update
@itguyappnweb3011
@itguyappnweb3011 Жыл бұрын
your sessions are very useful a querry :--- though I set levels to trace still log file is empty as it work on level off
@RaghavPal
@RaghavPal Жыл бұрын
will need to check on this
@itguyappnweb3011
@itguyappnweb3011 Жыл бұрын
@@RaghavPal yes please
@mehakverma3400
@mehakverma3400 6 жыл бұрын
Great work Raghav. Very well explained :)
@RaghavPal
@RaghavPal 6 жыл бұрын
Thanks Mehak
@sumanshekhar3741
@sumanshekhar3741 3 жыл бұрын
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.
@RaghavPal
@RaghavPal 3 жыл бұрын
Noted Suman
@PBidwai
@PBidwai 5 жыл бұрын
how did you use that properties file? I don't see that file being used anywhere in your code.
@RaghavPal
@RaghavPal 5 жыл бұрын
Hi Pratik, pls check earlier videos - kzbin.info/aero/PLhW3qG5bs-L8oRay6qeS70vJYZ3SBQnFa
@PBidwai
@PBidwai 5 жыл бұрын
Oh thanks...
@seemanelogal
@seemanelogal 5 жыл бұрын
@@PBidwai can i know the video number or the name from the link Raghav posted for u?
@seemanelogal
@seemanelogal 5 жыл бұрын
@@RaghavPal can i please know either video number or name of the topic in your video?
@PBidwai
@PBidwai 5 жыл бұрын
Its playlist: kzbin.info/aero/PLhW3qG5bs-L8oRay6qeS70vJYZ3SBQnFa
@Arunganesan1
@Arunganesan1 4 жыл бұрын
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.
@RaghavPal
@RaghavPal 4 жыл бұрын
Hi Rahul, try a diff ver, Also recheck that you followed all the steps
@RaghavPal
@RaghavPal 4 жыл бұрын
Hi Rahul, try a diff ver, Also recheck that you followed all the steps
@navya1433
@navya1433 6 ай бұрын
hi. i am facing same error. can you tell me what worked with you?
@udangng
@udangng 4 жыл бұрын
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?
@RaghavPal
@RaghavPal 4 жыл бұрын
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
@brandonflorida1092
@brandonflorida1092 6 жыл бұрын
Beautifully clear. Thank you so much!
@RaghavPal
@RaghavPal 6 жыл бұрын
You're welcome
@meghanamule1645
@meghanamule1645 2 жыл бұрын
Hi, I cant make logs folder in application after running application . even I set the log4j.properties ??
@RaghavPal
@RaghavPal 2 жыл бұрын
will need to check the setup Meghana, try some online examples
@vjkrish47
@vjkrish47 3 жыл бұрын
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...
@RaghavPal
@RaghavPal 3 жыл бұрын
I will plan a session on project structure
@madhavilatha1996
@madhavilatha1996 3 жыл бұрын
@@RaghavPal Thank you soo much...waiting for that..
@vigneshelan8716
@vigneshelan8716 3 жыл бұрын
log folder generating but inside log files i am not able to see logs any guess?
@RaghavPal
@RaghavPal 3 жыл бұрын
Hi Vignesh, will need to see log4j setup and settings file
@vaishalijillewar7437
@vaishalijillewar7437 5 жыл бұрын
Helpful
@RaghavPal
@RaghavPal 5 жыл бұрын
Thanks for watching Vaishali
@radhasubbu7476
@radhasubbu7476 2 жыл бұрын
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.
@RaghavPal
@RaghavPal 2 жыл бұрын
Hi Radha, I will try to do session on that, for now you can check some examples online
@ilavarasansriraman4140
@ilavarasansriraman4140 4 жыл бұрын
Thanks guru ❤😊✨
@RaghavPal
@RaghavPal 4 жыл бұрын
Always welcome Ilavarasan
@dhruv1973
@dhruv1973 4 жыл бұрын
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.
@RaghavPal
@RaghavPal 4 жыл бұрын
Hi Dhruv, can you provide the time in the video so I can check exactly what part are you facing problem with
@yehenandaraweera1533
@yehenandaraweera1533 4 жыл бұрын
Thank you !!!. clearly understood
@RaghavPal
@RaghavPal 4 жыл бұрын
Glad it helped Yehen
@uhsay1986
@uhsay1986 4 жыл бұрын
Hello Raghav, how do we add comments in .properties file ?
@RaghavPal
@RaghavPal 4 жыл бұрын
Hi Yash, can use #
@kumarsaurav9660
@kumarsaurav9660 4 жыл бұрын
thank u so much exactly what i am finding
@RaghavPal
@RaghavPal 4 жыл бұрын
Glad I could help Kumar
@anchalpal7735
@anchalpal7735 5 жыл бұрын
thank you for a helpful video
@RaghavPal
@RaghavPal 5 жыл бұрын
You're welcome Anchal
@mboyi6014
@mboyi6014 2 жыл бұрын
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.
@RaghavPal
@RaghavPal 2 жыл бұрын
Hi, will need to check your setup, check some log4j example and try with that
@mohammadrasheed8402
@mohammadrasheed8402 4 жыл бұрын
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?
@RaghavPal
@RaghavPal 4 жыл бұрын
You can setup log4j in a separate class and then use it wherever you want to add logs
@akhilakandukuri47
@akhilakandukuri47 4 жыл бұрын
Thanks for the video..really helpful. Is it mandatory to place log4j2.properties only inside src/main/resources
@RaghavPal
@RaghavPal 4 жыл бұрын
not mandatory
@shilupg
@shilupg 5 жыл бұрын
Wats the use of Log4, if we have extend report, whether both should be required, can we use the logger message in extend report
@RaghavPal
@RaghavPal 5 жыл бұрын
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
@WorkWork-ed4vc
@WorkWork-ed4vc 2 жыл бұрын
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?
@RaghavPal
@RaghavPal 2 жыл бұрын
will need to check with more details, can try using some online examples
@aartiriat7590
@aartiriat7590 4 жыл бұрын
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.
@RaghavPal
@RaghavPal 4 жыл бұрын
Hi Aarti, how did you check the compatibility, Can you not update Eclipse ver
@aartiriat7590
@aartiriat7590 4 жыл бұрын
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
@RaghavPal
@RaghavPal 4 жыл бұрын
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
@OdiaVlogsbyLipika
@OdiaVlogsbyLipika 4 жыл бұрын
Thanks for this video.
@RaghavPal
@RaghavPal 4 жыл бұрын
You're welcome Odia
@ankitmehra954
@ankitmehra954 4 жыл бұрын
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
@RaghavPal
@RaghavPal 4 жыл бұрын
Hi Ankit, this can help - stackoverflow.com/questions/44753863/log4j-properties-create-new-log-file-with-timestamp-for-every-run
@ankitmehra954
@ankitmehra954 4 жыл бұрын
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.
@ankitmehra954
@ankitmehra954 4 жыл бұрын
I got a solution for this problem
@AutomationTesting-q7v
@AutomationTesting-q7v 19 күн бұрын
How can i include this logs in extent reports or any other HTML reports. ?
@RaghavPal
@RaghavPal 18 күн бұрын
1. *Set up Log4j* : Configure `log4j.properties` to write logs to a file (e.g., `logs/test-log.log`). 2. *Generate Logs* : Use `Logger` in your tests: ```java log.info("Test started."); log.error("An error occurred."); ``` 3. *Read Logs in Code* : Create a method to read log content: ```java public String getLogsContent() throws IOException { return new String(Files.readAllBytes(Paths.get("logs/test-log.log"))); } ``` 4. *Add Logs to Report* : Use Extent Reports to include logs: ```java test.log(Status.INFO, "Logs: " + getLogsContent()); ``` 5. *Run Tests* : Logs will appear in the HTML report -
@SaraMohamed-ge7vg
@SaraMohamed-ge7vg 2 жыл бұрын
@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 ?
@RaghavPal
@RaghavPal 2 жыл бұрын
pls check this stackoverflow.com/questions/63300617/getting-issue-in-intellij-with-log4j-log-file-format
@mounika4639
@mounika4639 6 ай бұрын
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
@RaghavPal
@RaghavPal 6 ай бұрын
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 -
@tango3dublin
@tango3dublin 2 жыл бұрын
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?
@RaghavPal
@RaghavPal 2 жыл бұрын
Hi Samuel, not sure if you missed something, I will suggest to check the official documentation or some online examples and try
@tango3dublin
@tango3dublin 2 жыл бұрын
@@RaghavPal Thanks Raghav
@geekysantosh
@geekysantosh 4 жыл бұрын
what is the difference between log4j and extentreports and which is better?
@RaghavPal
@RaghavPal 4 жыл бұрын
Hi Santosh, log4j is to create logs at diff level, Extent reports is a reporting library
@nikitabobade1582
@nikitabobade1582 3 жыл бұрын
Hi Raghav, after running the test the log folder is not getting created. I am working on the framework implementation.
@RaghavPal
@RaghavPal 3 жыл бұрын
Hi Nikita, will need to check the setup again
@nikitabobade1582
@nikitabobade1582 3 жыл бұрын
Thanks for the reply sir...but could you please explain how the log4j works with TestNg framework
@RaghavPal
@RaghavPal 3 жыл бұрын
Hi Nikita, log4j is a logging library so we just added it for controlling the logs.
@istvan368
@istvan368 4 жыл бұрын
Really helped me, thank you :)
@RaghavPal
@RaghavPal 4 жыл бұрын
Glad to hear that István
@princemalik5917
@princemalik5917 4 жыл бұрын
Hi , Everything is running fine just an issue that mylogs.log file under log folder is coming empty. What should I do ?
@RaghavPal
@RaghavPal 4 жыл бұрын
Hi Prince, can get some help here - stackoverflow.com/questions/15520014/log-file-is-created-but-file-is-empty
@tanmaykumbhar9614
@tanmaykumbhar9614 4 жыл бұрын
Hi, im able to view the logs output on the console, but the same is not getting written in MyLogs.log file. Please help.
@RaghavPal
@RaghavPal 4 жыл бұрын
Hi Tanmay, I will have to check your setup. You can try some online help meanwhile
@dhruv1973
@dhruv1973 4 жыл бұрын
You need to give the name of your package in logger.file.name= in properties file
@AmitSingh-nq5vp
@AmitSingh-nq5vp 3 жыл бұрын
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
@RaghavPal
@RaghavPal 3 жыл бұрын
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
@sarangmech
@sarangmech 5 жыл бұрын
Hi Raghav, is there any test automation framework for testing an existing logging framework used by developers in a project?
@RaghavPal
@RaghavPal 5 жыл бұрын
Not sure on this Saranga
@venkatmungara180
@venkatmungara180 Жыл бұрын
thank you
@RaghavPal
@RaghavPal Жыл бұрын
Most welcome
@tarunparashar7554
@tarunparashar7554 3 жыл бұрын
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
@RaghavPal 3 жыл бұрын
Hi Tarun, check the detailed logs and see the steps again
@tarunparashar7554
@tarunparashar7554 3 жыл бұрын
@@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
@tarunparashar7554
@tarunparashar7554 3 жыл бұрын
Kindly do the needful.
@mallikarjunaswamyb3765
@mallikarjunaswamyb3765 5 жыл бұрын
Raghav also how can we generate the separate logs in parallel execution wit testng?
@RaghavPal
@RaghavPal 5 жыл бұрын
You can write logs as you wish using the log4j functions
@DucNguyen-xn5bd
@DucNguyen-xn5bd 5 жыл бұрын
Why we create class in main package Raghav? is this package any different with other?
@RaghavPal
@RaghavPal 5 жыл бұрын
main is the starting point in java program. Whatever we need to run at the start can put in main
@rajeshbe2234
@rajeshbe2234 5 ай бұрын
Hi Sir, How to add AM PM along with the timestamp of log 4j
@RaghavPal
@RaghavPal 5 ай бұрын
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 -
@rajeshbe2234
@rajeshbe2234 5 ай бұрын
@@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🫡😊
@subashtherider962
@subashtherider962 3 жыл бұрын
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
@RaghavPal
@RaghavPal 3 жыл бұрын
Yes, you can
@subashr7198
@subashr7198 3 жыл бұрын
@@RaghavPal how can you guide me
@RaghavPal
@RaghavPal 3 жыл бұрын
I will check, will try to add some session on this but for now, you will need to take online help
@100janyam
@100janyam Жыл бұрын
Why did we create this demo in src/main and not in src/test?
@RaghavPal
@RaghavPal Жыл бұрын
could have done that, you can continue in src/test
@shivam1427
@shivam1427 4 жыл бұрын
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
@RaghavPal
@RaghavPal 4 жыл бұрын
Ok Shivam, I will check on this, Not sure for IntelliJ
@karandeepsingh5000
@karandeepsingh5000 6 жыл бұрын
How can we change the time of logs to any particular timezone ? I think currently it is taking local time of the your machine
@RaghavPal
@RaghavPal 6 жыл бұрын
This should help stackoverflow.com/questions/9116425/apache-log4j-logging-with-specific-timezone logging.apache.org/log4j/1.2/faq.html#a3.4
@karandeepsingh5000
@karandeepsingh5000 6 жыл бұрын
Automation Step by Step - Raghav Pal Thanks a lot bro
@RaghavPal
@RaghavPal 6 жыл бұрын
You're welcome
@akashpatil5086
@akashpatil5086 4 жыл бұрын
what we learn is log4j or log4j2? plz clear m confused sir?
@RaghavPal
@RaghavPal 4 жыл бұрын
Hi Akash, this is a logging library to create and show logs during execution
@WorkWork-ed4vc
@WorkWork-ed4vc 2 жыл бұрын
You have Maven Project. Why did you do this with main method?
@RaghavPal
@RaghavPal 2 жыл бұрын
Pls refer the time stamp in video for me to refer
@Vinodmhetre007
@Vinodmhetre007 4 жыл бұрын
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.
@RaghavPal
@RaghavPal 4 жыл бұрын
Thanks for the tip! I will improve
@alyda4102
@alyda4102 4 жыл бұрын
Топ индус, уважаю
@RaghavPal
@RaghavPal 4 жыл бұрын
Большое спасибо. Униженный
@AmitRanjan
@AmitRanjan 3 жыл бұрын
Liked
@RaghavPal
@RaghavPal 3 жыл бұрын
Thanks Java
@tahaansari5621
@tahaansari5621 3 жыл бұрын
Hi, very helpful video. Hats off! I have a question though, how can I make different levels of logging for console and file in the same property file? E.g. I'd like to use debug level of logging for file but for console I'd like to have info level logging. P.S. this was an incredible video. Thank you!
@RaghavPal
@RaghavPal 3 жыл бұрын
Hi Taha, I will need to check on this, Will update if I find something. Thanks for watching
@tahaansari5621
@tahaansari5621 3 жыл бұрын
@@RaghavPal okay, I'll wait.
@ravindramedagam2506
@ravindramedagam2506 5 жыл бұрын
Thank you so much bro
@RaghavPal
@RaghavPal 5 жыл бұрын
You're welcome
@stutiswarnkar5147
@stutiswarnkar5147 6 жыл бұрын
After writing the .properties file. All its components are showing as unused. What to do?
@RaghavPal
@RaghavPal 6 жыл бұрын
Hi Stuti, have you referred them in your scripts. It should be fine if not creating any error
@deekshatewari4823
@deekshatewari4823 6 жыл бұрын
log folder is not getting created automatically
@RaghavPal
@RaghavPal 6 жыл бұрын
Will have to check. Pls also verify with the video, you did not miss any step
@santhosh7642
@santhosh7642 5 жыл бұрын
you might have missed selenium dependencies
@AbhishekChauhan-id7rc
@AbhishekChauhan-id7rc 4 жыл бұрын
Yes Raghav, Log folder is not being created . followed all the steps as per expected. Could you please tell the workaround for it.
@prabhudevan9034
@prabhudevan9034 5 жыл бұрын
Log4j2.properties remains same for every project?
@RaghavPal
@RaghavPal 5 жыл бұрын
You can use multiple files Prabhu
@tejkumarkempaiah6380
@tejkumarkempaiah6380 5 жыл бұрын
Raghav, Can you please add Implementing Log4J into Framework having TestBase or something similar ?
@RaghavPal
@RaghavPal 5 жыл бұрын
Hi Tej, will need more info/details on your needs
@tejkumarkempaiah6380
@tejkumarkempaiah6380 5 жыл бұрын
@@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
@RaghavPal 5 жыл бұрын
Okay I will add more sessions related to this
@tejkumarkempaiah4906
@tejkumarkempaiah4906 5 жыл бұрын
@@RaghavPal : Thank you
@tejkumarkempaiah4906
@tejkumarkempaiah4906 5 жыл бұрын
@@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 :)
@Last_30_Seconds
@Last_30_Seconds 2 жыл бұрын
After refreshed project not getting log folder please let me know why??
@RaghavPal
@RaghavPal 2 жыл бұрын
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
@Last_30_Seconds
@Last_30_Seconds 2 жыл бұрын
@@RaghavPal thanks Sir already tried but still not solved i will check again.
@ashwinidongare4147
@ashwinidongare4147 Жыл бұрын
How to overrite the file. Instead of appending
@RaghavPal
@RaghavPal Жыл бұрын
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
@meenu1107
@meenu1107 3 жыл бұрын
Log folder is not created in my project , what should i do?
@RaghavPal
@RaghavPal 3 жыл бұрын
Check the setup again Chhavi
@hboulahya
@hboulahya 4 жыл бұрын
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!!
@RaghavPal
@RaghavPal 4 жыл бұрын
Hi Hicham, pls check this stackoverflow.com/questions/12532339/no-appenders-could-be-found-for-loggerlog4j
@DucNguyen-xn5bd
@DucNguyen-xn5bd 5 жыл бұрын
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.
@RaghavPal
@RaghavPal 5 жыл бұрын
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
@marcscherzer
@marcscherzer 3 жыл бұрын
Are log4j and log4js same?
@RaghavPal
@RaghavPal 3 жыл бұрын
Hi Marc, log4js is different, check www.npmjs.com/package/log4js
Selenium Framework for Beginners 15 | How to add Log4j xml file in Java project
9:22
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 36 МЛН
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
How to Generate Log Files in Selenium using Log4j API
32:50
Naveen AutomationLabs
Рет қаралды 118 М.
Log4j2 logging in Selenium Java Framework using Log4j2 Properties & Log4j2 xml
28:24
SDET Adda For QA Automation
Рет қаралды 24 М.
Selenium Framework for Beginners 17 | What is Properties File | How to use
26:30
Automation Step by Step
Рет қаралды 46 М.
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 36 МЛН