EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Spring Tutorial Spring boot logging level
Secondary Sidebar
Spring Tutorial
  • Spring Boot
    • What is Spring Boot
    • Spring Boot flyway
    • Spring Boot framework
    • Spring Boot Logback
    • Spring Boot actuator endpoints
    • Spring Boot gRPC
    • Spring Boot jdbctemplate example
    • Spring Boot ehcache
    • Spring Boot Architecture
    • Spring Boot Port
    • Introduction of spring boot
    • Spring Boot ide
    • Spring Boot Netty
    • Spring Boot ORM
    • Spring Boot Versions
    • Spring Boot JUnit
    • Spring Boot Keycloak
    • Spring Boot gradle
    • Spring Boot Lombok
    • Spring Boot autowired
    • Spring Boot bean
    • Spring Boot hibernate
    • Spring Boot integration test
    • Spring Boot jdbc
    • Spring Boot MongoDB
    • Spring Boot postgresql
    • Spring Boot rest
    • Spring Boot swagger
    • Spring Boot thymeleaf
    • Spring Boot Unit Test
    • Spring Boot Webflux
    • Spring Boot webclient
    • Spring Boot kubernetes
    • Spring Boot Properties
    • Spring Boot Validation
    • Spring Boot Feature
    • Spring Boot Application
    • Spring Boot email
    • Spring Boot MVC
    • Spring Boot Exception Handling
    • Spring Boot Starter Parent
    • Spring Boot Docker
    • Spring Boot Logging
    • Spring Boot Query
    • Spring Boot Multiple Data Sources
    • Spring Boot Basic Authentication
    • Spring Boot Test
    • Spring Boot jwt
    • Spring Boot Liquibase
    • Spring Boot Prometheus
    • Spring Boot debug
    • Spring Boot GraalVM
    • Spring Boot Batch
    • Spring Boot controller
    • Spring Boot CLI
    • Spring Boot file upload
    • Spring Boot interceptor
    • Spring Boot Service
    • Spring Boot Configuration
    • Spring Boot Datasource Configuration
    • Spring Boot Annotations
    • Spring Boot Starter We
    • Spring Boot Actuator
    • Spring Boot DevTools
    • Spring Boot Repository
    • Spring Boot Dependencies
    • Spring Boot Path Variable
    • Spring Boot Microservices
    • Spring Boot Run Command
    • Spring Boot application.properties
    • Spring Boot Transaction Management
    • Spring Boot Banner
    • Spring Boot JPA
    • Spring Boot Change Port
    • Spring Boot RestTemplate
    • Spring Boot cors
    • Spring Boot HTTPS
    • Spring Boot OAuth2
    • Spring Boot Profiles
    • Spring Boot Interview Questions
    • Spring Boot filter
    • Spring boot logging level
    • Spring Boot Cache
    • Spring Boot Advantages
    • Spring Boot Scheduler
    • Spring Boot Initializr
    • Spring Boot Maven
    • Spring Boot Admin
    • Spring Boot Tomcat
    • Spring Boot WebSocket
    • Spring Boot Executable Jar
    • Spring Boot CommandLineRunner
    • Spring Boot DataSource
    • Spring Batch Scheduler
    • Spring Batch Example
    • Spring Batch Tasklet
    • Spring Batch Admin
    • Spring Batch
    • Spring Boot Qualifier
    • Spring Boot War
    • Spring Boot Test Configuration
  • Spring
    • What is Spring Framework?
    • Spring Architecture
    • What is Spring Integration?
    • IoC Containers
    • What is AOP?
    • Spring Modules
    • Spring Batch Processing
    • Spring Batch Partitioner
    • Spring Batch Job
    • Spring AOP
    • Spring Expression Language
    • Dependency Injection in Spring
    • Spring Batch Architecture
    • Spring framework Interview Questions
  • Spring Cloud Basics
    • What is Spring Cloud
    • Spring Cloud Contract
    • Spring Cloud Components
    • Spring Cloud Version
    • Spring Cloud Data Flow
    • Spring cloud stream
    • Spring Cloud Dependencies
    • Spring cloud microservices
    • spring cloud gateway
    • Spring Cloud Config
    • Spring Cloud Kubernetes
    • Spring Cloud Sleuth

Related Courses

Spring Boot Certification Course

Spring Framework Course Training

All in One Data Science Course

Spring boot logging level

Spring boot logging level

Introduction to Spring boot logging level

In spring boot, it is very easy to log at a different level; also, spring boot provides us default logging. While using it, we do not require an external dependency because it is already included. Logging is used to keep track of all the activity of our application; by the use of this, we can identify the errors in our application at runtime if they occur. Also, we can check and track if the application working fine. These are very easy to use and handle because we do not require lots of configuration for this as the spring boot framework manages it. In the coming section of the tutorial, we will see the different logging levels in the spring boot application and how we can set them in our application for better error tracking purpose in detail.

Syntax

As we have seen we can set different logging level in spring boot let’s take a look at the syntax and required things which are needed to make this work in our application for better understanding see below;

logging.level.root= your logging level

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

As you can see in the above line of syntax, we are trying to configure the log level. For this, we have to make the above changes to our applications.properties file, and we can set the log level whichever we want. Let’s take a look at the practice syntax for better understanding see below;

Example:

logging.level.root=DEBUG

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,818 ratings)

As you can have mentioned, this type of configuration enables the logging level at DEBUG level. In the coming section, we will see all the logging levels in spring boot with their respective working in detail and how to print the statement using those logs level in detail for beginners to understand it better.

How to set logging level in Spring boot?

In spring boot, we can set different logging levels, also with minimum configuration needed. This log level is important when we deploy our application in the development and production environment to keep track of any error or say all the activity. We have different types of log levels available in spring boot to make sure not any unnecessary logs can’t be printed on the production environment, which can lose any kind of information to anyone who is not authorized for that. In this section, we will first see the different type of logging level in detail, how they work and how we can use them in spring boot; see below, which are as follows;

1. INFO

This kind of information or logs should not contain the error or details of something. They are just used to inform the developers that everything is working fine. We can add logs as service has started, service has stopped, any db operations; we can trace all these kinds of logs that come under this INFO level general-purpose logs that tell the application’s activity.

Example:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Service
public class MyClass {
private static final Logger logger = LoggerFactory.getLogger(MyClass.class);
private void test(){
logger.info("I am info level log !!");
}
}
application.properties
logging.level.root=INFO

As you can see in the above code, we have implemented the info level logs; for this, we have to first initiate the LoggerFactory inside that we pass the name of our class, now we can use this. by calling the info() method on it.

2. DEBUG

In this mode, we want to monitor the information related to an application, like if the user got created, trying to print their id and all. This will come into the picture when we want to capture the production activity closely. Below see the syntax to use this;

Example:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Service
public class MyClass {
private static final Logger logger = LoggerFactory.getLogger(MyClass.class);
private void test(){
logger.debug("I am info debug log !!");
}
}
application.properties
logging.level.root=DEBUG

As you can see in the above code, we have implemented the debug level logs; for this, we have to first initiate the LoggerFactory inside that we pass the name of our class, now we can use this debug() method on it.

3. ERROR

This type of logging level is used when we want to capture the error in our application, causing the application to be down and breaking the functionality to work properly. We can track database connections, any file missing, or something serious which is causing the application to stop. Below see the syntax to use this in the spring boot application see below;

Example:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Service
public class MyClass {
private static final Logger logger = LoggerFactory.getLogger(MyClass.class);
private void test(){
logger.error("I am error level log !!");
}
}
application.properties
logging.level.root=ERROR

As you can see in the above code, we have implemented the error level logs; for this, we have to first initiate the LoggerFactory inside that we pass the name of our class; now, we can use this. by calling the error() method on it.

4. WARN

In this type of logs, we track the warning, which can lead the application to stop; suppose we are trying to establish a connection, but somehow it is falling and not able to connect, so in this kind of siltation, we can use warn level, which can predict any future cause to our application. Below see the syntax to use this in the spring boot application see below;

Example:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Service
public class MyClass {
private static final Logger logger = LoggerFactory.getLogger(MyClass.class);
private void test(){
logger.warn("I am warn level log !!");
}
}
application.properties
logging.level.root=WARN

As you can see in the above code, we have implemented the warn level logs; for this, we have to first initiate the LoggerFactory inside that we pass the name of our class, now we can use this. by calling the warn() method on it.

Conclusion

By using the logging level, we can easily divide our information logs not to be printed in different environments. We have to make normal changes to the application properties of the respective environment.

Recommended Articles

This is a guide to the Spring boot logging level. Here we discuss How to set the logging level in the Spring boot along with the examples. You may also have a look at the following articles to learn more –

  1. Spring Boot DevTools
  2. Spring Boot Starter Web
  3. Dompdf Laravel
  4. Spring AOP
Popular Course in this category
Spring Boot Training Program (2 Courses, 3 Project)
  2 Online Courses |  3 Hands-on Projects |  22+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Spring Framework Training (4 Courses, 6 Projects)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more