Skip to content

Commit fd9f75e

Browse files
committed
Apply suggestions from code review (2)
1 parent c3a1704 commit fd9f75e

File tree

3 files changed

+76
-52
lines changed

3 files changed

+76
-52
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ Logger -[#green,thickness=6]-> LoggerConfig : delegates `log()`
444444
@enduml
445445
....
446446
447-
[#logger-hiearchy]
447+
[#logger-hierarchy]
448448
=== Logger hierarchy
449449
450450
Log4j Core has a *hierarchical* model of ``LoggerConfig``s, and hence ``Logger``s.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ Users can add Components to loggers, appender references, appenders, or the glob
345345
+
346346
See xref:manual/filters.adoc[Filter configuration] for details.
347347
348+
[#global-properties]
348349
Properties::
349350
+
350351
Represent a set of reusable configuration values for property substitution.

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

Lines changed: 74 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,58 @@
1616
////
1717
= Lookups
1818
19-
Log4j Core provides a flexible and extensible property substitution system loosely based on the
20-
https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/StringSubstitutor.html[Commons Text `StringSubstitutor`].
19+
Log4j Core provides a flexible and extensible property substitution system.
2120
22-
The property substitution system is composed of two kinds of elements:
21+
[#StrSubstitutor-diagram]
22+
.Property substitution system
23+
[plantuml]
24+
....
25+
@startuml
26+
class StrSubstitutor #line.bold {
27+
Interpolator interpolator
28+
String replace(String input)
29+
String replace(LogEvent event, String input)
30+
}
31+
32+
StrSubstitutor --> Interpolator
33+
34+
class Interpolator {
35+
StrLookup[] lookups
36+
String lookup(String key)
37+
String lookup(LogEvent event, String key)
38+
}
39+
40+
Interpolator --> "0..*" StrLookup
41+
42+
class StrLookup {
43+
String lookup(String input)
44+
String lookup(LogEvent event, String key)
45+
}
46+
47+
@enduml
48+
....
49+
50+
The property substitution system is composed of these elements:
2351
2452
* A string interpolation engine (xref:manual/architecture.adoc#StrSubstitutor[`StrSubstitutor`]) that evaluates `$+{...}+` expressions.
53+
These expressions can contain recursive expressions and default values.
54+
+
2555
See xref:manual/configuration.adoc#property-substitution[property substitution] for more details.
56+
57+
* The
58+
link:../javadoc/log4j-core/org/apache/logging/log4j/core/lookup/Interpolator.html[`Interpolator`]
59+
that evaluates simple `$\{name}` expressions.
60+
+
61+
The Interpolator has two functions:
62+
63+
** If `name` does not contain a colon `:` character, the Interpolator uses the
64+
xref:manual/configuration.adoc#global-properties[`Properties` configuration element] to resolve its value.
65+
66+
** If `name` is of the form `prefix:key`, the Interpolator delegates the lookup to a `StrLookup` associated with `prefix` and falls back to evaluating `$+{key}+` if the lookup was not successful.
67+
2668
* A set of
2769
xref:plugin-reference.adoc#org-apache-logging-log4j_log4j-core_org-apache-logging-log4j-core-lookup-StrLookup[`StrLookup`]
28-
plugins that provide values for simple `$+{prefix:key}+` expressions.
70+
plugins, each one associated with a prefix, which retrieve data from external sources.
2971
3072
`StrLookup` is a simple map-like interface.
3173
The main difference between a map and `StrLookup` is that the latter can compute the value of a key programmatically in a global context or in the context of log event.
@@ -51,10 +93,12 @@ In the context of a log event `event`, Log4j evaluates `$+{prefix:key}+` express
5193
link:../javadoc/log4j-core/org/apache/logging/log4j/core/lookup/StrLookup.html#lookup(org.apache.logging.log4j.core.LogEvent,java.lang.String)[`lookup(event, "key")`] on the lookup associated to `prefix`.
5294
The result of this call might take into account the contents of the log event, besides the global state of the system.
5395
54-
The xref:manual/pattern-layout.adoc#plugin-attr-pattern[`pattern`] attribute of `PatternLayout` is an example of attribute that supports both evaluation contexts:
96+
Some configuration attributes (e.g., xref:manual/pattern-layout.adoc#plugin-attr-pattern[the `pattern` attribute of Pattern Layout]) supports both evaluation contexts:
5597
5698
* During the configuration process the `$+{...}+` expressions are evaluated using a global context.
57-
* For each log event the `$$+{...}+` expressions are evaluated, using the log event as context.
99+
The same process converts escaped `$$+{...}+` expressions to `$+{...}+` expressions.
100+
101+
* For each log event, the remaining expressions are evaluated, using the log event as context.
58102
59103
An example of lookup that can be used in both a global and event context is the `$+{date:...}+` lookup:
60104
@@ -66,9 +110,9 @@ link:../javadoc/log4j-core/org/apache/logging/log4j/core/LogEvent.html#getTimeMi
66110
[#collection]
67111
== Collection
68112
69-
Log4j Core provides many lookups out-of-the-box, which can be categorized into three non-disjoint groups:
113+
Log4j Core provides many lookups out-of-the-box:
70114
71-
* A large group of lookups is available in a global context and provides results, which do not vary in time.
115+
* A large group of lookups supports evaluation in a global context.
72116
These lookups can be safely used in eagerly evaluated properties of a
73117
xref:manual/configuration.adoc[configuration file]
74118
using the `${prefix:key}` syntax:
@@ -84,6 +128,14 @@ using the `${prefix:key}` syntax:
84128
| A Java
85129
https://docs.oracle.com/javase/{java-target-version}/docs/api/java/util/ResourceBundle.html[resource bundle]
86130
131+
| <<ContextMapLookup,`ctx`>>
132+
|
133+
| xref:manual/thread-context.adoc[]
134+
135+
| <<DateLookup,`date`>>
136+
|
137+
| Current timestamp
138+
87139
| <<DockerLookup,`docker`>>
88140
| log4j-docker
89141
| Docker container
@@ -96,10 +148,19 @@ https://docs.oracle.com/javase/{java-target-version}/docs/api/java/util/Resource
96148
|
97149
| JVM characteristics
98150
151+
| <<JndiLookup,`jndi`>>
152+
|
153+
| JNDI
154+
99155
| <<Log4jLookup,`log4j`>>
100156
|
101157
| Location of Log4j configuration file
102158
159+
| <<LowerLookup,`lower`>>
160+
|
161+
| It converts the supplied key to lowercase
162+
163+
103164
| <<MainMapLookup,`main`>>
104165
|
105166
| JVM application arguments
@@ -116,38 +177,18 @@ https://docs.oracle.com/javase/{java-target-version}/docs/api/java/util/Resource
116177
|
117178
| Java system properties
118179
180+
| <<UpperLookup,`upper`>>
181+
|
182+
| It converts the supplied key to uppercase
183+
119184
| <<WebLookup,`web`>>
120185
| log4j-jakarta-web
121186
| Jakarta
122187
https://jakarta.ee/specifications/servlet/6.0/apidocs/jakarta.servlet/jakarta/servlet/servletcontext[`ServletContext`].
123188
124189
|===
125190
126-
* A second group of lookups either gives results that vary in time or needs to be evaluated in the context of a log event.
127-
These lookups should be evaluated lazily using the `$$+{prefix:key}+` syntax.
128-
See
129-
xref:manual/configuration.adoc#lazy-property-substitution[lazy property substitution]
130-
for details.
131-
+
132-
[#global-context-mutable-list]
133-
.Mutable lookups available in the global context
134-
[cols="1,2m,5"]
135-
|===
136-
| Prefix | Dependency | Data source
137-
138-
| <<ContextMapLookup,`ctx`>>
139-
|
140-
| xref:manual/thread-context.adoc[]
141-
142-
| <<DateLookup,`date`>>
143-
|
144-
| Current timestamp
145-
146-
| <<JndiLookup,`jndi`>>
147-
|
148-
| JNDI
149-
150-
|===
191+
* The following lookups only support evaluation in the context of a log event or behave differently, when evaluated in such a context:
151192
+
152193
[#event-context-list]
153194
.Lookups available in the context of a log event
@@ -184,24 +225,6 @@ link:../javadoc/log4j-core/org/apache/logging/log4j/core/LogEvent.html#getMarker
184225
185226
|===
186227
187-
* Log4j Core also provides two lookups that can be used to modify the result of another lookup:
188-
+
189-
[#helper-lookups-list]
190-
.Helper lookups
191-
[cols="1,2m,5"]
192-
|===
193-
| Prefix | Dependency | Description
194-
195-
| <<LowerLookup,`lower`>>
196-
|
197-
| It converts the supplied key to lowercase
198-
199-
| <<UpperLookup,`upper`>>
200-
|
201-
| It converts the supplied key to uppercase
202-
203-
|===
204-
205228
[#ResourceBundleLookup]
206229
=== Resource Bundle Lookup
207230

0 commit comments

Comments
 (0)