Skip to main content

Posts

Log4j : How To Log Message To Console

Introduction This tutorial will help you to log all level messages into console using Log4j plugin. In previous tutorial we have seen how to setup the log4j plugin in Maven and simple logging application. If you need to understand the basic of Log4J the visit previous tutorial. What we will do in this tutorial We saw in the previous tutorial that Log4J's default configuration set the logging level to Error, causing it to log only errors and fatal messages to the console. To overcome this problem, we need to override the default configuration. To do so, we need to write a Log4j configuration file named Log4j2.xml and update the correct logging level.  Log4j supports YAML, JSON, and XML file formats for its configuration files. For this tutorial we are using  Log4j2.xml Sample Log4j2.xml <?xml version="1.0" encoding="UTF-8"?> <Configuration status= "ERROR" > <Appenders> <Console name= "Console" target
Recent posts

Getting Started With Log4j Logging

Introduction For Java applications, Log4j is a commonly used and trusted logging tool. When an application is deployed to an application server, logging is a must-have feature. In this tutorial, we'll see how to set up Log4j for a simple Java application. You can find all code related to this tutorial inside GitHub project. Why do we need Logging Logging is an important part of the application since it records user actions, input requests and output responses, error messages, and more. This information aids in the understanding of the application both inside and outside of it, as well as providing faster feedback or support for any issues that may occur during the application's execution. Maven configuration Add following dependencies into pom.xml pom.xml <dependencies> <dependency> <groupId> org.apache.logging.log4j </groupId> <artifactId> log4j-api </artifactId> <version> 2.17.2 </version>

Maven : Create JaCoCo Code Coverage Report

Introduction In this tutorial we will see how to setup the JaCoCo plugin to generate a code coverage report for a Maven project. In order to generate a unit test coverage report, we should have sufficient unit test cases in our application. For this tutorial, I am referring to a Maven project which has a string manipulation method. You can find this project at this GitHub location. There are a few steps that need to be taken to produce the report. Install the Maven JaCoCo plugin. Insert the following code into pom.xml. <plugin> <groupId> org.jacoco </groupId> <artifactId> jacoco-maven-plugin </artifactId> <version> 0.8.2 </version> <executions> <execution> <goals> <goal> prepare-agent </goal> </goals> </execution> <execution> <id> report </id> <phase> test <

Spring Boot RestTemplate Guide with Example

What is RestTemplet? RestTemplate is a HTTP Client library that provides basic APIs for executing different HTTP type requests. RestTemplate is one of the HTTP libraries available on the market. The Spring Boot team designed and maintains it. As previously said, it is a client library, which means it may be utilised in our application as a stand-alone dependency. To utilise it, you don't require a complete Spring boot application. It's suitable for use in simple Java applications as well as other frameworks such as Micronaut, Play and others. Setup Add RestTemplate dependency to project, for this tutorial I am creating a simple java application to consume HTTP request and a node application to provide HTTP service. For Gradle build tool Add the following dependency in the build.gradle file . // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web implementation group: 'org.springframework.boot' , name: 'spring-boot-starter-w

How to Change a Git Commit Message?

In this tutorial, we'll go over how to fix Git commit messages that have been committed to a local or remote Git repository. Reason to change commit message? When working with Git, there could be several reasons to update the commit message. Some of the common reasons are as follows: Message contains a typo. Missing intent of commit. Remove any confidential information. Correct issue ticket number to connect to an issue tracker such as Jira. Solution The reason could be anything, but you should be aware of the command to update the commit message at any point in the development of your application. Let's take a look at the solution for a single commit message. local commit Assume you perform the following Git operation $ git add -A $ git commit -m "[PROJECT-99] - Added user profile module." And after you realise that the issue number for the current commit is incorrect and needs to be corrected. That's the story of Project 100. You can correct it

How to enable SQL logs in Spring Boot application?

This tutorial will demonstrate how to enable and disable SQL log statements in a Spring Boot application in order to debug SQL flow. Problem You will frequently need to debug the SQL statement while developing a Spring Boot application with a SQL database. SQL debug logs can assist you figure out what's wrong with JPA statements and whether or not there's a problem with database connectivity. Example  If you've built custom Spring data JPA methods and need to know what SQL statement is being utilized behind them, return repository . findByUsernameIn ( usernames ); Then you can enable Hibernet debug mode to log SQL statements. Solution Update the application.yml file with the Hibernet configuration as logging: level: org: hibernate: DEBUG or application.properties as logging.level.org.hibernate=DEBUG The SQL statement will appear in the application logs after modifying the configuration file and restarting the application. 2022-04-07 08:41

Subscribe for latest tutorial updates

* indicates required