Skip to content

Commit f29c8db

Browse files
authored
Add Simple Logger and Status Logger pages (#2619)
1 parent 7852fc9 commit f29c8db

14 files changed

+200
-60
lines changed

src/site/antora/modules/ROOT/nav.adoc

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
** xref:manual/flowtracing.adoc[]
4343
** xref:manual/eventlogging.adoc[]
4444
** xref:manual/resource-logger.adoc[]
45+
** xref:manual/simple-logger.adoc[]
46+
** xref:manual/status-logger.adoc[]
4547
* Configuration
4648
** xref:manual/configuration.adoc[Configuration file]
4749
** xref:manual/systemproperties.adoc[]

src/site/antora/modules/ROOT/pages/faq.adoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ By default, Log4j looks for a configuration file named `log4j2.xml` on the class
126126
Note the `2` in the file name!
127127
(See xref:manual/configuration.adoc[the Configuration page] for more details.)
128128
129-
. Increase the logging verbosity of the internal status logger: +
129+
. Increase the logging verbosity of the internal xref:manual/status-logger.adoc[]: +
130130
`-Dlog4j2.statusLoggerLevel=TRACE`
131131
132132
. Enable all internal debug logging: `-Dlog4j2.debug`.
133-
This disables level-based status logger filtering and effectively allows all status logs.
133+
This disables level-based xref:manual/status-logger.adoc[] filtering and effectively allows all status logs.
134134
135135
[#separate_log_files]
136136
== How do I dynamically write to separate log files?
@@ -156,7 +156,7 @@ It is the responsibility of the logging _implementation_ to handle this object,
156156
* Log4j API offers support for logging xref:manual/messages.adoc[`Message` objects].
157157
Messages allow support for interesting and complex constructs to be passed through the logging system and be efficiently manipulated.
158158
Users are free to create their own message types and write custom layouts, filters and lookups to manipulate them.
159-
* Log4j API supports xref:manual/api.adoc#LambdaSupport[lambda expressions] both in its plain and fluent API.
159+
* Log4j API supports xref:manual/api.adoc#fluent-api[lambda expressions] both in its plain and fluent API.
160160
* Log4j API has better support for xref:manual/garbagefree.adoc[garbage-free logging]: it avoids creating `vararg` arrays and avoids creating ``String``s when logging ``CharSequence``s.
161161
162162
[#gc-free-slf4j]

src/site/antora/modules/ROOT/pages/log4j-jmx-gui.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
1616
////
1717
= Log4j JMX GUI
1818
19-
https://github.com/apache/logging-log4j-jmx-gui[The Apache Log4j JMX GUI] is a basic client GUI that can be used to monitor the `StatusLogger` output and to remotely modify the Log4j configuration.
19+
https://github.com/apache/logging-log4j-jmx-gui[The Apache Log4j JMX GUI] is a basic client GUI that can be used to monitor the xref:manual/status-logger.adoc[] output and to remotely modify the Log4j configuration.
2020
The client GUI can be run as a stand-alone application or as a JConsole plug-in.
2121
2222
[NOTE]

src/site/antora/modules/ROOT/pages/manual/api.adoc

+22-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ You can also check out xref:manual/installation.adoc[] for the complete installa
4949
Log4j API provides
5050
5151
* A logging API that libraries and applications can code to
52+
* xref:#simple-logger[A minimal logging implementation (aka. Simple logger)]
5253
* Adapter components to create a logging implementation
5354
54-
This page tries to cover the most prominent Log4j API features that libraries and applications can code to.
55+
This page tries to cover the most prominent Log4j API features.
5556
5657
[TIP]
5758
====
@@ -92,7 +93,7 @@ include::partial$manual/api-best-practice-use-supplier.adoc[]
9293
[#loggers]
9394
== Loggers
9495
95-
link:../javadoc/log4j-api/org/apache/logging/log4j/Logger.html[`Logger`]s obtained using link:../javadoc/log4j-api/org/apache/logging/log4j/LogManager.html[`LogManager`] is the primary entry point for logging.
96+
link:../javadoc/log4j-api/org/apache/logging/log4j/Logger.html[`Logger`]s are the primary entry point for logging.
9697
In this section we will introduce you to further details about ``Logger``s.
9798
9899
[#logger-names]
@@ -220,7 +221,25 @@ link:../javadoc/log4j-api/org/apache/logging/log4j/LogManager.html[`EventLogger`
220221
221222
xref:manual/eventlogging.adoc[Read more on event loggers...]
222223
223-
[#feature-fluent-api]
224+
[#simple-logger]
225+
=== Simple logger
226+
227+
Even though Log4j Core is the reference implementation of Log4j API, Log4j API itself also provides a very minimalist implementation: _Simple Logger_.
228+
This is a convenience for environments where either a fully-fledged logging implementation is missing, or cannot be included for other reasons.
229+
`SimpleLogger` is the fallback Log4j API implementation if no other is available in the classpath.
230+
231+
xref:manual/simple-logger.adoc[Read more on the simple logger...]
232+
233+
[#status-logger]
234+
=== Status logger
235+
236+
_Status Logger_ is a standalone, self-sufficient `Logger` implementation to record events that occur in the logging system (i.e., Log4j) itself.
237+
It is the logging system used by Log4j for reporting status of its internals.
238+
Users can use the status logger to either emit logs in their custom Log4j components, or troubleshoot a Log4j configuration.
239+
240+
xref:manual/status-logger.adoc[Read more on the status logger...]
241+
242+
[#fluent-api]
224243
== Fluent API
225244
226245
The fluent API allows you to log using a fluent interface:

src/site/antora/modules/ROOT/pages/manual/appenders.adoc

+5-3
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,9 @@ Each log event is sent as a Kafka record.
16711671
16721672
|syncSend
16731673
|boolean
1674-
|The default is `true`, causing sends to block until the record has been acknowledged by the Kafka server. When set to `false`, sends a return immediately, allowing for lower latency and significantly higher throughput. _New since 2.8. Be aware that this is a new addition, and it has not been extensively tested. Any failure sending to Kafka will be reported as an error to StatusLogger and the log event will be dropped (the ignoreExceptions parameter will not be effective). Log events may arrive out of order on the Kafka server._
1674+
|The default is `true`, causing sends to block until the record has been acknowledged by the Kafka server. When set to `false`, sends a return immediately, allowing for lower latency and significantly higher throughput. _New since 2.8. Be aware that this is a new addition, and it has not been extensively tested.
1675+
Any failure sending to Kafka will be reported as an error to xref:manual/status-logger.adoc[] and the log event will be dropped (the ignoreExceptions parameter will not be effective).
1676+
Log events may arrive out of order on the Kafka server._
16751677
16761678
|properties
16771679
|Property[]
@@ -2925,7 +2927,7 @@ default is 1, meaning only the files in the specified base directory.
29252927
false.
29262928
29272929
|testMode |boolean |If true, files are not deleted but instead a message
2928-
is printed to the xref:manual/configuration.adoc#StatusMessages[status logger]
2930+
is printed to the xref:manual/status-logger.adoc[]
29292931
at INFO level. Use this to do a dry run to test if the configuration
29302932
works as expected. The default is false.
29312933
@@ -3170,7 +3172,7 @@ the paths in the `pathList`.
31703172
under the base path up to the specified max depth, sorted most recently
31713173
modified files first. The script is free to modify and return this list.
31723174
3173-
|statusLogger |StatusLogger |The StatusLogger that can be used to log
3175+
|statusLogger |StatusLogger |The xref:manual/status-logger.adoc[] that can be used to log
31743176
internal events during script execution.
31753177
31763178
|configuration |Configuration |The Configuration that owns this

src/site/antora/modules/ROOT/pages/manual/configuration.adoc

+6-5
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Upon initialization of a new logger context, Log4j assigns it a context name and
5959
. Files named `log4j2-test.<extension>`,
6060
. Files named `log4j2<contextName>.<extension>`
6161
. Files named `log4j2.<extension>`,
62-
. If no configuration file is found, Log4j uses the link:../javadoc/log4j-core/org/apache/logging/log4j/core/config/DefaultConfiguration[DefaultConfiguration], and the status logger prints a warning.
62+
. If no configuration file is found, Log4j uses the link:../javadoc/log4j-core/org/apache/logging/log4j/core/config/DefaultConfiguration[DefaultConfiguration], and xref:manual/status-logger.adoc[] prints a warning.
6363
The default configuration prints all messages less specific than
6464
xref:manual/systemproperties.adoc#log4j2.level[log4j2.level]
6565
to the console.
@@ -422,11 +422,12 @@ To modify these options during a reconfiguration, you also need to change the re
422422
| Default value (before 2.24.0) | value of `log4j2.defaultStatusLevel`
423423
|===
424424
425-
Overrides the logging level of the status logger.
425+
Overrides the logging level of xref:manual/status-logger.adoc[].
426426
427-
WARNING: Since 2.24.0 this attribute is deprecated and should be replaced with the
428-
xref:manual/systemproperties.adoc#log4j2.statusLoggerLevel[log4j2.statusLoggerLevel]
429-
configuration property.
427+
[WARNING]
428+
====
429+
Since version `2.24.0`, this attribute is deprecated and should be replaced with the xref:manual/systemproperties.adoc#log4j2.statusLoggerLevel[log4j2.statusLoggerLevel] configuration property instead.
430+
====
430431
431432
[id=configuration-elements-filters]
432433
==== Filters

src/site/antora/modules/ROOT/pages/manual/jmx.adoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
1919
Log4j 2 has built-in support for JMX.
2020
21-
When JMX support is enabled, the StatusLogger, ContextSelector, and all LoggerContexts, LoggerConfigs, and Appenders are instrumented with MBeans.
21+
When JMX support is enabled, xref:manual/status-logger.adoc[], ContextSelector, and all LoggerContexts, LoggerConfigs, and xref:manual/appenders.adoc[] are instrumented with MBeans.
2222
2323
Also included is a simple client GUI that can be used to monitor the
24-
StatusLogger output, as well as to remotely reconfigure Log4j with a
24+
status logger output, as well as to remotely reconfigure Log4j with a
2525
different configuration file, or to edit the current configuration
2626
directly.
2727

src/site/antora/modules/ROOT/pages/manual/logsep.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ default ClassLoaderContextSelector.
102102
See the instructions shared in xref:manual/webapp.adoc[Log4j Web].
103103
Each application can be configured to share the same
104104
configuration used at the container or can be individually configured.
105-
If status logging is set to debug in the configuration there will be
105+
If xref:manual/status-logger.adoc[status logging] is set to debug in the configuration there will be
106106
output from when logging is initialized in the container and then again
107107
in each web application.
108108

src/site/antora/modules/ROOT/pages/manual/scripts.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ interface if they support compiling their scripts.
115115
Beanshell does extend the `Compilable` interface, but an attempt to compile a script ends up in an
116116
https://docs.oracle.com/javase/{java-target-version}/docs/api/java/lang/Error.html[Error]
117117
being thrown.
118-
Log4j catches the throwable, but issues a warning in the status logger.
118+
Log4j catches the throwable, but issues a warning in xref:manual/status-logger.adoc[].
119119
120120
----
121121
2015-09-27 16:13:23,095 main DEBUG Script BeanShellSelector is compilable
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
////
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
////
17+
18+
= Simple Logger
19+
20+
Even though Log4j Core is the reference implementation of xref:manual/api.adoc[Log4j API], Log4j API itself also provides a very minimalist implementation: link:../javadoc/log4j-api/org/apache/logging/log4j/simple/SimpleLogger.html[`SimpleLogger`].
21+
This is a convenience for environments where either a fully-fledged logging implementation is missing, or cannot be included for other reasons.
22+
`SimpleLogger` is the default Log4j API implementation if no other is available in the classpath.
23+
24+
[#config]
25+
== Configuration
26+
27+
`SimpleLogger` can be configured using the following system properties:
28+
29+
include::partial$manual/systemproperties/properties-simple-logger.adoc[leveloffset=+1]
30+
31+
=== Thread context
32+
33+
Simple Logger supports the same properties as Log4j Core for the configuration of the thread context.
34+
See xref:manual/systemproperties.adoc#properties-thread-context[] for details.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
////
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
////
17+
18+
:status-logger-properties-file-name: "log4j2.StatusLogger.properties"
19+
20+
= Status Logger
21+
22+
link:../javadoc/log4j-api/org/apache/logging/log4j/status/StatusLogger.html[`StatusLogger`] is a standalone, self-sufficient `Logger` implementation to record events that occur in the logging system (i.e., Log4j) itself.
23+
It is the logging system used by Log4j for reporting status of its internals.
24+
25+
[#usage]
26+
== Usage
27+
28+
You can use the status logger for several purposes:
29+
30+
[#usage-troubleshoot]
31+
Troubleshooting::
32+
When Log4j is not behaving in the way you expect it to, you can increase the verbosity of status logger messages emitted using xref:#log4j2.debug[the `log4j2.debug` system property] for troubleshooting.
33+
See xref:#config[] for details.
34+
35+
[#usage-report]
36+
Reporting internal status::
37+
If you have custom Log4j components (layouts, appenders, etc.), you cannot use Log4j API itself for logging, since this will result in a chicken and egg problem.
38+
This is where `StatusLogger` comes into play:
39+
+
40+
[source,java]
41+
----
42+
private class CustomLog4jComponent {
43+
44+
private static final Logger LOGGER = StatusLogger.getInstance();
45+
46+
void doSomething(String input) {
47+
LOGGER.trace("doing something with input: `{}`", input);
48+
}
49+
50+
}
51+
----
52+
53+
[#usage-listen]
54+
Listening internal status::
55+
You can configure where the status logger messages are delivered to.
56+
See xref:#listeners[].
57+
58+
[#config]
59+
== Configuration
60+
61+
`StatusLogger` can be configured in following ways:
62+
63+
. Passing system properties to the Java process (e.g., xref:#log4j2.statusLoggerLevel[`-Dlog4j2.statusLoggerLevel=INFO`]}
64+
+
65+
[WARNING]
66+
====
67+
Due to several complexities involved, **you are strongly advised to xref:#properties[configure the status logger only using system properties]!**
68+
====
69+
. Providing properties in a `{status-logger-properties-file-name}` file in the classpath
70+
. Using Log4j configuration (i.e., `<Configuration status="WARN" dest="out">` in a `log4j2.xml` in the classpath)
71+
+
72+
WARNING: Since version `2.24.0`, `status` attribute in the `Configuration` element is deprecated and should be replaced with the xref:manual/systemproperties.adoc#log4j2.statusLoggerLevel[log4j2.statusLoggerLevel] configuration property.
73+
. Programmatically (e.g., `StatusLogger.getLogger().setLevel(Level.WARN)`)
74+
75+
It is crucial to understand that there is a time between the first `StatusLogger` access and a configuration file (e.g., `log4j2.xml`) read.
76+
Consider the following example:
77+
78+
. The default level (of fallback listener) is `ERROR`
79+
. You have `<Configuration status="WARN">` in your `log4j2.xml`
80+
. Until your `log4j2.xml` configuration is read, the effective level will be `ERROR`
81+
. Once your `log4j2.xml` configuration is read, the effective level will be `WARN` as you configured
82+
83+
Hence, unless you use either system properties or `{status-logger-properties-file-name}` file in the classpath, there is a time window that only the defaults will be effective.
84+
85+
`StatusLogger` is designed as a singleton class accessed statically.
86+
If you are running an application containing multiple Log4j configurations (e.g., in a servlet environment with multiple containers), and you happen to have differing `StatusLogger` configurations (e.g, one `log4j2.xml` containing `<Configuration status="ERROR">` while the other `<Configuration status="INFO">`), the last loaded configuration will be the effective one.
87+
88+
[#properties]
89+
=== Properties
90+
91+
`StatusLogger` can be configured using the following system properties:
92+
93+
include::partial$manual/systemproperties/properties-status-logger.adoc[leveloffset=+2]
94+
95+
[#debug]
96+
== Debug mode
97+
98+
When the `log4j2.debug` system property is present, any level-related filtering will be skipped and all events will be notified to listeners.
99+
If no listeners are available, the fallback listener of type `StatusConsoleListener` will be used.
100+
101+
[#listeners]
102+
== Listeners
103+
104+
Each recorded log event by `StatusLogger` will first get buffered and then used to notify the registered link:../javadoc/log4j-api/org/apache/logging/log4j/status/StatusListener.html[`StatusListener`]s.
105+
If none are available, *the fallback listener* of type link:../javadoc/log4j-api/org/apache/logging/log4j/status/StatusConsoleListener.html[`StatusConsoleListener`] will be used.
106+
107+
You can programmatically register listeners using link:../javadoc/log4j-api/org/apache/logging/log4j/status/StatusLogger.html#registerListener(org.apache.logging.log4j.status.StatusListener)[the `StatusLogger#registerListener(StatusListener)` method].

src/site/antora/modules/ROOT/pages/manual/systemproperties.adoc

+14-39
Original file line numberDiff line numberDiff line change
@@ -88,41 +88,6 @@ In the particular case, when multiple implementations are present, you can selec
8888
8989
include::partial$manual/systemproperties/properties-provider.adoc[leveloffset=+2]
9090
91-
[id=properties-status-logger]
92-
=== Status Logger
93-
94-
NOTE: To configure status logger you can also place its configuration in a file named `log4j2.StatusLogger.properties`.
95-
96-
Log4j contains an internal logging mechanism called `StatusLogger` that is used by all Log4j components.
97-
By default, the status logger only reports errors on the standard error stream, but you can configure it using the following properties.
98-
99-
include::partial$manual/systemproperties/properties-status-logger.adoc[leveloffset=+2]
100-
101-
[id=properties-simple-logger]
102-
=== Simple logger
103-
104-
NOTE: To configure simple logger you can also place its configuration in a file named `log4j2.simplelog.properties`.
105-
106-
The simple logger implementation contained in `log4j-api` can be configured using these properties:
107-
108-
include::partial$manual/systemproperties/properties-simple-logger.adoc[leveloffset=+2]
109-
110-
[id=properties-simple-logger-thread-context]
111-
=== Thread context (Simple Logger)
112-
113-
The behavior of the `ThreadContext` class can be fine-tuned using the following properties.
114-
115-
[WARNING]
116-
====
117-
These configuration properties are only used by the Log4j Core and Simple Logger implementations of Log4j API.
118-
119-
The `log4j-to-slf4j` logging bridge delegates `ThreadContext` calls to the SLF4J https://slf4j.org/api/org/slf4j/MDC.html[MDC] class.
120-
121-
The `log4j-to-jul` logging bridge ignores all `ThreadContext` method calls.
122-
====
123-
124-
include::partial$manual/systemproperties/properties-thread-context.adoc[leveloffset=+2]
125-
12691
[id=properties-log4j-core]
12792
== Log4j Core properties
12893
@@ -203,11 +168,21 @@ Moreover, each JNDI usage must be **explicitly** enabled by the user through the
203168
204169
include::partial$manual/systemproperties/properties-jndi.adoc[leveloffset=+2]
205170
206-
[id=properties-log4j-core-thread-context]
207-
=== Thread context (Log4j Core)
171+
[id=properties-thread-context]
172+
=== Thread context
173+
174+
The behavior of the `ThreadContext` class can be fine-tuned using the following properties.
175+
176+
[WARNING]
177+
====
178+
These configuration properties are only used by the Log4j Core and xref:manual/simple-logger.adoc[] implementations of Log4j API.
179+
180+
The `log4j-to-slf4j` logging bridge delegates `ThreadContext` calls to the SLF4J https://slf4j.org/api/org/slf4j/MDC.html[MDC] class.
208181
209-
Log4j Core supports the same properties as Simple Logger for the configuration of the thread context.
210-
See <<properties-simple-logger-thread-context>> for more details.
182+
The `log4j-to-jul` logging bridge ignores all `ThreadContext` method calls.
183+
====
184+
185+
include::partial$manual/systemproperties/properties-thread-context.adoc[leveloffset=+2]
211186
212187
[id=properties-transport-security]
213188
=== Transport security

0 commit comments

Comments
 (0)