登录Groovy脚本 [英] Logging in Groovy Script
问题描述
我有一个基本的Groovy脚本,我正在尽可能简单地创建日志。我希望邮件转到stdout以及日志文件,并且日志文件中的每个条目都会有一个时间戳。
我不能使用@记录符号,因为它是一个脚本,我没有要注入的类。这可能是理想的,否则我认为。
您可以在脚本中使用以下模式(在Groovy Editor中尝试)。
import java.util.logging.Logger
Logger logger = Logger.getLogger()
logger.info(我是测试信息日志)
上述日志输出到STDOUT。为了将其记录到文件中,您必须使用 getLogger
创建一个记录器。请遵循 API ,以方便您使用。
I have a basic Groovy script, and I'm looking to create logs as simply as possible. I want the message to go to stdout, as well as a log file, and each entry in the log file would have a timestamp.
I can't use the @Log notation, because it's a script, and I don't have a class to inject into. This would have been ideal otherwise I think.
You can have the below pattern in your script (tried in Groovy Editor).
import java.util.logging.Logger
Logger logger = Logger.getLogger("")
logger.info ("I am a test info log")
The above logs output to STDOUT. In order to log it to a file, you have to create a logger using getLogger
. Follow the API for your convenience.
这篇关于登录Groovy脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!