当前位置: 首页 > 知识库问答 >
问题:

未解析的引用:日志

文英达
2023-03-14
package com.main.inventoryservice.controller

import com.main.inventoryservice.model.Inventory
import com.main.inventoryservice.repository.InventoryRepository
import lombok.RequiredArgsConstructor
import lombok.extern.slf4j.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*
import java.util.*


@RestController
@RequestMapping("/inventory")
@RequiredArgsConstructor
@Slf4j
class InventoryController {
    @Autowired
    private lateinit var inventoryRepository: InventoryRepository

@GetMapping("/{skuCode}")
fun isInStock(@PathVariable skuCode: String): Boolean? {
    log.info("Checking stock for product with skucode - $skuCode")
    val (_, _, stock) = inventoryRepository.findBySkuCode(skuCode)
        .orElseThrow { RuntimeException("Cannot Find Product by sku code $skuCode") }
    return stock!! > 0
}
}
log.info("Checking stock for product with skucode - $skuCode")
unresolved refrence :log
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id("org.springframework.boot") version "2.5.2"
    id("io.spring.dependency-management") version "1.0.11.RELEASE"
    kotlin("jvm") version "1.5.20"
    kotlin("plugin.spring") version "1.5.20"
    kotlin("plugin.jpa") version "1.5.20"
}

group = "com.main"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11

repositories {
    mavenCentral()
}

extra["springCloudVersion"] = "2020.0.3"

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-amqp")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.springframework.boot:spring-boot-starter-oauth2-resource-server")
    implementation("org.springframework.boot:spring-boot-starter-security")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation("org.springframework.cloud:spring-cloud-sleuth-zipkin")
    implementation("org.springframework.security:spring-security-oauth2-jose:5.4.6")
    implementation("org.springframework.cloud:spring-cloud-starter")
    implementation("org.springframework.cloud:spring-cloud-stream-binder-rabbit:3.1.3")
    implementation("org.springframework.cloud:spring-cloud-starter-bus-amqp:3.0.2")
    implementation("org.springframework.cloud:spring-cloud-starter-config")
    implementation("net.logstash.logback:logstash-logback-encoder:6.6")
    implementation("org.springframework.cloud:spring-cloud-starter-sleuth")
    runtimeOnly("mysql:mysql-connector-java")
    compileOnly("org.projectlombok:lombok")
    annotationProcessor("org.projectlombok:lombok")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    testImplementation("org.springframework.amqp:spring-rabbit-test")
    testImplementation("org.springframework.security:spring-security-test")
}

dependencyManagement {
    imports {
        mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
    }
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "11"
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}

我想通过日志打印一些消息,所以我使用log.info(),但它不工作,并在日志内容上显示错误

共有1个答案

莫逸仙
2023-03-14

您应该使用java.util.logging.logger:

>

  • 导入:

    import java.util.logging.Logger;
    

    创建:

    class YourClass {
        private static final Logger logger = Logger.getLogger("MyLogger");
    }
    
    class YourClass {
        private static final Logger logger = Logger.getLogger("MyLogger");
    
        public void some() {
            logger.severe(":(");
            logger.warning(":|");
            logger.info(":)");
        }
    }
    

  •  类似资料: