3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

SpringBoot+Kotlinでログを出力する方法

Posted at

はじめに

SpringBootでログを出そうとしたときに結構時間がかかってしまったのでまとめます
実際やり方がわかれば簡単でしたが、ここまで時間がかかったのはなぜなのでしょうか

やり方

まずはbuild.gradle.ktに以下を追加します

build.gradle.kt
	implementation("org.springframework.boot:spring-boot-starter-aop")

application.propertiesに以下を追加

application.properties
logging.level.root=INFO

そして、ログを出したい箇所に以下を追加します

import org.slf4j.LoggerFactory

private val logger = LoggerFactory.getLogger(ToDoController::class.java)

logger.info("ここにログで表示する文章を書く")

おわりに

SpringBootでLoggerFactoryをインポートしたかったのですが、何故かslf4jが見つからず、spring-boot-starter-aopを入れることでログを表示できるようになりました

参考

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?