Groovy Script and log4j

前端 未结 2 1811
长发绾君心
长发绾君心 2021-02-04 02:42

Been searching here and there looking for a working example of log4j logging to file in a Groovy script.

No explicit class (it\'s just a script). No grails. Not to conso

2条回答
  •  情话喂你
    2021-02-04 03:12

    Another way to do this would be to use Groovy's logging package. You can use the same easily my importing the util logging and using the @Log annotation like in this example

    import groovy.util.logging.*
    
    @Log
    class Test{
        public class() {
            log.debug "Logging"
        }
    }
    

    However, since the annotation works on a class, you would need to create your groovy script inside a class. Free form scripts don't get the logger access this way.

    Hope this helps.

提交回复
热议问题