//////////////////////////////////////////

  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.

//////////////////////////////////////////
==== Logging improvements

Groovy provides a family of AST transformations that help with integration of the most widely
used logging frameworks. There is a transform and associated annotation for each of the common frameworks.
These transforms provide a streamlined declarative approach to using the logging framework.
In each case, the transform will:

* add a static final `log` field to the annotated class corresponding to the logger
* wrap all calls to `log.level()` into the appropriate `log.isLevelEnabled` guard, depending on the underlying framework

Those transformations support two parameters:

* `value` (default `log`) corresponds to the name of the logger field
* `category` (defaults to the class name) is the name of the logger category

It's worth noting that annotating a class with one of those annotations doesn't
prevent you from using the logging framework using the normal long-hand approach.

[[xform-Log]]
===== `@groovy.util.logging.Log`

The first logging AST transformation available is the `@Log` annotation which relies on the JDK logging framework. Writing:

[source,groovy]
----
include::../test/LogImprovementsASTTransformsTest.groovy[tags=log_spec,indent=0]
----

is equivalent to writing:

[source,groovy]
----
include::../test/LogImprovementsASTTransformsTest.groovy[tags=log_equiv,indent=0]
----

[[xform-Commons]]
===== `@groovy.util.logging.Commons`

Groovy supports the http://commons.apache.org/proper/commons-logging/[Apache Commons Logging] framework using the
`@Commons` annotation. Writing:

[source,groovy]
----
include::../test/LogImprovementsASTTransformsTest.groovy[tags=commons_spec,indent=0]
----

is equivalent to writing:

[source,groovy]
----
include::../test/LogImprovementsASTTransformsTest.groovy[tags=commons_equiv,indent=0]
----

You still need to add the appropriate commons-logging jar to your classpath.

[[xform-Log4j]]
===== `@groovy.util.logging.Log4j`

Groovy supports the http://logging.apache.org/log4j/1.2/[Apache Log4j 1.x] framework using the
`@Log4j` annotation. Writing:

[source,groovy]
----
include::../test/LogImprovementsASTTransformsTest.groovy[tags=log4j_spec,indent=0]
----

is equivalent to writing:

[source,groovy]
----
include::../test/LogImprovementsASTTransformsTest.groovy[tags=log4j_equiv,indent=0]
----

You still need to add the appropriate log4j jar to your classpath.
This annotation can also be used with the compatible https://reload4j.qos.ch/[reload4j] log4j
drop-in replacement, just use the jar from that project instead of a log4j jar.

[[xform-Log4j2]]
===== `@groovy.util.logging.Log4j2`

Groovy supports the http://logging.apache.org/log4j/2.x/[Apache Log4j 2.x] framework using the
`@Log4j2` annotation. Writing:

[source,groovy]
----
include::../test/LogImprovementsASTTransformsTest.groovy[tags=log4j2_spec,indent=0]
----

is equivalent to writing:

[source,groovy]
----
include::../test/LogImprovementsASTTransformsTest.groovy[tags=log4j2_equiv,indent=0]
----

You still need to add the appropriate log4j2 jar to your classpath.

[[xform-Slf4j]]
===== `@groovy.util.logging.Slf4j`

Groovy supports the http://www.slf4j.org/[Simple Logging Facade for Java (SLF4J)] framework using the
`@Slf4j` annotation. Writing:

[source,groovy]
----
include::../test/LogImprovementsASTTransformsTest.groovy[tags=slf4j_spec,indent=0]
----

is equivalent to writing:

[source,groovy]
----
include::../test/LogImprovementsASTTransformsTest.groovy[tags=slf4j_equiv,indent=0]
----

You still need to add the appropriate slf4j jar(s) to your classpath.

[[xform-PlatformLog]]
===== `@groovy.util.logging.PlatformLog`

Groovy supports the https://openjdk.org/jeps/264[Java Platform Logging API and Service]
framework using the `@PlatformLog` annotation. Writing:

[source,groovy]
----
include::../test/LogImprovementsASTTransformsTest.groovy[tags=platformlog_spec,indent=0]
----

is equivalent to writing:

[source,groovy]
----
include::../test/LogImprovementsASTTransformsTest.groovy[tags=platformlog_equiv,indent=0]
----

You need to be using JDK 9+ to use this capability.

