我如何在 src/groovy/类中使用“日志" [英] How can i use 'log' inside a src/groovy/ class

查看:26
本文介绍了我如何在 src/groovy/类中使用“日志"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了这个错误:

groovy.lang.MissingPropertyException:没有这样的属性:日志类:org.utils.MyClass

groovy.lang.MissingPropertyException: No such property: log for class: org.utils.MyClass

课程内容如下:

package org.utils

class MyClass {
    int organizationCount = 0

    public int getOrganizationCount(){
        log.debug "There are ${organizationCount} organization(s) found."
        return organizationCount
    }

}

我需要添加导入语句吗?我需要添加什么?请注意,该类位于 src/groovy/org/utils 中.我知道可以在控制器、服务等中访问log"变量.在src"类中不确定.

Do i need to add an import statement? What do i need to add? Note that the class is located in src/groovy/org/utils. I know that the 'log' variable is accessible in controllers, services, etc. Not sure in 'src' classes.

谢谢.

推荐答案

在 grails 3 中,默认的日志系统是 logback.只需将 @Slf4j 注释添加到您的 src/groovy 类即可解决问题.

In grails 3, the default logging system is logback. Simply adding the @Slf4j annotation to your src/groovy class will take care of things.

import groovy.util.logging.Slf4j

@Slf4j
class MyUtil {

这篇关于我如何在 src/groovy/类中使用“日志"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆