////
    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.
////
[id=log4j.isWebapp]
== `log4j.isWebapp`

[cols="1h,5"]
|===
| Env. variable | `LOG4J_IS_WEBAPP`
| Type          | `boolean`
| Default value | `true` if the https://jakarta.ee/specifications/servlet/6.0/apidocs/jakarta.servlet/jakarta/servlet/servlet[Servlet] class on classpath,

`false` otherwise
|===

Setting this property to `true` switches Log4j Core into "Web application mode" (_"Web-app mode"_).

In this mode Log4j is optimized to work in a Servlet container.

This mode is incompatible with <<log4j.enableThreadlocals>>.

[id=log4j.enableThreadlocals]
== `log4j.enableThreadlocals`

[cols="1h,5"]
|===
| Env. variable | `LOG4J_ENABLE_THREADLOCALS`
| Type          | `boolean`
| Default value | `false` if Web-app mode is enabled,

`true` otherwise
|===

Setting this property to `true` switches Log4j Core into "garbage-free mode" (_"GC-free mode"_).

In this mode Log4j uses ``ThreadLocal``s for object pooling to prevent object allocations.

https://docs.oracle.com/en/java/javase/{java-target-version}/docs/api/java.base/java/lang/ThreadLocal.html[`ThreadLocal`] fields holding non-JDK classes can cause memory leaks in web applications when the application server's thread pool continues to reference these fields after the web application is undeployed.
Hence, to avoid causing memory leaks, `log4j2.enableThreadlocals` by default reflects the opposite of xref:#log4j.isWebapp[`log4j.isWebapp`].
