[
https://issues.apache.org/jira/browse/GROOVY-11049?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17721594#comment-17721594
]
Paul King edited comment on GROOVY-11049 at 5/11/23 3:01 AM:
-------------------------------------------------------------
h2. Short answer
The following should work with recent versions of Groovy 3.0.x:
{code:java}
@Grab('ch.qos.logback:logback-classic:1.2.12')
@GrabConfig(systemClassLoader=true)
import org.slf4j.LoggerFactory
...
{code}
The following should work with recent versions of Groovy 4.0.x:
{code:java}
@Grab('ch.qos.logback:logback-classic:1.4.7')
@GrabConfig(systemClassLoader=true)
import org.slf4j.LoggerFactory
...
{code}
h2. Longer answer
While Groovy supports all the logging platforms, Groovy doesn't have any
logging requirements itself. I presume you are using a standard install of
Groovy. If this is the case, the interaction you are seeing is because testng
from 7.5 added slf4j-api as a required dependency and we include testng in the
standard install.
Options:
* Don't use the standard install but rather set up your own
dependencies/classpath with a build tool
* If you don't use testng, delete the slf4j-api jar in your install (in which
case you want need the @GrabExclude line above)
* If you don't want to use the logback versions described above, replace the
slf4j-api jar in your installation with one compatible with the version of
logback that you want to use
was (Author: paulk):
h2. Short answer
The following should work with recent versions of Groovy 3.0.x:
{code:java}
@Grab('ch.qos.logback:logback-classic:1.2.12')
@GrabConfig(systemClassLoader=true)
import org.slf4j.LoggerFactory
...
{code}
The following should work with recent versions of Groovy 4.0.x:
{code:java}
@Grab('ch.qos.logback:logback-classic:1.4.7')
@GrabConfig(systemClassLoader=true)
import org.slf4j.LoggerFactory
...
{code}
h2. Longer answer
While Groovy supports all the logging platforms, Groovy doesn't have any
logging requirements itself. I presume you are using a standard install of
Groovy. If this is the case, the interaction you are seeing is because testng
from 7.5 added slf4j-api as a required dependency and we include testng in the
standard install.
Options:
* Don't use the standard install but rather set up your own
dependencies/classpath with a build tool
* If you don't use testng, delete the slf4j-api jar in your install
* If you don't want to use the logback versions described above, replace the
slf4j-api jar in your installation with one compatible with the version of
logback that you want to use
> Logging with Slf4j doesn't work in scripts
> ------------------------------------------
>
> Key: GROOVY-11049
> URL: https://issues.apache.org/jira/browse/GROOVY-11049
> Project: Groovy
> Issue Type: Bug
> Components: GroovyScriptEngine
> Affects Versions: 3.0.10, 3.0.17, 4.0.12
> Environment: OS: Mac OS X, Ubuntu 22.04
> Groovy versions affected: 3.0.10+, 4.x
> Groovy versions working as expected: 2.5.x(2.5.22), 3.x till 3.0.9
> JDK versions: Tested in JDK11 and JDK17
> Reporter: Devaprasadh Xavier
> Priority: Major
>
> *Test script:*
> {code:java}
> @Grab(group = 'ch.qos.logback', module = 'logback-classic', version = '1.4.7')
> import org.slf4j.LoggerFactory
> LoggerFactory.getLogger('test').info('Hello, World!')
> {code}
> *Expected output: (works in 2.5.22 and 3.x till 3.0.9)*
> {code:java}
> 07:21:03.685 [main] INFO test -- Hello, World! {code}
> *Actual output in 3.x versions above 3.0.9:*
> {code:java}
> SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
> SLF4J: Defaulting to no-operation (NOP) logger implementation
> SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further
> details.
> {code}
> *Actual output in 4.x versions:* **
> {code:java}
> SLF4J: No SLF4J providers were found.
> SLF4J: Defaulting to no-operation (NOP) logger implementation
> SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)