@@ -2115,159 +2115,7 @@ In this example, we also set the `strict` parameter to false, which allows us to
21152115
21162116Deprecated. Consider using traits instead.
21172117
2118- ==== Logging improvements
2119-
2120- Groovy provides a family of AST transformations that help with integration of the most widely
2121- used logging frameworks. There is a transform and associated annotation for each of the common frameworks.
2122- These transforms provide a streamlined declarative approach to using the logging framework.
2123- In each case, the transform will:
2124-
2125- * add a static final `log` field to the annotated class corresponding to the logger
2126- * wrap all calls to `log.level()` into the appropriate `log.isLevelEnabled` guard, depending on the underlying framework
2127-
2128- Those transformations support two parameters:
2129-
2130- * `value` (default `log`) corresponds to the name of the logger field
2131- * `category` (defaults to the class name) is the name of the logger category
2132-
2133- It's worth noting that annotating a class with one of those annotations doesn't
2134- prevent you from using the logging framework using the normal long-hand approach.
2135-
2136- [[xform-Log]]
2137- ===== `@groovy.util.logging.Log`
2138-
2139- The first logging AST transformation available is the `@Log` annotation which relies on the JDK logging framework. Writing:
2140-
2141- [source,groovy]
2142- ----
2143- include::../test/LogImprovementsASTTransformsTest.groovy[tags=log_spec,indent=0]
2144- ----
2145-
2146- is equivalent to writing:
2147-
2148- [source,groovy]
2149- ----
2150- include::../test/LogImprovementsASTTransformsTest.groovy[tags=log_equiv,indent=0]
2151- ----
2152-
2153- [[xform-Commons]]
2154- ===== `@groovy.util.logging.Commons`
2155-
2156- Groovy supports the http://commons.apache.org/proper/commons-logging/[Apache Commons Logging] framework using the
2157- `@Commons` annotation. Writing:
2158-
2159- [source,groovy]
2160- ----
2161- include::../test/LogImprovementsASTTransformsTest.groovy[tags=commons_spec,indent=0]
2162- ----
2163-
2164- is equivalent to writing:
2165-
2166- [source,groovy]
2167- ----
2168- include::../test/LogImprovementsASTTransformsTest.groovy[tags=commons_equiv,indent=0]
2169- ----
2170-
2171- You still need to add the appropriate commons-logging jar to your classpath.
2172-
2173- [[xform-Log4j]]
2174- ===== `@groovy.util.logging.Log4j`
2175-
2176- Groovy supports the http://logging.apache.org/log4j/1.2/[Apache Log4j 1.x] framework using the
2177- `@Log4j` annotation. Writing:
2178-
2179- [source,groovy]
2180- ----
2181- include::../test/LogImprovementsASTTransformsTest.groovy[tags=log4j_spec,indent=0]
2182- ----
2183-
2184- is equivalent to writing:
2185-
2186- [source,groovy]
2187- ----
2188- include::../test/LogImprovementsASTTransformsTest.groovy[tags=log4j_equiv,indent=0]
2189- ----
2190-
2191- You still need to add the appropriate log4j jar to your classpath.
2192- This annotation can also be used with the compatible https://reload4j.qos.ch/[reload4j] log4j
2193- drop-in replacement, just use the jar from that project instead of a log4j jar.
2194-
2195- [[xform-Log4j2]]
2196- ===== `@groovy.util.logging.Log4j2`
2197-
2198- Groovy supports the http://logging.apache.org/log4j/2.x/[Apache Log4j 2.x] framework using the
2199- `@Log4j2` annotation. Writing:
2200-
2201- [source,groovy]
2202- ----
2203- include::../test/LogImprovementsASTTransformsTest.groovy[tags=log4j2_spec,indent=0]
2204- ----
2205-
2206- is equivalent to writing:
2207-
2208- [source,groovy]
2209- ----
2210- include::../test/LogImprovementsASTTransformsTest.groovy[tags=log4j2_equiv,indent=0]
2211- ----
2212-
2213- You still need to add the appropriate log4j2 jar to your classpath.
2214-
2215- [[xform-Slf4j]]
2216- ===== `@groovy.util.logging.Slf4j`
2217-
2218- Groovy supports the http://www.slf4j.org/[Simple Logging Facade for Java (SLF4J)] framework using the
2219- `@Slf4j` annotation. Writing:
2220-
2221- [source,groovy]
2222- ----
2223- include::../test/LogImprovementsASTTransformsTest.groovy[tags=slf4j_spec,indent=0]
2224- ----
2225-
2226- is equivalent to writing:
2227-
2228- [source,groovy]
2229- ----
2230- include::../test/LogImprovementsASTTransformsTest.groovy[tags=slf4j_equiv,indent=0]
2231- ----
2232-
2233- You still need to add the appropriate slf4j jar(s) to your classpath.
2234-
2235- [[xform-PlatformLog]]
2236- ===== `@groovy.util.logging.PlatformLog`
2237-
2238- Groovy supports the https://openjdk.org/jeps/264[Java Platform Logging API and Service]
2239- framework using the `@PlatformLog` annotation. Writing:
2240-
2241- [source,groovy]
2242- ----
2243- @groovy.util.logging.PlatformLog
2244- class Greeter {
2245- void greet() {
2246- log.info 'Called greeter'
2247- println 'Hello, world!'
2248- }
2249- }
2250- ----
2251-
2252- is equivalent to writing:
2253-
2254- [source,groovy]
2255- ----
2256- import java.lang.System.Logger
2257- import java.lang.System.LoggerFinder
2258- import static java.lang.System.Logger.Level.INFO
2259-
2260- class Greeter {
2261- private static final transient Logger log =
2262- LoggerFinder.loggerFinder.getLogger(Greeter.class.name, Greeter.class.module)
2263- void greet() {
2264- log.log INFO, 'Called greeter'
2265- println 'Hello, world!'
2266- }
2267- }
2268- ----
2269-
2270- You need to be using JDK 9+ to use this capability.
2118+ include::../../../subprojects/groovy-logging-test/src/spec/doc/logging-transforms.adoc[]
22712119
22722120==== Declarative concurrency
22732121
0 commit comments