2016-07-24 20:31:45.280 INFO 10220 --- [ main] c.d.SpringBootHelloWorldApplication : Starting SpringBootHelloWorldApplication on NODTBSL206AG with PID 10220 (started by Dinesh.Rajput in D:personal dataspring-boot-workspaceSpringBootHelloWorld) 2016-07-24 20:31:45.286 INFO 10220 --- [ main] c.d.SpringBootHelloWorldApplication : No active profile set, falling back to default profiles: default 2016-07-24 20:31:45.502 INFO 10220 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@1809907: startup date [Sun Jul 24 20:31:45 IST 2016]; root of context hierarchy 2016-07-24 20:31:48.201 INFO 10220 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http) 2016-07-24 20:31:48.226 INFO 10220 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat 2016-07-24 20:31:48.228 INFO 10220 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.3 2016-07-24 20:31:48.485 INFO 10220 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2016-07-24 20:31:48.485 INFO 10220 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2993 ms
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.dineshonjava</groupId> <artifactId>SpringBootHelloWorld</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>SpringBootHelloWorld</name> <description>SpringBootHelloWorld project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.0.RC1</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
package com.dineshonjava; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @SpringBootApplication public class SpringBootHelloWorldApplication { private static final Logger logger = LoggerFactory.getLogger(SpringBootHelloWorldApplication.class); @RequestMapping("/") String home() { return "Hello World!"; } public static void main(String[] args) { SpringApplication.run(SpringBootHelloWorldApplication.class, args); logger.error("Message logged at ERROR level"); logger.warn("Message logged at WARN level"); logger.info("Message logged at INFO level"); logger.debug("Message logged at DEBUG level"); } }
2016-07-24 20:57:40.828 ERROR 3024 --- [ main] c.d.SpringBootHelloWorldApplication : Message logged at ERROR level 2016-07-24 20:57:40.828 WARN 3024 --- [ main] c.d.SpringBootHelloWorldApplication : Message logged at WARN level 2016-07-24 20:57:40.828 INFO 3024 --- [ main] c.d.SpringBootHelloWorldApplication : Message logged at INFO level
<?xml version="1.0" encoding="UTF-8"?> <configuration> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <!-- Log message format --> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n </pattern> </encoder> </appender> <!-- Setting the root level of logging to INFO --> <root level="info"> <appender-ref ref="STDOUT" /> </root> </configuration>
21:14:46.352 [main] ERROR c.d.SpringBootHelloWorldApplication - Message logged at ERROR level 21:14:46.352 [main] WARN c.d.SpringBootHelloWorldApplication - Message logged at WARN level 21:14:46.352 [main] INFO c.d.SpringBootHelloWorldApplication - Message logged at INFO level
<?xml version="1.0" encoding="UTF-8"?> <configuration> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <!-- Log message format --> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> <!-- Need appender to write to file --> <appender name="FILE" class="ch.qos.logback.core.FileAppender"> <!-- Name of the file where the log messages are written --> <file>MySpringBootApp.log</file> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> <logger name="com.dineshonjava.service" level="warn"> <appender-ref ref="FILE" /> </logger> <!-- Setting the root level of logging to INFO --> <root level="info"> <appender-ref ref="FILE" /> </root> </configuration>
package com.dineshonjava.service; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class HelloService { private Logger logger = LoggerFactory.getLogger(HelloService.class); public void service(){ logger.info("Message at INFO level from HelloService.service()"); logger.warn("Message at WARN level from HelloService.service()"); } }
Spring Boot Related Topics
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…