登录Groovy脚本 [英] Logging in Groovy Script

查看:130
本文介绍了登录Groovy脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的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屋!

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