Last active
December 17, 2020 17:54
-
-
Save david-hosier/df7d41bb1c19dcb9bf3f14d8147d6c17 to your computer and use it in GitHub Desktop.
This gist shows how to use an injected Log4j logger in a Groovy script. Note that the injection only works on a class. This is an example of using Log4j2 with the latest version as the time of writing. If the log4j2.xml file lives in the same directory as the script, it will automatically be used to configure logging. Inspired by https://stackov…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab(group='org.apache.logging.log4j', module='log4j-core', version='2.14.0') | |
@Grab(group='org.apache.logging.log4j', module='log4j-api', version='2.14.0') | |
import org.apache.log4j.* | |
import groovy.util.logging.* | |
@Log4j2 | |
class LoggingTest { | |
def execute() { | |
log.info "Yay, it worked!" | |
} | |
} | |
def test = new LoggingTest() | |
test.execute() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<Configuration status="INFO"> | |
<Appenders> | |
<Console name="Console" target="SYSTEM_OUT"> | |
<PatternLayout pattern="%d{HH:mm:ss.SSS}: %-5level: %msg%n%n"/> | |
</Console> | |
</Appenders> | |
<Loggers> | |
<Root level="info"> | |
<AppenderRef ref="Console" /> | |
</Root> | |
</Loggers> | |
</Configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment