Coming from a Node background, what is the equivalent of console.log() in spring boot?
For example I'd like to see in my console the job info in the following method.
@RequestMapping(value = "jobposts/create", method = RequestMethod.POST)
public Job create(@RequestBody Job job){
System.out.println(job);
return jobRepository.saveAndFlush(job);
}
System.out.println(); is how I know to do it in Java but it doesn't seem to appear in my console. Using IntelliJ.
Configuring the file name and path To make Spring Boot write its log to disk, set the path and filename. With this configuration, Spring Boot will write to the console and also to a log file called spring. log , at the path you specify.
Run Spring Boot Application with the Command LineOpen terminal window and change directory to the root folder of your Spring Boot application. If you list files in this directory, you should see a pom. xml file. You can also run your Spring Boot application as an executable Java jar file.
By default, Spring Boot will only log to the console and will not write log files. If you want to write log files in addition to the console output you need to set a logging. file or logging. path property (for example in your application.
Spring Boot helps developers create applications that just run. Specifically, it lets you create standalone applications that run on their own, without relying on an external web server, by embedding a web server such as Tomcat or Netty into your app during the initialization process.
System.out.println(job);
like you have done.
It prints something like yourpackage.Job@2g45e0f9
Try to execute you code using debug mode and see if the post method will be executed as it has to do.
Did you tried adding console appender in you logging configuration file.? Here is how you can do in slf4j + logback ecosystem
in logback.xml,
<configuration>
<appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<timeZone>UTC</timeZone>
</encoder>
</appender>
<logger name="com.yourcompany.packagename" level="INFO" additivity="false">
<appender-ref ref="consoleAppender" />
</logger>
<root level="ERROR">
<appender-ref ref="consoleAppender" />
</root>
</configuration>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With